blob: 4db510a18d504ae3585199a80bad864b41db2a27 [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
61 asset.save()
62 asset.submit()
63
64def setup_item():
65 items = json.loads(open(frappe.get_app_path('erpnext', 'demo', 'data', 'item.json')).read())
66 for i in items:
67 item = frappe.new_doc('Item')
68 item.update(i)
Manas Solanki087a2252018-05-04 16:02:38 +053069 if item.item_defaults[0].default_warehouse:
70 item.item_defaults[0].company = data.get("Manufacturing").get('company_name')
71 warehouse = frappe.get_all('Warehouse', filters={'warehouse_name': item.item_defaults[0].default_warehouse}, limit=1)
Neil Trini Lasrado6da2b082016-10-31 17:13:30 +053072 if warehouse:
Manas Solanki087a2252018-05-04 16:02:38 +053073 item.item_defaults[0].default_warehouse = warehouse[0].name
Neil Trini Lasrado06724592016-08-22 12:57:09 +053074 item.insert()
75
76def setup_product_bundle():
77 frappe.get_doc({
78 'doctype': 'Product Bundle',
79 'new_item_code': 'Wind Mill A Series with Spare Bearing',
80 'items': [
81 {'item_code': 'Wind Mill A Series', 'qty': 1},
82 {'item_code': 'Bearing Collar', 'qty': 1},
83 {'item_code': 'Bearing Assembly', 'qty': 1},
84 ]
85 }).insert()
86
87def setup_item_price():
88 frappe.db.sql("delete from `tabItem Price`")
89
90 standard_selling = {
91 "Base Bearing Plate": 28,
92 "Base Plate": 21,
93 "Bearing Assembly": 300,
94 "Bearing Block": 14,
95 "Bearing Collar": 103.6,
96 "Bearing Pipe": 63,
97 "Blade Rib": 46.2,
98 "Disc Collars": 42,
99 "External Disc": 56,
100 "Internal Disc": 70,
101 "Shaft": 340,
102 "Stand": 400,
103 "Upper Bearing Plate": 300,
104 "Wind Mill A Series": 320,
105 "Wind Mill A Series with Spare Bearing": 750,
106 "Wind MIll C Series": 400,
107 "Wind Turbine": 400,
108 "Wing Sheet": 30.8
109 }
110
111 standard_buying = {
112 "Base Bearing Plate": 20,
113 "Base Plate": 28,
114 "Base Plate Un Painted": 16,
115 "Bearing Block": 13,
116 "Bearing Collar": 96.4,
117 "Bearing Pipe": 55,
118 "Blade Rib": 38,
119 "Disc Collars": 34,
120 "External Disc": 50,
121 "Internal Disc": 60,
122 "Shaft": 250,
123 "Stand": 300,
124 "Upper Bearing Plate": 200,
125 "Wing Sheet": 25
126 }
127
128 for price_list in ("standard_buying", "standard_selling"):
Achilles Rasquinha714c7462018-02-15 11:28:55 +0530129 for item, rate in iteritems(locals().get(price_list)):
Neil Trini Lasrado06724592016-08-22 12:57:09 +0530130 frappe.get_doc({
131 "doctype": "Item Price",
132 "price_list": price_list.replace("_", " ").title(),
133 "item_code": item,
134 "selling": 1 if price_list=="standard_selling" else 0,
135 "buying": 1 if price_list=="standard_buying" else 0,
136 "price_list_rate": rate,
137 "currency": "USD"
138 }).insert()