blob: 52450637c34d2e6038672e25bf16b88e328d0dba [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
Rohit Waghchaure8002d472016-07-13 16:03:05 +05306from frappe.utils import cint, flt
Rushabh Mehtadc8067e2016-06-29 18:38:32 +05307
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()
Rohit Waghchaure8002d472016-07-13 16:03:05 +053030 setup_salary_structure_for_timesheet()
Rushabh Mehtadc8067e2016-06-29 18:38:32 +053031 setup_user_roles()
Rushabh Mehta391c0ef2016-07-11 13:01:44 +053032 frappe.db.commit()
33 frappe.clear_cache()
Rushabh Mehtadc8067e2016-06-29 18:38:32 +053034
35def complete_setup(domain='Manufacturing'):
36 print "Complete Setup..."
37 from frappe.desk.page.setup_wizard.setup_wizard import setup_complete
38
39 if not frappe.get_all('Company', limit=1):
40 setup_complete({
41 "first_name": "Test",
42 "last_name": "User",
43 "email": "test_demo@erpnext.com",
44 "company_tagline": 'Awesome Products and Services',
45 "password": "test",
46 "fy_start_date": "2015-01-01",
47 "fy_end_date": "2015-12-31",
48 "bank_account": "National Bank",
49 "industry": domain,
50 "company_name": data.get(domain).get('company_name'),
51 "chart_of_accounts": "Standard",
52 "company_abbr": ''.join([d[0] for d in data.get(domain).get('company_name').split()]).upper(),
53 "currency": 'USD',
54 "timezone": 'America/New_York',
55 "country": 'United States',
56 "language": "english"
57 })
58
59def setup_demo_page():
60 # home page should always be "start"
61 website_settings = frappe.get_doc("Website Settings", "Website Settings")
62 website_settings.home_page = "demo"
63 website_settings.save()
64
65def setup_fiscal_year():
66 fiscal_year = None
67 for year in xrange(2014, frappe.utils.now_datetime().year + 1, 1):
68 try:
69 fiscal_year = frappe.get_doc({
70 "doctype": "Fiscal Year",
71 "year": frappe.utils.cstr(year),
72 "year_start_date": "{0}-01-01".format(year),
73 "year_end_date": "{0}-12-31".format(year)
74 }).insert()
75 except frappe.DuplicateEntryError:
76 pass
77
78 # set the last fiscal year (current year) as default
79 fiscal_year.set_as_default()
80
81def setup_holiday_list():
82 """Setup Holiday List for the current year"""
83 year = frappe.utils.now_datetime().year
84 holiday_list = frappe.get_doc({
85 "doctype": "Holiday List",
86 "holiday_list_name": str(year),
87 "from_date": "{0}-01-01".format(year),
88 "to_date": "{0}-12-31".format(year),
89 })
90 holiday_list.insert()
91 holiday_list.weekly_off = "Saturday"
92 holiday_list.get_weekly_off_dates()
93 holiday_list.weekly_off = "Sunday"
94 holiday_list.get_weekly_off_dates()
95 holiday_list.save()
96
97 frappe.set_value("Company", erpnext.get_default_company(), "default_holiday_list", holiday_list.name)
98
99def setup_customer():
100 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']
101 for c in customers:
102 frappe.get_doc({
103 "doctype": "Customer",
104 "customer_name": c,
105 "customer_group": "Commercial",
106 "customer_type": random.choice(["Company", "Individual"]),
107 "territory": "Rest Of The World"
108 }).insert()
109
110def setup_supplier():
111 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']
112 for s in suppliers:
113 frappe.get_doc({
114 "doctype": "Supplier",
115 "supplier_name": s,
116 "supplier_type": random.choice(["Services", "Raw Material"]),
117 }).insert()
118
119def setup_workstation():
120 workstations = [u'Drilling Machine 1', u'Lathe 1', u'Assembly Station 1', u'Assembly Station 2', u'Packing and Testing Station']
121 for w in workstations:
122 frappe.get_doc({
123 "doctype": "Workstation",
124 "workstation_name": w,
125 "holiday_list": frappe.get_all("Holiday List")[0].name,
126 "hour_rate_consumable": int(random.random() * 20),
127 "hour_rate_electricity": int(random.random() * 10),
128 "hour_rate_labour": int(random.random() * 40),
129 "hour_rate_rent": int(random.random() * 10),
130 "working_hours": [
131 {
132 "enabled": 1,
133 "start_time": "8:00:00",
134 "end_time": "15:00:00"
135 }
136 ]
137 }).insert()
138
139def show_item_groups_in_website():
140 """set show_in_website=1 for Item Groups"""
141 products = frappe.get_doc("Item Group", "Products")
142 products.show_in_website = 1
143 products.route = 'products'
144 products.save()
145
146def setup_item():
147 items = json.loads(open(frappe.get_app_path('erpnext', 'demo', 'data', 'item.json')).read())
148 for i in items:
149 item = frappe.new_doc('Item')
150 item.update(i)
Rushabh Mehta3ce24d62016-07-11 16:07:06 +0530151 item.min_order_qty = random.randint(10, 30)
Rushabh Mehtadc8067e2016-06-29 18:38:32 +0530152 item.default_warehouse = frappe.get_all('Warehouse', filters={'warehouse_name': item.default_warehouse}, limit=1)[0].name
153 item.insert()
154
Rushabh Mehtacca33b22016-07-08 18:24:46 +0530155def setup_warehouse():
156 w = frappe.new_doc('Warehouse')
157 w.warehouse_name = 'Supplier'
158 w.insert()
159
Rushabh Mehtadc8067e2016-06-29 18:38:32 +0530160def setup_currency_exchange():
161 frappe.get_doc({
162 'doctype': 'Currency Exchange',
163 'from_currency': 'EUR',
164 'to_currency': 'USD',
165 'exchange_rate': 1.13
166 }).insert()
167
168 frappe.get_doc({
169 'doctype': 'Currency Exchange',
170 'from_currency': 'CNY',
171 'to_currency': 'USD',
172 'exchange_rate': 0.16
173 }).insert()
174
175def setup_product_bundle():
176 frappe.get_doc({
177 'doctype': 'Product Bundle',
178 'new_item_code': 'Wind Mill A Series with Spare Bearing',
179 'items': [
180 {'item_code': 'Wind Mill A Series', 'qty': 1},
181 {'item_code': 'Bearing Collar', 'qty': 1},
182 {'item_code': 'Bearing Assembly', 'qty': 1},
183 ]
184 }).insert()
185
186def setup_user():
187 frappe.db.sql('delete from tabUser where name not in ("Guest", "Administrator")')
188 for u in json.loads(open(frappe.get_app_path('erpnext', 'demo', 'data', 'user.json')).read()):
189 user = frappe.new_doc("User")
190 user.update(u)
191 user.flags.no_welcome_mail
192 user.password = 'demo'
193 user.insert()
194
Rushabh Mehtacca33b22016-07-08 18:24:46 +0530195def import_json(doctype, submit=False, values=None):
Rushabh Mehtadc8067e2016-06-29 18:38:32 +0530196 frappe.flags.in_import = True
197 data = json.loads(open(frappe.get_app_path('erpnext', 'demo', 'data',
198 frappe.scrub(doctype) + '.json')).read())
199 for d in data:
200 doc = frappe.new_doc(doctype)
201 doc.update(d)
202 doc.insert()
203 if submit:
204 doc.submit()
205
Rushabh Mehta391c0ef2016-07-11 13:01:44 +0530206 frappe.db.commit()
207
Rushabh Mehtadc8067e2016-06-29 18:38:32 +0530208def setup_employee():
209 frappe.db.set_value("HR Settings", None, "emp_created_by", "Naming Series")
210 frappe.db.commit()
211
212 import_json('Employee')
213
214def setup_item_price():
215 frappe.db.sql("delete from `tabItem Price`")
216
217 standard_selling = {
218 "Base Bearing Plate": 28,
219 "Base Plate": 21,
220 "Bearing Assembly": 300,
221 "Bearing Block": 14,
222 "Bearing Collar": 103.6,
223 "Bearing Pipe": 63,
224 "Blade Rib": 46.2,
225 "Disc Collars": 42,
226 "External Disc": 56,
227 "Internal Disc": 70,
228 "Shaft": 340,
229 "Stand": 400,
230 "Upper Bearing Plate": 300,
231 "Wind Mill A Series": 320,
232 "Wind Mill A Series with Spare Bearing": 750,
233 "Wind MIll C Series": 400,
234 "Wind Turbine": 400,
235 "Wing Sheet": 30.8
236 }
237
238 standard_buying = {
239 "Base Bearing Plate": 20,
240 "Base Plate": 28,
241 "Base Plate Un Painted": 16,
242 "Bearing Block": 13,
243 "Bearing Collar": 96.4,
244 "Bearing Pipe": 55,
245 "Blade Rib": 38,
246 "Disc Collars": 34,
247 "External Disc": 50,
248 "Internal Disc": 60,
249 "Shaft": 250,
250 "Stand": 300,
251 "Upper Bearing Plate": 200,
252 "Wing Sheet": 25
253 }
254
255 for price_list in ("standard_buying", "standard_selling"):
256 for item, rate in locals().get(price_list).iteritems():
257 frappe.get_doc({
258 "doctype": "Item Price",
259 "price_list": price_list.replace("_", " ").title(),
260 "item_code": item,
261 "selling": 1 if price_list=="standard_selling" else 0,
262 "buying": 1 if price_list=="standard_buying" else 0,
263 "price_list_rate": rate,
264 "currency": "USD"
265 }).insert()
266
267def setup_salary_structure():
268 f = frappe.get_doc('Fiscal Year', frappe.defaults.get_global_default('fiscal_year'))
269
270 for e in frappe.get_all('Employee', fields=['name', 'date_of_joining']):
271 ss = frappe.new_doc('Salary Structure')
272 ss.employee = e.name
273
274 if not e.date_of_joining:
275 continue
276
277 ss.from_date = e.date_of_joining if (e.date_of_joining
278 and e.date_of_joining > f.year_start_date) else f.year_start_date
279 ss.to_date = f.year_end_date
280 ss.append('earnings', {
Rushabh Mehtacca33b22016-07-08 18:24:46 +0530281 'salary_component': 'Basic',
282 'amount': random.random() * 10000
Rushabh Mehtadc8067e2016-06-29 18:38:32 +0530283 })
284 ss.append('deductions', {
Rushabh Mehtacca33b22016-07-08 18:24:46 +0530285 'salary_component': 'Income Tax',
286 'amount': random.random() * 1000
Rushabh Mehtadc8067e2016-06-29 18:38:32 +0530287 })
Rushabh Mehtacca33b22016-07-08 18:24:46 +0530288
Rushabh Mehtadc8067e2016-06-29 18:38:32 +0530289 ss.insert()
Rohit Waghchaure8002d472016-07-13 16:03:05 +0530290
291def setup_salary_structure_for_timesheet():
292 for e in frappe.get_all('Salary Structure', fields=['name'], filters={'is_active': 'Yes'}, limit=2):
293 ss_doc = frappe.get_doc("Salary Structure", e.name)
294 ss_doc.salary_slip_based_on_timesheet = 1
295 ss_doc.salary_component = 'Basic'
296 ss_doc.hour_rate = flt(random.random() * 10, 2)
297 ss_doc.save(ignore_permissions=True)
Rushabh Mehtadc8067e2016-06-29 18:38:32 +0530298
299def setup_account():
300 frappe.flags.in_import = True
301 data = json.loads(open(frappe.get_app_path('erpnext', 'demo', 'data',
302 'account.json')).read())
303 for d in data:
304 doc = frappe.new_doc('Account')
305 doc.update(d)
306 doc.parent_account = frappe.db.get_value('Account', {'account_name': doc.parent_account})
307 doc.insert()
308
309def setup_user_roles():
310 if not frappe.db.get_global('demo_hr_user'):
311 user = frappe.get_doc('User', 'CharmaineGaudreau@example.com')
312 user.add_roles('HR User', 'HR Manager', 'Accounts User')
313 frappe.db.set_global('demo_hr_user', user.name)
314
315 if not frappe.db.get_global('demo_sales_user_1'):
316 user = frappe.get_doc('User', 'VakhitaRyzaev@example.com')
317 user.add_roles('Sales User')
318 frappe.db.set_global('demo_sales_user_1', user.name)
319
320 if not frappe.db.get_global('demo_sales_user_2'):
321 user = frappe.get_doc('User', 'GabrielleLoftus@example.com')
322 user.add_roles('Sales User', 'Sales Manager', 'Accounts User')
323 frappe.db.set_global('demo_sales_user_2', user.name)
Rushabh Mehtaea0ff232016-07-07 14:02:26 +0530324
325 if not frappe.db.get_global('demo_purchase_user'):
326 user = frappe.get_doc('User', 'MichalSobczak@example.com')
Rushabh Mehtacca33b22016-07-08 18:24:46 +0530327 user.add_roles('Purchase User', 'Purchase Manager', 'Accounts User', 'Stock User')
Rushabh Mehtaea0ff232016-07-07 14:02:26 +0530328 frappe.db.set_global('demo_purchase_user', user.name)
Rushabh Mehtacca33b22016-07-08 18:24:46 +0530329
330 if not frappe.db.get_global('demo_manufacturing_user'):
331 user = frappe.get_doc('User', 'NuranVerkleij@example.com')
332 user.add_roles('Manufacturing User', 'Stock User', 'Purchase User', 'Accounts User')
333 frappe.db.set_global('demo_manufacturing_user', user.name)
334
335 if not frappe.db.get_global('demo_stock_user'):
336 user = frappe.get_doc('User', 'HatsueKashiwagi@example.com')
337 user.add_roles('Manufacturing User', 'Stock User', 'Purchase User', 'Accounts User')
338 frappe.db.set_global('demo_stock_user', user.name)
339
Rushabh Mehta8cfe18e2016-07-13 11:29:59 +0530340 if not frappe.db.get_global('demo_accounts_user'):
341 user = frappe.get_doc('User', 'LeonAbdulov@example.com')
Rushabh Mehta92d1b8c2016-07-14 15:46:12 +0530342 user.add_roles('Accounts User', 'Accounts Manager', 'Sales User', 'Purchase User')
Rushabh Mehta8cfe18e2016-07-13 11:29:59 +0530343 frappe.db.set_global('demo_accounts_user', user.name)
Rohit Waghchaure8002d472016-07-13 16:03:05 +0530344
345 if not frappe.db.get_global('demo_projects_user'):
346 user = frappe.get_doc('User', 'panca@example.com')
347 user.add_roles('HR User', 'Projects User')
348 frappe.db.set_global('demo_projects_user', user.name)
Rushabh Mehta8cfe18e2016-07-13 11:29:59 +0530349