blob: 8ac203903b2a9f5d1f05924a4421adf7588a7777 [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)
66 item.default_warehouse = frappe.get_all('Warehouse', filters={'warehouse_name': item.default_warehouse}, limit=1)[0].name
67 item.insert()
68
69def setup_product_bundle():
70 frappe.get_doc({
71 'doctype': 'Product Bundle',
72 'new_item_code': 'Wind Mill A Series with Spare Bearing',
73 'items': [
74 {'item_code': 'Wind Mill A Series', 'qty': 1},
75 {'item_code': 'Bearing Collar', 'qty': 1},
76 {'item_code': 'Bearing Assembly', 'qty': 1},
77 ]
78 }).insert()
79
80def setup_item_price():
81 frappe.db.sql("delete from `tabItem Price`")
82
83 standard_selling = {
84 "Base Bearing Plate": 28,
85 "Base Plate": 21,
86 "Bearing Assembly": 300,
87 "Bearing Block": 14,
88 "Bearing Collar": 103.6,
89 "Bearing Pipe": 63,
90 "Blade Rib": 46.2,
91 "Disc Collars": 42,
92 "External Disc": 56,
93 "Internal Disc": 70,
94 "Shaft": 340,
95 "Stand": 400,
96 "Upper Bearing Plate": 300,
97 "Wind Mill A Series": 320,
98 "Wind Mill A Series with Spare Bearing": 750,
99 "Wind MIll C Series": 400,
100 "Wind Turbine": 400,
101 "Wing Sheet": 30.8
102 }
103
104 standard_buying = {
105 "Base Bearing Plate": 20,
106 "Base Plate": 28,
107 "Base Plate Un Painted": 16,
108 "Bearing Block": 13,
109 "Bearing Collar": 96.4,
110 "Bearing Pipe": 55,
111 "Blade Rib": 38,
112 "Disc Collars": 34,
113 "External Disc": 50,
114 "Internal Disc": 60,
115 "Shaft": 250,
116 "Stand": 300,
117 "Upper Bearing Plate": 200,
118 "Wing Sheet": 25
119 }
120
121 for price_list in ("standard_buying", "standard_selling"):
122 for item, rate in locals().get(price_list).iteritems():
123 frappe.get_doc({
124 "doctype": "Item Price",
125 "price_list": price_list.replace("_", " ").title(),
126 "item_code": item,
127 "selling": 1 if price_list=="standard_selling" else 0,
128 "buying": 1 if price_list=="standard_buying" else 0,
129 "price_list_rate": rate,
130 "currency": "USD"
131 }).insert()