blob: 918fd5484fabbddaae03a0dfe68e6c9af02a054d [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()
Saurabhf589c822016-07-15 18:28:05 +053035 setup_account_to_expense_type()
Rushabh Mehtadc8067e2016-06-29 18:38:32 +053036 setup_user_roles()
Nabin Hait74edfff2016-07-21 11:39:46 +053037 setup_budget()
Rushabh Mehta391c0ef2016-07-11 13:01:44 +053038 frappe.db.commit()
39 frappe.clear_cache()
Rushabh Mehtadc8067e2016-06-29 18:38:32 +053040
41def complete_setup(domain='Manufacturing'):
42 print "Complete Setup..."
43 from frappe.desk.page.setup_wizard.setup_wizard import setup_complete
44
45 if not frappe.get_all('Company', limit=1):
46 setup_complete({
47 "first_name": "Test",
48 "last_name": "User",
49 "email": "test_demo@erpnext.com",
50 "company_tagline": 'Awesome Products and Services',
51 "password": "test",
52 "fy_start_date": "2015-01-01",
53 "fy_end_date": "2015-12-31",
54 "bank_account": "National Bank",
Rushabh Mehta04a64a72016-07-22 12:19:18 +053055 "domain": domain,
Rushabh Mehtadc8067e2016-06-29 18:38:32 +053056 "company_name": data.get(domain).get('company_name'),
57 "chart_of_accounts": "Standard",
58 "company_abbr": ''.join([d[0] for d in data.get(domain).get('company_name').split()]).upper(),
59 "currency": 'USD',
60 "timezone": 'America/New_York',
61 "country": 'United States',
62 "language": "english"
63 })
64
65def setup_demo_page():
66 # home page should always be "start"
67 website_settings = frappe.get_doc("Website Settings", "Website Settings")
68 website_settings.home_page = "demo"
69 website_settings.save()
70
71def setup_fiscal_year():
72 fiscal_year = None
Nabin Hait16066262016-07-21 11:00:28 +053073 for year in xrange(2010, now_datetime().year + 1, 1):
Rushabh Mehtadc8067e2016-06-29 18:38:32 +053074 try:
75 fiscal_year = frappe.get_doc({
76 "doctype": "Fiscal Year",
Saurabhf589c822016-07-15 18:28:05 +053077 "year": cstr(year),
Rushabh Mehtadc8067e2016-06-29 18:38:32 +053078 "year_start_date": "{0}-01-01".format(year),
79 "year_end_date": "{0}-12-31".format(year)
80 }).insert()
81 except frappe.DuplicateEntryError:
82 pass
83
84 # set the last fiscal year (current year) as default
85 fiscal_year.set_as_default()
86
87def setup_holiday_list():
88 """Setup Holiday List for the current year"""
Saurabhf589c822016-07-15 18:28:05 +053089 year = now_datetime().year
Rushabh Mehtadc8067e2016-06-29 18:38:32 +053090 holiday_list = frappe.get_doc({
91 "doctype": "Holiday List",
92 "holiday_list_name": str(year),
93 "from_date": "{0}-01-01".format(year),
94 "to_date": "{0}-12-31".format(year),
95 })
96 holiday_list.insert()
97 holiday_list.weekly_off = "Saturday"
98 holiday_list.get_weekly_off_dates()
99 holiday_list.weekly_off = "Sunday"
100 holiday_list.get_weekly_off_dates()
101 holiday_list.save()
102
103 frappe.set_value("Company", erpnext.get_default_company(), "default_holiday_list", holiday_list.name)
104
105def setup_customer():
106 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']
107 for c in customers:
108 frappe.get_doc({
109 "doctype": "Customer",
110 "customer_name": c,
111 "customer_group": "Commercial",
112 "customer_type": random.choice(["Company", "Individual"]),
113 "territory": "Rest Of The World"
114 }).insert()
115
116def setup_supplier():
117 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']
118 for s in suppliers:
119 frappe.get_doc({
120 "doctype": "Supplier",
121 "supplier_name": s,
122 "supplier_type": random.choice(["Services", "Raw Material"]),
123 }).insert()
124
125def setup_workstation():
126 workstations = [u'Drilling Machine 1', u'Lathe 1', u'Assembly Station 1', u'Assembly Station 2', u'Packing and Testing Station']
127 for w in workstations:
128 frappe.get_doc({
129 "doctype": "Workstation",
130 "workstation_name": w,
131 "holiday_list": frappe.get_all("Holiday List")[0].name,
132 "hour_rate_consumable": int(random.random() * 20),
133 "hour_rate_electricity": int(random.random() * 10),
134 "hour_rate_labour": int(random.random() * 40),
135 "hour_rate_rent": int(random.random() * 10),
136 "working_hours": [
137 {
138 "enabled": 1,
139 "start_time": "8:00:00",
140 "end_time": "15:00:00"
141 }
142 ]
143 }).insert()
144
145def show_item_groups_in_website():
146 """set show_in_website=1 for Item Groups"""
147 products = frappe.get_doc("Item Group", "Products")
148 products.show_in_website = 1
149 products.route = 'products'
150 products.save()
151
152def setup_item():
153 items = json.loads(open(frappe.get_app_path('erpnext', 'demo', 'data', 'item.json')).read())
154 for i in items:
155 item = frappe.new_doc('Item')
156 item.update(i)
Rushabh Mehta3ce24d62016-07-11 16:07:06 +0530157 item.min_order_qty = random.randint(10, 30)
Rushabh Mehtadc8067e2016-06-29 18:38:32 +0530158 item.default_warehouse = frappe.get_all('Warehouse', filters={'warehouse_name': item.default_warehouse}, limit=1)[0].name
159 item.insert()
160
Rushabh Mehtacca33b22016-07-08 18:24:46 +0530161def setup_warehouse():
162 w = frappe.new_doc('Warehouse')
163 w.warehouse_name = 'Supplier'
164 w.insert()
Rushabh Mehta04a64a72016-07-22 12:19:18 +0530165
Nabin Hait3edefb12016-07-20 16:13:18 +0530166def setup_asset():
167 assets = json.loads(open(frappe.get_app_path('erpnext', 'demo', 'data', 'asset.json')).read())
168 for d in assets:
169 asset = frappe.new_doc('Asset')
170 asset.update(d)
171 asset.purchase_date = add_days(nowdate(), -random.randint(20, 1500))
172 asset.next_depreciation_date = add_days(asset.purchase_date, 30)
173 asset.warehouse = "Stores - WPL"
174 asset.set_missing_values()
175 asset.make_depreciation_schedule()
176 asset.flags.ignore_validate = True
177 asset.save()
178 asset.submit()
Rushabh Mehtacca33b22016-07-08 18:24:46 +0530179
Rushabh Mehtadc8067e2016-06-29 18:38:32 +0530180def setup_currency_exchange():
181 frappe.get_doc({
182 'doctype': 'Currency Exchange',
183 'from_currency': 'EUR',
184 'to_currency': 'USD',
185 'exchange_rate': 1.13
186 }).insert()
187
188 frappe.get_doc({
189 'doctype': 'Currency Exchange',
190 'from_currency': 'CNY',
191 'to_currency': 'USD',
192 'exchange_rate': 0.16
193 }).insert()
194
195def setup_product_bundle():
196 frappe.get_doc({
197 'doctype': 'Product Bundle',
198 'new_item_code': 'Wind Mill A Series with Spare Bearing',
199 'items': [
200 {'item_code': 'Wind Mill A Series', 'qty': 1},
201 {'item_code': 'Bearing Collar', 'qty': 1},
202 {'item_code': 'Bearing Assembly', 'qty': 1},
203 ]
204 }).insert()
205
206def setup_user():
207 frappe.db.sql('delete from tabUser where name not in ("Guest", "Administrator")')
208 for u in json.loads(open(frappe.get_app_path('erpnext', 'demo', 'data', 'user.json')).read()):
209 user = frappe.new_doc("User")
210 user.update(u)
211 user.flags.no_welcome_mail
212 user.password = 'demo'
213 user.insert()
214
Rushabh Mehtacca33b22016-07-08 18:24:46 +0530215def import_json(doctype, submit=False, values=None):
Rushabh Mehtadc8067e2016-06-29 18:38:32 +0530216 frappe.flags.in_import = True
217 data = json.loads(open(frappe.get_app_path('erpnext', 'demo', 'data',
218 frappe.scrub(doctype) + '.json')).read())
219 for d in data:
220 doc = frappe.new_doc(doctype)
221 doc.update(d)
222 doc.insert()
223 if submit:
224 doc.submit()
225
Rushabh Mehta391c0ef2016-07-11 13:01:44 +0530226 frappe.db.commit()
227
Rushabh Mehtadc8067e2016-06-29 18:38:32 +0530228def setup_employee():
229 frappe.db.set_value("HR Settings", None, "emp_created_by", "Naming Series")
230 frappe.db.commit()
231
232 import_json('Employee')
233
234def setup_item_price():
235 frappe.db.sql("delete from `tabItem Price`")
236
237 standard_selling = {
238 "Base Bearing Plate": 28,
239 "Base Plate": 21,
240 "Bearing Assembly": 300,
241 "Bearing Block": 14,
242 "Bearing Collar": 103.6,
243 "Bearing Pipe": 63,
244 "Blade Rib": 46.2,
245 "Disc Collars": 42,
246 "External Disc": 56,
247 "Internal Disc": 70,
248 "Shaft": 340,
249 "Stand": 400,
250 "Upper Bearing Plate": 300,
251 "Wind Mill A Series": 320,
252 "Wind Mill A Series with Spare Bearing": 750,
253 "Wind MIll C Series": 400,
254 "Wind Turbine": 400,
255 "Wing Sheet": 30.8
256 }
257
258 standard_buying = {
259 "Base Bearing Plate": 20,
260 "Base Plate": 28,
261 "Base Plate Un Painted": 16,
262 "Bearing Block": 13,
263 "Bearing Collar": 96.4,
264 "Bearing Pipe": 55,
265 "Blade Rib": 38,
266 "Disc Collars": 34,
267 "External Disc": 50,
268 "Internal Disc": 60,
269 "Shaft": 250,
270 "Stand": 300,
271 "Upper Bearing Plate": 200,
272 "Wing Sheet": 25
273 }
274
275 for price_list in ("standard_buying", "standard_selling"):
276 for item, rate in locals().get(price_list).iteritems():
277 frappe.get_doc({
278 "doctype": "Item Price",
279 "price_list": price_list.replace("_", " ").title(),
280 "item_code": item,
281 "selling": 1 if price_list=="standard_selling" else 0,
282 "buying": 1 if price_list=="standard_buying" else 0,
283 "price_list_rate": rate,
284 "currency": "USD"
285 }).insert()
286
287def setup_salary_structure():
288 f = frappe.get_doc('Fiscal Year', frappe.defaults.get_global_default('fiscal_year'))
289
290 for e in frappe.get_all('Employee', fields=['name', 'date_of_joining']):
291 ss = frappe.new_doc('Salary Structure')
292 ss.employee = e.name
293
294 if not e.date_of_joining:
295 continue
296
297 ss.from_date = e.date_of_joining if (e.date_of_joining
298 and e.date_of_joining > f.year_start_date) else f.year_start_date
299 ss.to_date = f.year_end_date
300 ss.append('earnings', {
Rushabh Mehtacca33b22016-07-08 18:24:46 +0530301 'salary_component': 'Basic',
302 'amount': random.random() * 10000
Rushabh Mehtadc8067e2016-06-29 18:38:32 +0530303 })
304 ss.append('deductions', {
Rushabh Mehtacca33b22016-07-08 18:24:46 +0530305 'salary_component': 'Income Tax',
306 'amount': random.random() * 1000
Rushabh Mehtadc8067e2016-06-29 18:38:32 +0530307 })
Rushabh Mehtacca33b22016-07-08 18:24:46 +0530308
Rushabh Mehtadc8067e2016-06-29 18:38:32 +0530309 ss.insert()
Rushabh Mehta04a64a72016-07-22 12:19:18 +0530310
Rohit Waghchaure8002d472016-07-13 16:03:05 +0530311def setup_salary_structure_for_timesheet():
312 for e in frappe.get_all('Salary Structure', fields=['name'], filters={'is_active': 'Yes'}, limit=2):
313 ss_doc = frappe.get_doc("Salary Structure", e.name)
314 ss_doc.salary_slip_based_on_timesheet = 1
315 ss_doc.salary_component = 'Basic'
316 ss_doc.hour_rate = flt(random.random() * 10, 2)
317 ss_doc.save(ignore_permissions=True)
Rushabh Mehtadc8067e2016-06-29 18:38:32 +0530318
319def setup_account():
320 frappe.flags.in_import = True
321 data = json.loads(open(frappe.get_app_path('erpnext', 'demo', 'data',
322 'account.json')).read())
323 for d in data:
324 doc = frappe.new_doc('Account')
325 doc.update(d)
326 doc.parent_account = frappe.db.get_value('Account', {'account_name': doc.parent_account})
327 doc.insert()
328
Saurabhf589c822016-07-15 18:28:05 +0530329def setup_account_to_expense_type():
330 expense_types = [{'name': _('Calls'), "account": "Sales Expenses - WPL"},
331 {'name': _('Food'), "account": "Entertainment Expenses - WPL"},
332 {'name': _('Medical'), "account": "Utility Expenses - WPL"},
333 {'name': _('Others'), "account": "Miscellaneous Expenses - WPL"},
334 {'name': _('Travel'), "account": "Travel Expenses - WPL"}]
Rushabh Mehta04a64a72016-07-22 12:19:18 +0530335
Saurabhf589c822016-07-15 18:28:05 +0530336 for expense_type in expense_types:
337 doc = frappe.get_doc("Expense Claim Type", expense_type["name"])
Saurabh718d8352016-07-18 15:20:47 +0530338 doc.append("accounts", {
339 "company" : erpnext.get_default_company(),
340 "default_account" : expense_type["account"]
341 })
Saurabhf589c822016-07-15 18:28:05 +0530342 doc.save(ignore_permissions=True)
Rushabh Mehta04a64a72016-07-22 12:19:18 +0530343
Nabin Hait74edfff2016-07-21 11:39:46 +0530344def setup_budget():
345 fiscal_years = frappe.get_all("Fiscal Year", order_by="year_start_date")[-2:]
Rushabh Mehta04a64a72016-07-22 12:19:18 +0530346
Nabin Hait74edfff2016-07-21 11:39:46 +0530347 for fy in fiscal_years:
348 budget = frappe.new_doc("Budget")
349 budget.cost_center = get_random("Cost Center")
350 budget.fiscal_year = fy.name
351 budget.action_if_annual_budget_exceeded = "Warn"
352 expense_ledger_count = frappe.db.count("Account", {"is_group": "0", "root_type": "Expense"})
353
354 add_random_children(budget, "accounts", rows=random.randint(10, expense_ledger_count), randomize = { "account": ("Account", {"is_group": "0", "root_type": "Expense"})
355 }, unique="account")
Rushabh Mehta04a64a72016-07-22 12:19:18 +0530356
Nabin Hait74edfff2016-07-21 11:39:46 +0530357 for d in budget.accounts:
358 d.budget_amount = random.randint(5, 100) * 10000
Rushabh Mehta04a64a72016-07-22 12:19:18 +0530359
Nabin Hait74edfff2016-07-21 11:39:46 +0530360 budget.save()
361 budget.submit()
Rushabh Mehta04a64a72016-07-22 12:19:18 +0530362
363
Rushabh Mehtadc8067e2016-06-29 18:38:32 +0530364def setup_user_roles():
365 if not frappe.db.get_global('demo_hr_user'):
366 user = frappe.get_doc('User', 'CharmaineGaudreau@example.com')
367 user.add_roles('HR User', 'HR Manager', 'Accounts User')
368 frappe.db.set_global('demo_hr_user', user.name)
369
370 if not frappe.db.get_global('demo_sales_user_1'):
371 user = frappe.get_doc('User', 'VakhitaRyzaev@example.com')
372 user.add_roles('Sales User')
373 frappe.db.set_global('demo_sales_user_1', user.name)
374
375 if not frappe.db.get_global('demo_sales_user_2'):
376 user = frappe.get_doc('User', 'GabrielleLoftus@example.com')
377 user.add_roles('Sales User', 'Sales Manager', 'Accounts User')
378 frappe.db.set_global('demo_sales_user_2', user.name)
Rushabh Mehtaea0ff232016-07-07 14:02:26 +0530379
380 if not frappe.db.get_global('demo_purchase_user'):
381 user = frappe.get_doc('User', 'MichalSobczak@example.com')
Rushabh Mehtacca33b22016-07-08 18:24:46 +0530382 user.add_roles('Purchase User', 'Purchase Manager', 'Accounts User', 'Stock User')
Rushabh Mehtaea0ff232016-07-07 14:02:26 +0530383 frappe.db.set_global('demo_purchase_user', user.name)
Rushabh Mehtacca33b22016-07-08 18:24:46 +0530384
385 if not frappe.db.get_global('demo_manufacturing_user'):
386 user = frappe.get_doc('User', 'NuranVerkleij@example.com')
387 user.add_roles('Manufacturing User', 'Stock User', 'Purchase User', 'Accounts User')
388 frappe.db.set_global('demo_manufacturing_user', user.name)
389
390 if not frappe.db.get_global('demo_stock_user'):
391 user = frappe.get_doc('User', 'HatsueKashiwagi@example.com')
392 user.add_roles('Manufacturing User', 'Stock User', 'Purchase User', 'Accounts User')
393 frappe.db.set_global('demo_stock_user', user.name)
394
Rushabh Mehta8cfe18e2016-07-13 11:29:59 +0530395 if not frappe.db.get_global('demo_accounts_user'):
396 user = frappe.get_doc('User', 'LeonAbdulov@example.com')
Rushabh Mehta92d1b8c2016-07-14 15:46:12 +0530397 user.add_roles('Accounts User', 'Accounts Manager', 'Sales User', 'Purchase User')
Rushabh Mehta8cfe18e2016-07-13 11:29:59 +0530398 frappe.db.set_global('demo_accounts_user', user.name)
Rushabh Mehta04a64a72016-07-22 12:19:18 +0530399
Rohit Waghchaure8002d472016-07-13 16:03:05 +0530400 if not frappe.db.get_global('demo_projects_user'):
401 user = frappe.get_doc('User', 'panca@example.com')
402 user.add_roles('HR User', 'Projects User')
403 frappe.db.set_global('demo_projects_user', user.name)
Rushabh Mehta8cfe18e2016-07-13 11:29:59 +0530404