blob: 336752723e10f9461017ad67c12f8f47a5306194 [file] [log] [blame]
Rushabh Mehtadc8067e2016-06-29 18:38:32 +05301from __future__ import unicode_literals
2
3import random, json
Nabin Hait74edfff2016-07-21 11:39:46 +05304from frappe.utils.make_random import add_random_children, get_random
Rushabh Mehtadc8067e2016-06-29 18:38:32 +05305from erpnext.demo.domains import data
6import frappe, erpnext
Nabin Hait3edefb12016-07-20 16:13:18 +05307from frappe.utils import flt, now_datetime, cstr, nowdate, add_days
Saurabhf589c822016-07-15 18:28:05 +05308from frappe import _
Rushabh Mehtadc8067e2016-06-29 18:38:32 +05309
10def setup_data():
11 domain = frappe.flags.domain
12 complete_setup(domain)
13 setup_demo_page()
14 setup_fiscal_year()
15 setup_holiday_list()
16 setup_customer()
17 setup_supplier()
Nabin Hait3edefb12016-07-20 16:13:18 +053018 import_json("Asset Category")
Rushabh Mehtadc8067e2016-06-29 18:38:32 +053019 setup_item()
Rushabh Mehtacca33b22016-07-08 18:24:46 +053020 setup_warehouse()
Nabin Hait3edefb12016-07-20 16:13:18 +053021 setup_asset()
Rushabh Mehtadc8067e2016-06-29 18:38:32 +053022 import_json('Address')
23 import_json('Contact')
24 setup_workstation()
25 import_json('Operation')
26 import_json('Lead')
27 setup_item_price()
28 show_item_groups_in_website()
29 setup_currency_exchange()
30 import_json('BOM', submit=True)
31 setup_user()
32 setup_employee()
33 setup_salary_structure()
Rohit Waghchaure8002d472016-07-13 16:03:05 +053034 setup_salary_structure_for_timesheet()
Rohit Waghchaure7d439ec2016-07-21 14:50:59 +053035 setup_mode_of_payment()
Saurabhf589c822016-07-15 18:28:05 +053036 setup_account_to_expense_type()
Rushabh Mehtadc8067e2016-06-29 18:38:32 +053037 setup_user_roles()
Nabin Hait74edfff2016-07-21 11:39:46 +053038 setup_budget()
Rohit Waghchaure7d439ec2016-07-21 14:50:59 +053039 setup_pos_profile()
Rushabh Mehta391c0ef2016-07-11 13:01:44 +053040 frappe.db.commit()
41 frappe.clear_cache()
Rushabh Mehtadc8067e2016-06-29 18:38:32 +053042
43def complete_setup(domain='Manufacturing'):
44 print "Complete Setup..."
45 from frappe.desk.page.setup_wizard.setup_wizard import setup_complete
46
47 if not frappe.get_all('Company', limit=1):
48 setup_complete({
49 "first_name": "Test",
50 "last_name": "User",
51 "email": "test_demo@erpnext.com",
52 "company_tagline": 'Awesome Products and Services',
53 "password": "test",
54 "fy_start_date": "2015-01-01",
55 "fy_end_date": "2015-12-31",
56 "bank_account": "National Bank",
Rushabh Mehta04a64a72016-07-22 12:19:18 +053057 "domain": domain,
Rushabh Mehtadc8067e2016-06-29 18:38:32 +053058 "company_name": data.get(domain).get('company_name'),
59 "chart_of_accounts": "Standard",
60 "company_abbr": ''.join([d[0] for d in data.get(domain).get('company_name').split()]).upper(),
61 "currency": 'USD',
62 "timezone": 'America/New_York',
63 "country": 'United States',
64 "language": "english"
65 })
66
67def setup_demo_page():
68 # home page should always be "start"
69 website_settings = frappe.get_doc("Website Settings", "Website Settings")
70 website_settings.home_page = "demo"
71 website_settings.save()
72
73def setup_fiscal_year():
74 fiscal_year = None
Nabin Hait16066262016-07-21 11:00:28 +053075 for year in xrange(2010, now_datetime().year + 1, 1):
Rushabh Mehtadc8067e2016-06-29 18:38:32 +053076 try:
77 fiscal_year = frappe.get_doc({
78 "doctype": "Fiscal Year",
Saurabhf589c822016-07-15 18:28:05 +053079 "year": cstr(year),
Rushabh Mehtadc8067e2016-06-29 18:38:32 +053080 "year_start_date": "{0}-01-01".format(year),
81 "year_end_date": "{0}-12-31".format(year)
82 }).insert()
83 except frappe.DuplicateEntryError:
84 pass
85
86 # set the last fiscal year (current year) as default
87 fiscal_year.set_as_default()
88
89def setup_holiday_list():
90 """Setup Holiday List for the current year"""
Saurabhf589c822016-07-15 18:28:05 +053091 year = now_datetime().year
Rushabh Mehtadc8067e2016-06-29 18:38:32 +053092 holiday_list = frappe.get_doc({
93 "doctype": "Holiday List",
94 "holiday_list_name": str(year),
95 "from_date": "{0}-01-01".format(year),
96 "to_date": "{0}-12-31".format(year),
97 })
98 holiday_list.insert()
99 holiday_list.weekly_off = "Saturday"
100 holiday_list.get_weekly_off_dates()
101 holiday_list.weekly_off = "Sunday"
102 holiday_list.get_weekly_off_dates()
103 holiday_list.save()
104
105 frappe.set_value("Company", erpnext.get_default_company(), "default_holiday_list", holiday_list.name)
106
107def setup_customer():
108 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']
109 for c in customers:
110 frappe.get_doc({
111 "doctype": "Customer",
112 "customer_name": c,
113 "customer_group": "Commercial",
114 "customer_type": random.choice(["Company", "Individual"]),
115 "territory": "Rest Of The World"
116 }).insert()
117
118def setup_supplier():
119 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']
120 for s in suppliers:
121 frappe.get_doc({
122 "doctype": "Supplier",
123 "supplier_name": s,
124 "supplier_type": random.choice(["Services", "Raw Material"]),
125 }).insert()
126
127def setup_workstation():
128 workstations = [u'Drilling Machine 1', u'Lathe 1', u'Assembly Station 1', u'Assembly Station 2', u'Packing and Testing Station']
129 for w in workstations:
130 frappe.get_doc({
131 "doctype": "Workstation",
132 "workstation_name": w,
133 "holiday_list": frappe.get_all("Holiday List")[0].name,
134 "hour_rate_consumable": int(random.random() * 20),
135 "hour_rate_electricity": int(random.random() * 10),
136 "hour_rate_labour": int(random.random() * 40),
137 "hour_rate_rent": int(random.random() * 10),
138 "working_hours": [
139 {
140 "enabled": 1,
141 "start_time": "8:00:00",
142 "end_time": "15:00:00"
143 }
144 ]
145 }).insert()
146
147def show_item_groups_in_website():
148 """set show_in_website=1 for Item Groups"""
149 products = frappe.get_doc("Item Group", "Products")
150 products.show_in_website = 1
151 products.route = 'products'
152 products.save()
153
154def setup_item():
155 items = json.loads(open(frappe.get_app_path('erpnext', 'demo', 'data', 'item.json')).read())
156 for i in items:
157 item = frappe.new_doc('Item')
158 item.update(i)
Rushabh Mehta3ce24d62016-07-11 16:07:06 +0530159 item.min_order_qty = random.randint(10, 30)
Rushabh Mehtadc8067e2016-06-29 18:38:32 +0530160 item.default_warehouse = frappe.get_all('Warehouse', filters={'warehouse_name': item.default_warehouse}, limit=1)[0].name
161 item.insert()
162
Rushabh Mehtacca33b22016-07-08 18:24:46 +0530163def setup_warehouse():
164 w = frappe.new_doc('Warehouse')
165 w.warehouse_name = 'Supplier'
166 w.insert()
Rushabh Mehta04a64a72016-07-22 12:19:18 +0530167
Nabin Hait3edefb12016-07-20 16:13:18 +0530168def setup_asset():
169 assets = json.loads(open(frappe.get_app_path('erpnext', 'demo', 'data', 'asset.json')).read())
170 for d in assets:
171 asset = frappe.new_doc('Asset')
172 asset.update(d)
173 asset.purchase_date = add_days(nowdate(), -random.randint(20, 1500))
174 asset.next_depreciation_date = add_days(asset.purchase_date, 30)
175 asset.warehouse = "Stores - WPL"
176 asset.set_missing_values()
177 asset.make_depreciation_schedule()
178 asset.flags.ignore_validate = True
179 asset.save()
180 asset.submit()
Rushabh Mehtacca33b22016-07-08 18:24:46 +0530181
Rushabh Mehtadc8067e2016-06-29 18:38:32 +0530182def setup_currency_exchange():
183 frappe.get_doc({
184 'doctype': 'Currency Exchange',
185 'from_currency': 'EUR',
186 'to_currency': 'USD',
187 'exchange_rate': 1.13
188 }).insert()
189
190 frappe.get_doc({
191 'doctype': 'Currency Exchange',
192 'from_currency': 'CNY',
193 'to_currency': 'USD',
194 'exchange_rate': 0.16
195 }).insert()
196
197def setup_product_bundle():
198 frappe.get_doc({
199 'doctype': 'Product Bundle',
200 'new_item_code': 'Wind Mill A Series with Spare Bearing',
201 'items': [
202 {'item_code': 'Wind Mill A Series', 'qty': 1},
203 {'item_code': 'Bearing Collar', 'qty': 1},
204 {'item_code': 'Bearing Assembly', 'qty': 1},
205 ]
206 }).insert()
207
208def setup_user():
209 frappe.db.sql('delete from tabUser where name not in ("Guest", "Administrator")')
210 for u in json.loads(open(frappe.get_app_path('erpnext', 'demo', 'data', 'user.json')).read()):
211 user = frappe.new_doc("User")
212 user.update(u)
213 user.flags.no_welcome_mail
214 user.password = 'demo'
215 user.insert()
216
Rushabh Mehtacca33b22016-07-08 18:24:46 +0530217def import_json(doctype, submit=False, values=None):
Rushabh Mehtadc8067e2016-06-29 18:38:32 +0530218 frappe.flags.in_import = True
219 data = json.loads(open(frappe.get_app_path('erpnext', 'demo', 'data',
220 frappe.scrub(doctype) + '.json')).read())
221 for d in data:
222 doc = frappe.new_doc(doctype)
223 doc.update(d)
224 doc.insert()
225 if submit:
226 doc.submit()
227
Rushabh Mehta391c0ef2016-07-11 13:01:44 +0530228 frappe.db.commit()
229
Rushabh Mehtadc8067e2016-06-29 18:38:32 +0530230def setup_employee():
231 frappe.db.set_value("HR Settings", None, "emp_created_by", "Naming Series")
232 frappe.db.commit()
233
234 import_json('Employee')
235
236def setup_item_price():
237 frappe.db.sql("delete from `tabItem Price`")
238
239 standard_selling = {
240 "Base Bearing Plate": 28,
241 "Base Plate": 21,
242 "Bearing Assembly": 300,
243 "Bearing Block": 14,
244 "Bearing Collar": 103.6,
245 "Bearing Pipe": 63,
246 "Blade Rib": 46.2,
247 "Disc Collars": 42,
248 "External Disc": 56,
249 "Internal Disc": 70,
250 "Shaft": 340,
251 "Stand": 400,
252 "Upper Bearing Plate": 300,
253 "Wind Mill A Series": 320,
254 "Wind Mill A Series with Spare Bearing": 750,
255 "Wind MIll C Series": 400,
256 "Wind Turbine": 400,
257 "Wing Sheet": 30.8
258 }
259
260 standard_buying = {
261 "Base Bearing Plate": 20,
262 "Base Plate": 28,
263 "Base Plate Un Painted": 16,
264 "Bearing Block": 13,
265 "Bearing Collar": 96.4,
266 "Bearing Pipe": 55,
267 "Blade Rib": 38,
268 "Disc Collars": 34,
269 "External Disc": 50,
270 "Internal Disc": 60,
271 "Shaft": 250,
272 "Stand": 300,
273 "Upper Bearing Plate": 200,
274 "Wing Sheet": 25
275 }
276
277 for price_list in ("standard_buying", "standard_selling"):
278 for item, rate in locals().get(price_list).iteritems():
279 frappe.get_doc({
280 "doctype": "Item Price",
281 "price_list": price_list.replace("_", " ").title(),
282 "item_code": item,
283 "selling": 1 if price_list=="standard_selling" else 0,
284 "buying": 1 if price_list=="standard_buying" else 0,
285 "price_list_rate": rate,
286 "currency": "USD"
287 }).insert()
288
289def setup_salary_structure():
290 f = frappe.get_doc('Fiscal Year', frappe.defaults.get_global_default('fiscal_year'))
291
292 for e in frappe.get_all('Employee', fields=['name', 'date_of_joining']):
293 ss = frappe.new_doc('Salary Structure')
294 ss.employee = e.name
295
296 if not e.date_of_joining:
297 continue
298
299 ss.from_date = e.date_of_joining if (e.date_of_joining
300 and e.date_of_joining > f.year_start_date) else f.year_start_date
301 ss.to_date = f.year_end_date
302 ss.append('earnings', {
Rushabh Mehtacca33b22016-07-08 18:24:46 +0530303 'salary_component': 'Basic',
304 'amount': random.random() * 10000
Rushabh Mehtadc8067e2016-06-29 18:38:32 +0530305 })
306 ss.append('deductions', {
Rushabh Mehtacca33b22016-07-08 18:24:46 +0530307 'salary_component': 'Income Tax',
308 'amount': random.random() * 1000
Rushabh Mehtadc8067e2016-06-29 18:38:32 +0530309 })
Rushabh Mehtacca33b22016-07-08 18:24:46 +0530310
Rushabh Mehtadc8067e2016-06-29 18:38:32 +0530311 ss.insert()
Rushabh Mehta04a64a72016-07-22 12:19:18 +0530312
Rohit Waghchaure8002d472016-07-13 16:03:05 +0530313def setup_salary_structure_for_timesheet():
314 for e in frappe.get_all('Salary Structure', fields=['name'], filters={'is_active': 'Yes'}, limit=2):
315 ss_doc = frappe.get_doc("Salary Structure", e.name)
316 ss_doc.salary_slip_based_on_timesheet = 1
317 ss_doc.salary_component = 'Basic'
318 ss_doc.hour_rate = flt(random.random() * 10, 2)
319 ss_doc.save(ignore_permissions=True)
Rushabh Mehtadc8067e2016-06-29 18:38:32 +0530320
Rohit Waghchaure7d439ec2016-07-21 14:50:59 +0530321def setup_mode_of_payment():
322 account_dict = {'Cash': 'Cash - WPL', 'Bank': 'National Bank - WPL'}
323 for payment_mode in frappe.get_all('Mode of Payment', fields = ["name", "type"]):
324 if payment_mode.type:
325 mop = frappe.get_doc('Mode of Payment', payment_mode.name)
326 mop.append('accounts', {
327 'company': erpnext.get_default_company(),
328 'default_account': account_dict.get(payment_mode.type)
329 })
330
331 mop.save(ignore_permissions=True)
332
Rushabh Mehtadc8067e2016-06-29 18:38:32 +0530333def setup_account():
334 frappe.flags.in_import = True
335 data = json.loads(open(frappe.get_app_path('erpnext', 'demo', 'data',
336 'account.json')).read())
337 for d in data:
338 doc = frappe.new_doc('Account')
339 doc.update(d)
340 doc.parent_account = frappe.db.get_value('Account', {'account_name': doc.parent_account})
341 doc.insert()
342
Saurabhf589c822016-07-15 18:28:05 +0530343def setup_account_to_expense_type():
344 expense_types = [{'name': _('Calls'), "account": "Sales Expenses - WPL"},
345 {'name': _('Food'), "account": "Entertainment Expenses - WPL"},
346 {'name': _('Medical'), "account": "Utility Expenses - WPL"},
347 {'name': _('Others'), "account": "Miscellaneous Expenses - WPL"},
348 {'name': _('Travel'), "account": "Travel Expenses - WPL"}]
Rushabh Mehta04a64a72016-07-22 12:19:18 +0530349
Saurabhf589c822016-07-15 18:28:05 +0530350 for expense_type in expense_types:
351 doc = frappe.get_doc("Expense Claim Type", expense_type["name"])
Saurabh718d8352016-07-18 15:20:47 +0530352 doc.append("accounts", {
353 "company" : erpnext.get_default_company(),
354 "default_account" : expense_type["account"]
355 })
Saurabhf589c822016-07-15 18:28:05 +0530356 doc.save(ignore_permissions=True)
Rushabh Mehta04a64a72016-07-22 12:19:18 +0530357
Nabin Hait74edfff2016-07-21 11:39:46 +0530358def setup_budget():
359 fiscal_years = frappe.get_all("Fiscal Year", order_by="year_start_date")[-2:]
Rushabh Mehta04a64a72016-07-22 12:19:18 +0530360
Nabin Hait74edfff2016-07-21 11:39:46 +0530361 for fy in fiscal_years:
362 budget = frappe.new_doc("Budget")
363 budget.cost_center = get_random("Cost Center")
364 budget.fiscal_year = fy.name
365 budget.action_if_annual_budget_exceeded = "Warn"
366 expense_ledger_count = frappe.db.count("Account", {"is_group": "0", "root_type": "Expense"})
367
368 add_random_children(budget, "accounts", rows=random.randint(10, expense_ledger_count), randomize = { "account": ("Account", {"is_group": "0", "root_type": "Expense"})
369 }, unique="account")
Rushabh Mehta04a64a72016-07-22 12:19:18 +0530370
Nabin Hait74edfff2016-07-21 11:39:46 +0530371 for d in budget.accounts:
372 d.budget_amount = random.randint(5, 100) * 10000
Rushabh Mehta04a64a72016-07-22 12:19:18 +0530373
Nabin Hait74edfff2016-07-21 11:39:46 +0530374 budget.save()
375 budget.submit()
Rushabh Mehta04a64a72016-07-22 12:19:18 +0530376
377
Rushabh Mehtadc8067e2016-06-29 18:38:32 +0530378def setup_user_roles():
379 if not frappe.db.get_global('demo_hr_user'):
380 user = frappe.get_doc('User', 'CharmaineGaudreau@example.com')
381 user.add_roles('HR User', 'HR Manager', 'Accounts User')
382 frappe.db.set_global('demo_hr_user', user.name)
383
384 if not frappe.db.get_global('demo_sales_user_1'):
385 user = frappe.get_doc('User', 'VakhitaRyzaev@example.com')
386 user.add_roles('Sales User')
387 frappe.db.set_global('demo_sales_user_1', user.name)
388
389 if not frappe.db.get_global('demo_sales_user_2'):
390 user = frappe.get_doc('User', 'GabrielleLoftus@example.com')
391 user.add_roles('Sales User', 'Sales Manager', 'Accounts User')
392 frappe.db.set_global('demo_sales_user_2', user.name)
Rushabh Mehtaea0ff232016-07-07 14:02:26 +0530393
394 if not frappe.db.get_global('demo_purchase_user'):
395 user = frappe.get_doc('User', 'MichalSobczak@example.com')
Rushabh Mehtacca33b22016-07-08 18:24:46 +0530396 user.add_roles('Purchase User', 'Purchase Manager', 'Accounts User', 'Stock User')
Rushabh Mehtaea0ff232016-07-07 14:02:26 +0530397 frappe.db.set_global('demo_purchase_user', user.name)
Rushabh Mehtacca33b22016-07-08 18:24:46 +0530398
399 if not frappe.db.get_global('demo_manufacturing_user'):
400 user = frappe.get_doc('User', 'NuranVerkleij@example.com')
401 user.add_roles('Manufacturing User', 'Stock User', 'Purchase User', 'Accounts User')
402 frappe.db.set_global('demo_manufacturing_user', user.name)
403
404 if not frappe.db.get_global('demo_stock_user'):
405 user = frappe.get_doc('User', 'HatsueKashiwagi@example.com')
406 user.add_roles('Manufacturing User', 'Stock User', 'Purchase User', 'Accounts User')
407 frappe.db.set_global('demo_stock_user', user.name)
408
Rushabh Mehta8cfe18e2016-07-13 11:29:59 +0530409 if not frappe.db.get_global('demo_accounts_user'):
410 user = frappe.get_doc('User', 'LeonAbdulov@example.com')
Rushabh Mehta92d1b8c2016-07-14 15:46:12 +0530411 user.add_roles('Accounts User', 'Accounts Manager', 'Sales User', 'Purchase User')
Rushabh Mehta8cfe18e2016-07-13 11:29:59 +0530412 frappe.db.set_global('demo_accounts_user', user.name)
Rushabh Mehta04a64a72016-07-22 12:19:18 +0530413
Rohit Waghchaure8002d472016-07-13 16:03:05 +0530414 if not frappe.db.get_global('demo_projects_user'):
415 user = frappe.get_doc('User', 'panca@example.com')
416 user.add_roles('HR User', 'Projects User')
417 frappe.db.set_global('demo_projects_user', user.name)
Rushabh Mehta8cfe18e2016-07-13 11:29:59 +0530418
Rohit Waghchaure7d439ec2016-07-21 14:50:59 +0530419def setup_pos_profile():
420 pos = frappe.new_doc('POS Profile')
421 pos.user = frappe.db.get_global('demo_accounts_user')
422 pos.naming_series = 'SINV-'
423 pos.update_stock = 0
424 pos.write_off_account = 'Cost of Goods Sold - WPL'
425 pos.write_off_cost_center = 'Main - WPL'
426
427 pos.append('payments', {
428 'mode_of_payment': frappe.db.get_value('Mode of Payment', {'type': 'Cash'}, 'name'),
429 'amount': 0.0
430 })
431
432 pos.insert()