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