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