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