blob: 137a07326b23a9a1d3ac4b09c05893ae00db4bd6 [file] [log] [blame]
Rushabh Mehtadc8067e2016-06-29 18:38:32 +05301from __future__ import unicode_literals
2
3import random, json
4from erpnext.demo.domains import data
5import frappe, erpnext
6import frappe.utils
7
8def setup_data():
9 domain = frappe.flags.domain
10 complete_setup(domain)
11 setup_demo_page()
12 setup_fiscal_year()
13 setup_holiday_list()
14 setup_customer()
15 setup_supplier()
16 setup_item()
Rushabh Mehtacca33b22016-07-08 18:24:46 +053017 setup_warehouse()
Rushabh Mehtadc8067e2016-06-29 18:38:32 +053018 import_json('Address')
19 import_json('Contact')
20 setup_workstation()
21 import_json('Operation')
22 import_json('Lead')
23 setup_item_price()
24 show_item_groups_in_website()
25 setup_currency_exchange()
26 import_json('BOM', submit=True)
27 setup_user()
28 setup_employee()
29 setup_salary_structure()
30 setup_user_roles()
Rushabh Mehta391c0ef2016-07-11 13:01:44 +053031 frappe.db.commit()
32 frappe.clear_cache()
Rushabh Mehtadc8067e2016-06-29 18:38:32 +053033
34def complete_setup(domain='Manufacturing'):
35 print "Complete Setup..."
36 from frappe.desk.page.setup_wizard.setup_wizard import setup_complete
37
38 if not frappe.get_all('Company', limit=1):
39 setup_complete({
40 "first_name": "Test",
41 "last_name": "User",
42 "email": "test_demo@erpnext.com",
43 "company_tagline": 'Awesome Products and Services',
44 "password": "test",
45 "fy_start_date": "2015-01-01",
46 "fy_end_date": "2015-12-31",
47 "bank_account": "National Bank",
48 "industry": domain,
49 "company_name": data.get(domain).get('company_name'),
50 "chart_of_accounts": "Standard",
51 "company_abbr": ''.join([d[0] for d in data.get(domain).get('company_name').split()]).upper(),
52 "currency": 'USD',
53 "timezone": 'America/New_York',
54 "country": 'United States',
55 "language": "english"
56 })
57
58def setup_demo_page():
59 # home page should always be "start"
60 website_settings = frappe.get_doc("Website Settings", "Website Settings")
61 website_settings.home_page = "demo"
62 website_settings.save()
63
64def setup_fiscal_year():
65 fiscal_year = None
66 for year in xrange(2014, frappe.utils.now_datetime().year + 1, 1):
67 try:
68 fiscal_year = frappe.get_doc({
69 "doctype": "Fiscal Year",
70 "year": frappe.utils.cstr(year),
71 "year_start_date": "{0}-01-01".format(year),
72 "year_end_date": "{0}-12-31".format(year)
73 }).insert()
74 except frappe.DuplicateEntryError:
75 pass
76
77 # set the last fiscal year (current year) as default
78 fiscal_year.set_as_default()
79
80def setup_holiday_list():
81 """Setup Holiday List for the current year"""
82 year = frappe.utils.now_datetime().year
83 holiday_list = frappe.get_doc({
84 "doctype": "Holiday List",
85 "holiday_list_name": str(year),
86 "from_date": "{0}-01-01".format(year),
87 "to_date": "{0}-12-31".format(year),
88 })
89 holiday_list.insert()
90 holiday_list.weekly_off = "Saturday"
91 holiday_list.get_weekly_off_dates()
92 holiday_list.weekly_off = "Sunday"
93 holiday_list.get_weekly_off_dates()
94 holiday_list.save()
95
96 frappe.set_value("Company", erpnext.get_default_company(), "default_holiday_list", holiday_list.name)
97
98def setup_customer():
99 customers = [u'Asian Junction', u'Life Plan Counselling', u'Two Pesos', u'Mr Fables', u'Intelacard', u'Big D Supermarkets', u'Adaptas', u'Nelson Brothers', u'Landskip Yard Care', u'Buttrey Food & Drug', u'Fayva', u'Asian Fusion', u'Crafts Canada', u'Consumers and Consumers Express', u'Netobill', u'Choices', u'Chi-Chis', u'Red Food', u'Endicott Shoes', u'Hind Enterprises']
100 for c in customers:
101 frappe.get_doc({
102 "doctype": "Customer",
103 "customer_name": c,
104 "customer_group": "Commercial",
105 "customer_type": random.choice(["Company", "Individual"]),
106 "territory": "Rest Of The World"
107 }).insert()
108
109def setup_supplier():
110 suppliers = [u'Helios Air', u'Ks Merchandise', u'HomeBase', u'Scott Ties', u'Reliable Investments', u'Nan Duskin', u'Rainbow Records', u'New World Realty', u'Asiatic Solutions', u'Eagle Hardware', u'Modern Electricals']
111 for s in suppliers:
112 frappe.get_doc({
113 "doctype": "Supplier",
114 "supplier_name": s,
115 "supplier_type": random.choice(["Services", "Raw Material"]),
116 }).insert()
117
118def setup_workstation():
119 workstations = [u'Drilling Machine 1', u'Lathe 1', u'Assembly Station 1', u'Assembly Station 2', u'Packing and Testing Station']
120 for w in workstations:
121 frappe.get_doc({
122 "doctype": "Workstation",
123 "workstation_name": w,
124 "holiday_list": frappe.get_all("Holiday List")[0].name,
125 "hour_rate_consumable": int(random.random() * 20),
126 "hour_rate_electricity": int(random.random() * 10),
127 "hour_rate_labour": int(random.random() * 40),
128 "hour_rate_rent": int(random.random() * 10),
129 "working_hours": [
130 {
131 "enabled": 1,
132 "start_time": "8:00:00",
133 "end_time": "15:00:00"
134 }
135 ]
136 }).insert()
137
138def show_item_groups_in_website():
139 """set show_in_website=1 for Item Groups"""
140 products = frappe.get_doc("Item Group", "Products")
141 products.show_in_website = 1
142 products.route = 'products'
143 products.save()
144
145def setup_item():
146 items = json.loads(open(frappe.get_app_path('erpnext', 'demo', 'data', 'item.json')).read())
147 for i in items:
148 item = frappe.new_doc('Item')
149 item.update(i)
150 item.default_warehouse = frappe.get_all('Warehouse', filters={'warehouse_name': item.default_warehouse}, limit=1)[0].name
151 item.insert()
152
Rushabh Mehtacca33b22016-07-08 18:24:46 +0530153def setup_warehouse():
154 w = frappe.new_doc('Warehouse')
155 w.warehouse_name = 'Supplier'
156 w.insert()
157
Rushabh Mehtadc8067e2016-06-29 18:38:32 +0530158def setup_currency_exchange():
159 frappe.get_doc({
160 'doctype': 'Currency Exchange',
161 'from_currency': 'EUR',
162 'to_currency': 'USD',
163 'exchange_rate': 1.13
164 }).insert()
165
166 frappe.get_doc({
167 'doctype': 'Currency Exchange',
168 'from_currency': 'CNY',
169 'to_currency': 'USD',
170 'exchange_rate': 0.16
171 }).insert()
172
173def setup_product_bundle():
174 frappe.get_doc({
175 'doctype': 'Product Bundle',
176 'new_item_code': 'Wind Mill A Series with Spare Bearing',
177 'items': [
178 {'item_code': 'Wind Mill A Series', 'qty': 1},
179 {'item_code': 'Bearing Collar', 'qty': 1},
180 {'item_code': 'Bearing Assembly', 'qty': 1},
181 ]
182 }).insert()
183
184def setup_user():
185 frappe.db.sql('delete from tabUser where name not in ("Guest", "Administrator")')
186 for u in json.loads(open(frappe.get_app_path('erpnext', 'demo', 'data', 'user.json')).read()):
187 user = frappe.new_doc("User")
188 user.update(u)
189 user.flags.no_welcome_mail
190 user.password = 'demo'
191 user.insert()
192
Rushabh Mehtacca33b22016-07-08 18:24:46 +0530193def import_json(doctype, submit=False, values=None):
Rushabh Mehtadc8067e2016-06-29 18:38:32 +0530194 frappe.flags.in_import = True
195 data = json.loads(open(frappe.get_app_path('erpnext', 'demo', 'data',
196 frappe.scrub(doctype) + '.json')).read())
197 for d in data:
198 doc = frappe.new_doc(doctype)
199 doc.update(d)
200 doc.insert()
201 if submit:
202 doc.submit()
203
Rushabh Mehta391c0ef2016-07-11 13:01:44 +0530204 frappe.db.commit()
205
Rushabh Mehtadc8067e2016-06-29 18:38:32 +0530206def setup_employee():
207 frappe.db.set_value("HR Settings", None, "emp_created_by", "Naming Series")
208 frappe.db.commit()
209
210 import_json('Employee')
211
212def setup_item_price():
213 frappe.db.sql("delete from `tabItem Price`")
214
215 standard_selling = {
216 "Base Bearing Plate": 28,
217 "Base Plate": 21,
218 "Bearing Assembly": 300,
219 "Bearing Block": 14,
220 "Bearing Collar": 103.6,
221 "Bearing Pipe": 63,
222 "Blade Rib": 46.2,
223 "Disc Collars": 42,
224 "External Disc": 56,
225 "Internal Disc": 70,
226 "Shaft": 340,
227 "Stand": 400,
228 "Upper Bearing Plate": 300,
229 "Wind Mill A Series": 320,
230 "Wind Mill A Series with Spare Bearing": 750,
231 "Wind MIll C Series": 400,
232 "Wind Turbine": 400,
233 "Wing Sheet": 30.8
234 }
235
236 standard_buying = {
237 "Base Bearing Plate": 20,
238 "Base Plate": 28,
239 "Base Plate Un Painted": 16,
240 "Bearing Block": 13,
241 "Bearing Collar": 96.4,
242 "Bearing Pipe": 55,
243 "Blade Rib": 38,
244 "Disc Collars": 34,
245 "External Disc": 50,
246 "Internal Disc": 60,
247 "Shaft": 250,
248 "Stand": 300,
249 "Upper Bearing Plate": 200,
250 "Wing Sheet": 25
251 }
252
253 for price_list in ("standard_buying", "standard_selling"):
254 for item, rate in locals().get(price_list).iteritems():
255 frappe.get_doc({
256 "doctype": "Item Price",
257 "price_list": price_list.replace("_", " ").title(),
258 "item_code": item,
259 "selling": 1 if price_list=="standard_selling" else 0,
260 "buying": 1 if price_list=="standard_buying" else 0,
261 "price_list_rate": rate,
262 "currency": "USD"
263 }).insert()
264
265def setup_salary_structure():
266 f = frappe.get_doc('Fiscal Year', frappe.defaults.get_global_default('fiscal_year'))
267
268 for e in frappe.get_all('Employee', fields=['name', 'date_of_joining']):
269 ss = frappe.new_doc('Salary Structure')
270 ss.employee = e.name
271
272 if not e.date_of_joining:
273 continue
274
275 ss.from_date = e.date_of_joining if (e.date_of_joining
276 and e.date_of_joining > f.year_start_date) else f.year_start_date
277 ss.to_date = f.year_end_date
278 ss.append('earnings', {
Rushabh Mehtacca33b22016-07-08 18:24:46 +0530279 'salary_component': 'Basic',
280 'amount': random.random() * 10000
Rushabh Mehtadc8067e2016-06-29 18:38:32 +0530281 })
282 ss.append('deductions', {
Rushabh Mehtacca33b22016-07-08 18:24:46 +0530283 'salary_component': 'Income Tax',
284 'amount': random.random() * 1000
Rushabh Mehtadc8067e2016-06-29 18:38:32 +0530285 })
Rushabh Mehtacca33b22016-07-08 18:24:46 +0530286
Rushabh Mehtadc8067e2016-06-29 18:38:32 +0530287 ss.insert()
288
289def setup_account():
290 frappe.flags.in_import = True
291 data = json.loads(open(frappe.get_app_path('erpnext', 'demo', 'data',
292 'account.json')).read())
293 for d in data:
294 doc = frappe.new_doc('Account')
295 doc.update(d)
296 doc.parent_account = frappe.db.get_value('Account', {'account_name': doc.parent_account})
297 doc.insert()
298
299def setup_user_roles():
300 if not frappe.db.get_global('demo_hr_user'):
301 user = frappe.get_doc('User', 'CharmaineGaudreau@example.com')
302 user.add_roles('HR User', 'HR Manager', 'Accounts User')
303 frappe.db.set_global('demo_hr_user', user.name)
304
305 if not frappe.db.get_global('demo_sales_user_1'):
306 user = frappe.get_doc('User', 'VakhitaRyzaev@example.com')
307 user.add_roles('Sales User')
308 frappe.db.set_global('demo_sales_user_1', user.name)
309
310 if not frappe.db.get_global('demo_sales_user_2'):
311 user = frappe.get_doc('User', 'GabrielleLoftus@example.com')
312 user.add_roles('Sales User', 'Sales Manager', 'Accounts User')
313 frappe.db.set_global('demo_sales_user_2', user.name)
Rushabh Mehtaea0ff232016-07-07 14:02:26 +0530314
315 if not frappe.db.get_global('demo_purchase_user'):
316 user = frappe.get_doc('User', 'MichalSobczak@example.com')
Rushabh Mehtacca33b22016-07-08 18:24:46 +0530317 user.add_roles('Purchase User', 'Purchase Manager', 'Accounts User', 'Stock User')
Rushabh Mehtaea0ff232016-07-07 14:02:26 +0530318 frappe.db.set_global('demo_purchase_user', user.name)
Rushabh Mehtacca33b22016-07-08 18:24:46 +0530319
320 if not frappe.db.get_global('demo_manufacturing_user'):
321 user = frappe.get_doc('User', 'NuranVerkleij@example.com')
322 user.add_roles('Manufacturing User', 'Stock User', 'Purchase User', 'Accounts User')
323 frappe.db.set_global('demo_manufacturing_user', user.name)
324
325 if not frappe.db.get_global('demo_stock_user'):
326 user = frappe.get_doc('User', 'HatsueKashiwagi@example.com')
327 user.add_roles('Manufacturing User', 'Stock User', 'Purchase User', 'Accounts User')
328 frappe.db.set_global('demo_stock_user', user.name)
329