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