blob: 5db3519c2cee8b6a3033537288e8dc752e7b47bc [file] [log] [blame]
Neil Trini Lasrado06724592016-08-22 12:57:09 +05301from __future__ import unicode_literals
2
Chillar Anand915b3432021-09-02 16:44:59 +05303import json
4import random
Neil Trini Lasrado06724592016-08-22 12:57:09 +05305
Chillar Anand915b3432021-09-02 16:44:59 +05306import frappe
7from frappe.utils import add_days, nowdate
Achilles Rasquinha5f0c7032018-02-15 11:55:45 +05308from six import iteritems
9
Chillar Anand915b3432021-09-02 16:44:59 +053010from erpnext.demo.domains import data
11from erpnext.demo.setup.setup_data import import_json
12
13
Neil Trini Lasrado06724592016-08-22 12:57:09 +053014def setup_data():
igormbqaa08fb92020-11-04 11:40:57 -030015 import_json("Location")
Neil Trini Lasrado06724592016-08-22 12:57:09 +053016 import_json("Asset Category")
17 setup_item()
18 setup_workstation()
19 setup_asset()
20 import_json('Operation')
21 setup_item_price()
22 show_item_groups_in_website()
23 import_json('BOM', submit=True)
24 frappe.db.commit()
25 frappe.clear_cache()
26
27def setup_workstation():
28 workstations = [u'Drilling Machine 1', u'Lathe 1', u'Assembly Station 1', u'Assembly Station 2', u'Packing and Testing Station']
29 for w in workstations:
30 frappe.get_doc({
31 "doctype": "Workstation",
32 "workstation_name": w,
33 "holiday_list": frappe.get_all("Holiday List")[0].name,
34 "hour_rate_consumable": int(random.random() * 20),
35 "hour_rate_electricity": int(random.random() * 10),
36 "hour_rate_labour": int(random.random() * 40),
37 "hour_rate_rent": int(random.random() * 10),
38 "working_hours": [
39 {
40 "enabled": 1,
41 "start_time": "8:00:00",
42 "end_time": "15:00:00"
43 }
44 ]
45 }).insert()
46
47def show_item_groups_in_website():
48 """set show_in_website=1 for Item Groups"""
49 products = frappe.get_doc("Item Group", "Products")
50 products.show_in_website = 1
51 products.route = 'products'
52 products.save()
53
54def setup_asset():
55 assets = json.loads(open(frappe.get_app_path('erpnext', 'demo', 'data', 'asset.json')).read())
56 for d in assets:
57 asset = frappe.new_doc('Asset')
58 asset.update(d)
59 asset.purchase_date = add_days(nowdate(), -random.randint(20, 1500))
60 asset.next_depreciation_date = add_days(asset.purchase_date, 30)
61 asset.warehouse = "Stores - WPL"
62 asset.set_missing_values()
63 asset.make_depreciation_schedule()
64 asset.flags.ignore_validate = True
Saurabheb579a12018-06-06 15:05:31 +053065 asset.flags.ignore_mandatory = True
Neil Trini Lasrado06724592016-08-22 12:57:09 +053066 asset.save()
67 asset.submit()
68
69def setup_item():
70 items = json.loads(open(frappe.get_app_path('erpnext', 'demo', 'data', 'item.json')).read())
71 for i in items:
72 item = frappe.new_doc('Item')
73 item.update(i)
Saurabheb579a12018-06-06 15:05:31 +053074 if hasattr(item, 'item_defaults') and item.item_defaults[0].default_warehouse:
Manas Solanki087a2252018-05-04 16:02:38 +053075 item.item_defaults[0].company = data.get("Manufacturing").get('company_name')
76 warehouse = frappe.get_all('Warehouse', filters={'warehouse_name': item.item_defaults[0].default_warehouse}, limit=1)
Neil Trini Lasrado6da2b082016-10-31 17:13:30 +053077 if warehouse:
Manas Solanki087a2252018-05-04 16:02:38 +053078 item.item_defaults[0].default_warehouse = warehouse[0].name
Neil Trini Lasrado06724592016-08-22 12:57:09 +053079 item.insert()
80
81def setup_product_bundle():
82 frappe.get_doc({
83 'doctype': 'Product Bundle',
84 'new_item_code': 'Wind Mill A Series with Spare Bearing',
85 'items': [
86 {'item_code': 'Wind Mill A Series', 'qty': 1},
87 {'item_code': 'Bearing Collar', 'qty': 1},
88 {'item_code': 'Bearing Assembly', 'qty': 1},
89 ]
90 }).insert()
91
92def setup_item_price():
93 frappe.db.sql("delete from `tabItem Price`")
94
95 standard_selling = {
96 "Base Bearing Plate": 28,
97 "Base Plate": 21,
98 "Bearing Assembly": 300,
99 "Bearing Block": 14,
100 "Bearing Collar": 103.6,
101 "Bearing Pipe": 63,
102 "Blade Rib": 46.2,
103 "Disc Collars": 42,
104 "External Disc": 56,
105 "Internal Disc": 70,
106 "Shaft": 340,
107 "Stand": 400,
108 "Upper Bearing Plate": 300,
109 "Wind Mill A Series": 320,
110 "Wind Mill A Series with Spare Bearing": 750,
111 "Wind MIll C Series": 400,
112 "Wind Turbine": 400,
113 "Wing Sheet": 30.8
114 }
115
116 standard_buying = {
117 "Base Bearing Plate": 20,
118 "Base Plate": 28,
119 "Base Plate Un Painted": 16,
120 "Bearing Block": 13,
121 "Bearing Collar": 96.4,
122 "Bearing Pipe": 55,
123 "Blade Rib": 38,
124 "Disc Collars": 34,
125 "External Disc": 50,
126 "Internal Disc": 60,
127 "Shaft": 250,
128 "Stand": 300,
129 "Upper Bearing Plate": 200,
130 "Wing Sheet": 25
131 }
132
133 for price_list in ("standard_buying", "standard_selling"):
Achilles Rasquinha714c7462018-02-15 11:28:55 +0530134 for item, rate in iteritems(locals().get(price_list)):
Neil Trini Lasrado06724592016-08-22 12:57:09 +0530135 frappe.get_doc({
136 "doctype": "Item Price",
137 "price_list": price_list.replace("_", " ").title(),
138 "item_code": item,
139 "selling": 1 if price_list=="standard_selling" else 0,
140 "buying": 1 if price_list=="standard_buying" else 0,
141 "price_list_rate": rate,
142 "currency": "USD"
143 }).insert()