Rushabh Mehta | dc8067e | 2016-06-29 18:38:32 +0530 | [diff] [blame] | 1 | from __future__ import unicode_literals |
| 2 | |
| 3 | import random, json |
| 4 | from erpnext.demo.domains import data |
| 5 | import frappe, erpnext |
Nabin Hait | 3edefb1 | 2016-07-20 16:13:18 +0530 | [diff] [blame] | 6 | from frappe.utils import flt, now_datetime, cstr, nowdate, add_days |
Saurabh | f589c82 | 2016-07-15 18:28:05 +0530 | [diff] [blame] | 7 | from frappe import _ |
Rushabh Mehta | dc8067e | 2016-06-29 18:38:32 +0530 | [diff] [blame] | 8 | |
| 9 | def setup_data(): |
| 10 | domain = frappe.flags.domain |
| 11 | complete_setup(domain) |
| 12 | setup_demo_page() |
| 13 | setup_fiscal_year() |
| 14 | setup_holiday_list() |
| 15 | setup_customer() |
| 16 | setup_supplier() |
Nabin Hait | 3edefb1 | 2016-07-20 16:13:18 +0530 | [diff] [blame] | 17 | import_json("Asset Category") |
Rushabh Mehta | dc8067e | 2016-06-29 18:38:32 +0530 | [diff] [blame] | 18 | setup_item() |
Rushabh Mehta | cca33b2 | 2016-07-08 18:24:46 +0530 | [diff] [blame] | 19 | setup_warehouse() |
Nabin Hait | 3edefb1 | 2016-07-20 16:13:18 +0530 | [diff] [blame] | 20 | setup_asset() |
Rushabh Mehta | dc8067e | 2016-06-29 18:38:32 +0530 | [diff] [blame] | 21 | import_json('Address') |
| 22 | import_json('Contact') |
| 23 | setup_workstation() |
| 24 | import_json('Operation') |
| 25 | import_json('Lead') |
| 26 | setup_item_price() |
| 27 | show_item_groups_in_website() |
| 28 | setup_currency_exchange() |
| 29 | import_json('BOM', submit=True) |
| 30 | setup_user() |
| 31 | setup_employee() |
| 32 | setup_salary_structure() |
Rohit Waghchaure | 8002d47 | 2016-07-13 16:03:05 +0530 | [diff] [blame] | 33 | setup_salary_structure_for_timesheet() |
Saurabh | f589c82 | 2016-07-15 18:28:05 +0530 | [diff] [blame] | 34 | setup_account_to_expense_type() |
Rushabh Mehta | dc8067e | 2016-06-29 18:38:32 +0530 | [diff] [blame] | 35 | setup_user_roles() |
Rushabh Mehta | 391c0ef | 2016-07-11 13:01:44 +0530 | [diff] [blame] | 36 | frappe.db.commit() |
| 37 | frappe.clear_cache() |
Rushabh Mehta | dc8067e | 2016-06-29 18:38:32 +0530 | [diff] [blame] | 38 | |
| 39 | def complete_setup(domain='Manufacturing'): |
| 40 | print "Complete Setup..." |
| 41 | from frappe.desk.page.setup_wizard.setup_wizard import setup_complete |
| 42 | |
| 43 | if not frappe.get_all('Company', limit=1): |
| 44 | setup_complete({ |
| 45 | "first_name": "Test", |
| 46 | "last_name": "User", |
| 47 | "email": "test_demo@erpnext.com", |
| 48 | "company_tagline": 'Awesome Products and Services', |
| 49 | "password": "test", |
| 50 | "fy_start_date": "2015-01-01", |
| 51 | "fy_end_date": "2015-12-31", |
| 52 | "bank_account": "National Bank", |
| 53 | "industry": domain, |
| 54 | "company_name": data.get(domain).get('company_name'), |
| 55 | "chart_of_accounts": "Standard", |
| 56 | "company_abbr": ''.join([d[0] for d in data.get(domain).get('company_name').split()]).upper(), |
| 57 | "currency": 'USD', |
| 58 | "timezone": 'America/New_York', |
| 59 | "country": 'United States', |
| 60 | "language": "english" |
| 61 | }) |
| 62 | |
| 63 | def setup_demo_page(): |
| 64 | # home page should always be "start" |
| 65 | website_settings = frappe.get_doc("Website Settings", "Website Settings") |
| 66 | website_settings.home_page = "demo" |
| 67 | website_settings.save() |
| 68 | |
| 69 | def setup_fiscal_year(): |
| 70 | fiscal_year = None |
Nabin Hait | 1606626 | 2016-07-21 11:00:28 +0530 | [diff] [blame] | 71 | for year in xrange(2010, now_datetime().year + 1, 1): |
Rushabh Mehta | dc8067e | 2016-06-29 18:38:32 +0530 | [diff] [blame] | 72 | try: |
| 73 | fiscal_year = frappe.get_doc({ |
| 74 | "doctype": "Fiscal Year", |
Saurabh | f589c82 | 2016-07-15 18:28:05 +0530 | [diff] [blame] | 75 | "year": cstr(year), |
Rushabh Mehta | dc8067e | 2016-06-29 18:38:32 +0530 | [diff] [blame] | 76 | "year_start_date": "{0}-01-01".format(year), |
| 77 | "year_end_date": "{0}-12-31".format(year) |
| 78 | }).insert() |
| 79 | except frappe.DuplicateEntryError: |
| 80 | pass |
| 81 | |
| 82 | # set the last fiscal year (current year) as default |
| 83 | fiscal_year.set_as_default() |
| 84 | |
| 85 | def setup_holiday_list(): |
| 86 | """Setup Holiday List for the current year""" |
Saurabh | f589c82 | 2016-07-15 18:28:05 +0530 | [diff] [blame] | 87 | year = now_datetime().year |
Rushabh Mehta | dc8067e | 2016-06-29 18:38:32 +0530 | [diff] [blame] | 88 | holiday_list = frappe.get_doc({ |
| 89 | "doctype": "Holiday List", |
| 90 | "holiday_list_name": str(year), |
| 91 | "from_date": "{0}-01-01".format(year), |
| 92 | "to_date": "{0}-12-31".format(year), |
| 93 | }) |
| 94 | holiday_list.insert() |
| 95 | holiday_list.weekly_off = "Saturday" |
| 96 | holiday_list.get_weekly_off_dates() |
| 97 | holiday_list.weekly_off = "Sunday" |
| 98 | holiday_list.get_weekly_off_dates() |
| 99 | holiday_list.save() |
| 100 | |
| 101 | frappe.set_value("Company", erpnext.get_default_company(), "default_holiday_list", holiday_list.name) |
| 102 | |
| 103 | def setup_customer(): |
| 104 | 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'] |
| 105 | for c in customers: |
| 106 | frappe.get_doc({ |
| 107 | "doctype": "Customer", |
| 108 | "customer_name": c, |
| 109 | "customer_group": "Commercial", |
| 110 | "customer_type": random.choice(["Company", "Individual"]), |
| 111 | "territory": "Rest Of The World" |
| 112 | }).insert() |
| 113 | |
| 114 | def setup_supplier(): |
| 115 | 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'] |
| 116 | for s in suppliers: |
| 117 | frappe.get_doc({ |
| 118 | "doctype": "Supplier", |
| 119 | "supplier_name": s, |
| 120 | "supplier_type": random.choice(["Services", "Raw Material"]), |
| 121 | }).insert() |
| 122 | |
| 123 | def setup_workstation(): |
| 124 | workstations = [u'Drilling Machine 1', u'Lathe 1', u'Assembly Station 1', u'Assembly Station 2', u'Packing and Testing Station'] |
| 125 | for w in workstations: |
| 126 | frappe.get_doc({ |
| 127 | "doctype": "Workstation", |
| 128 | "workstation_name": w, |
| 129 | "holiday_list": frappe.get_all("Holiday List")[0].name, |
| 130 | "hour_rate_consumable": int(random.random() * 20), |
| 131 | "hour_rate_electricity": int(random.random() * 10), |
| 132 | "hour_rate_labour": int(random.random() * 40), |
| 133 | "hour_rate_rent": int(random.random() * 10), |
| 134 | "working_hours": [ |
| 135 | { |
| 136 | "enabled": 1, |
| 137 | "start_time": "8:00:00", |
| 138 | "end_time": "15:00:00" |
| 139 | } |
| 140 | ] |
| 141 | }).insert() |
| 142 | |
| 143 | def show_item_groups_in_website(): |
| 144 | """set show_in_website=1 for Item Groups""" |
| 145 | products = frappe.get_doc("Item Group", "Products") |
| 146 | products.show_in_website = 1 |
| 147 | products.route = 'products' |
| 148 | products.save() |
| 149 | |
| 150 | def setup_item(): |
| 151 | items = json.loads(open(frappe.get_app_path('erpnext', 'demo', 'data', 'item.json')).read()) |
| 152 | for i in items: |
| 153 | item = frappe.new_doc('Item') |
| 154 | item.update(i) |
Rushabh Mehta | 3ce24d6 | 2016-07-11 16:07:06 +0530 | [diff] [blame] | 155 | item.min_order_qty = random.randint(10, 30) |
Rushabh Mehta | dc8067e | 2016-06-29 18:38:32 +0530 | [diff] [blame] | 156 | item.default_warehouse = frappe.get_all('Warehouse', filters={'warehouse_name': item.default_warehouse}, limit=1)[0].name |
| 157 | item.insert() |
| 158 | |
Rushabh Mehta | cca33b2 | 2016-07-08 18:24:46 +0530 | [diff] [blame] | 159 | def setup_warehouse(): |
| 160 | w = frappe.new_doc('Warehouse') |
| 161 | w.warehouse_name = 'Supplier' |
| 162 | w.insert() |
Nabin Hait | 3edefb1 | 2016-07-20 16:13:18 +0530 | [diff] [blame] | 163 | |
| 164 | def setup_asset(): |
| 165 | assets = json.loads(open(frappe.get_app_path('erpnext', 'demo', 'data', 'asset.json')).read()) |
| 166 | for d in assets: |
| 167 | asset = frappe.new_doc('Asset') |
| 168 | asset.update(d) |
| 169 | asset.purchase_date = add_days(nowdate(), -random.randint(20, 1500)) |
| 170 | asset.next_depreciation_date = add_days(asset.purchase_date, 30) |
| 171 | asset.warehouse = "Stores - WPL" |
| 172 | asset.set_missing_values() |
| 173 | asset.make_depreciation_schedule() |
| 174 | asset.flags.ignore_validate = True |
| 175 | asset.save() |
| 176 | asset.submit() |
Rushabh Mehta | cca33b2 | 2016-07-08 18:24:46 +0530 | [diff] [blame] | 177 | |
Rushabh Mehta | dc8067e | 2016-06-29 18:38:32 +0530 | [diff] [blame] | 178 | def setup_currency_exchange(): |
| 179 | frappe.get_doc({ |
| 180 | 'doctype': 'Currency Exchange', |
| 181 | 'from_currency': 'EUR', |
| 182 | 'to_currency': 'USD', |
| 183 | 'exchange_rate': 1.13 |
| 184 | }).insert() |
| 185 | |
| 186 | frappe.get_doc({ |
| 187 | 'doctype': 'Currency Exchange', |
| 188 | 'from_currency': 'CNY', |
| 189 | 'to_currency': 'USD', |
| 190 | 'exchange_rate': 0.16 |
| 191 | }).insert() |
| 192 | |
| 193 | def setup_product_bundle(): |
| 194 | frappe.get_doc({ |
| 195 | 'doctype': 'Product Bundle', |
| 196 | 'new_item_code': 'Wind Mill A Series with Spare Bearing', |
| 197 | 'items': [ |
| 198 | {'item_code': 'Wind Mill A Series', 'qty': 1}, |
| 199 | {'item_code': 'Bearing Collar', 'qty': 1}, |
| 200 | {'item_code': 'Bearing Assembly', 'qty': 1}, |
| 201 | ] |
| 202 | }).insert() |
| 203 | |
| 204 | def setup_user(): |
| 205 | frappe.db.sql('delete from tabUser where name not in ("Guest", "Administrator")') |
| 206 | for u in json.loads(open(frappe.get_app_path('erpnext', 'demo', 'data', 'user.json')).read()): |
| 207 | user = frappe.new_doc("User") |
| 208 | user.update(u) |
| 209 | user.flags.no_welcome_mail |
| 210 | user.password = 'demo' |
| 211 | user.insert() |
| 212 | |
Rushabh Mehta | cca33b2 | 2016-07-08 18:24:46 +0530 | [diff] [blame] | 213 | def import_json(doctype, submit=False, values=None): |
Rushabh Mehta | dc8067e | 2016-06-29 18:38:32 +0530 | [diff] [blame] | 214 | frappe.flags.in_import = True |
| 215 | data = json.loads(open(frappe.get_app_path('erpnext', 'demo', 'data', |
| 216 | frappe.scrub(doctype) + '.json')).read()) |
| 217 | for d in data: |
| 218 | doc = frappe.new_doc(doctype) |
| 219 | doc.update(d) |
| 220 | doc.insert() |
| 221 | if submit: |
| 222 | doc.submit() |
| 223 | |
Rushabh Mehta | 391c0ef | 2016-07-11 13:01:44 +0530 | [diff] [blame] | 224 | frappe.db.commit() |
| 225 | |
Rushabh Mehta | dc8067e | 2016-06-29 18:38:32 +0530 | [diff] [blame] | 226 | def setup_employee(): |
| 227 | frappe.db.set_value("HR Settings", None, "emp_created_by", "Naming Series") |
| 228 | frappe.db.commit() |
| 229 | |
| 230 | import_json('Employee') |
| 231 | |
| 232 | def setup_item_price(): |
| 233 | frappe.db.sql("delete from `tabItem Price`") |
| 234 | |
| 235 | standard_selling = { |
| 236 | "Base Bearing Plate": 28, |
| 237 | "Base Plate": 21, |
| 238 | "Bearing Assembly": 300, |
| 239 | "Bearing Block": 14, |
| 240 | "Bearing Collar": 103.6, |
| 241 | "Bearing Pipe": 63, |
| 242 | "Blade Rib": 46.2, |
| 243 | "Disc Collars": 42, |
| 244 | "External Disc": 56, |
| 245 | "Internal Disc": 70, |
| 246 | "Shaft": 340, |
| 247 | "Stand": 400, |
| 248 | "Upper Bearing Plate": 300, |
| 249 | "Wind Mill A Series": 320, |
| 250 | "Wind Mill A Series with Spare Bearing": 750, |
| 251 | "Wind MIll C Series": 400, |
| 252 | "Wind Turbine": 400, |
| 253 | "Wing Sheet": 30.8 |
| 254 | } |
| 255 | |
| 256 | standard_buying = { |
| 257 | "Base Bearing Plate": 20, |
| 258 | "Base Plate": 28, |
| 259 | "Base Plate Un Painted": 16, |
| 260 | "Bearing Block": 13, |
| 261 | "Bearing Collar": 96.4, |
| 262 | "Bearing Pipe": 55, |
| 263 | "Blade Rib": 38, |
| 264 | "Disc Collars": 34, |
| 265 | "External Disc": 50, |
| 266 | "Internal Disc": 60, |
| 267 | "Shaft": 250, |
| 268 | "Stand": 300, |
| 269 | "Upper Bearing Plate": 200, |
| 270 | "Wing Sheet": 25 |
| 271 | } |
| 272 | |
| 273 | for price_list in ("standard_buying", "standard_selling"): |
| 274 | for item, rate in locals().get(price_list).iteritems(): |
| 275 | frappe.get_doc({ |
| 276 | "doctype": "Item Price", |
| 277 | "price_list": price_list.replace("_", " ").title(), |
| 278 | "item_code": item, |
| 279 | "selling": 1 if price_list=="standard_selling" else 0, |
| 280 | "buying": 1 if price_list=="standard_buying" else 0, |
| 281 | "price_list_rate": rate, |
| 282 | "currency": "USD" |
| 283 | }).insert() |
| 284 | |
| 285 | def setup_salary_structure(): |
| 286 | f = frappe.get_doc('Fiscal Year', frappe.defaults.get_global_default('fiscal_year')) |
| 287 | |
| 288 | for e in frappe.get_all('Employee', fields=['name', 'date_of_joining']): |
| 289 | ss = frappe.new_doc('Salary Structure') |
| 290 | ss.employee = e.name |
| 291 | |
| 292 | if not e.date_of_joining: |
| 293 | continue |
| 294 | |
| 295 | ss.from_date = e.date_of_joining if (e.date_of_joining |
| 296 | and e.date_of_joining > f.year_start_date) else f.year_start_date |
| 297 | ss.to_date = f.year_end_date |
| 298 | ss.append('earnings', { |
Rushabh Mehta | cca33b2 | 2016-07-08 18:24:46 +0530 | [diff] [blame] | 299 | 'salary_component': 'Basic', |
| 300 | 'amount': random.random() * 10000 |
Rushabh Mehta | dc8067e | 2016-06-29 18:38:32 +0530 | [diff] [blame] | 301 | }) |
| 302 | ss.append('deductions', { |
Rushabh Mehta | cca33b2 | 2016-07-08 18:24:46 +0530 | [diff] [blame] | 303 | 'salary_component': 'Income Tax', |
| 304 | 'amount': random.random() * 1000 |
Rushabh Mehta | dc8067e | 2016-06-29 18:38:32 +0530 | [diff] [blame] | 305 | }) |
Rushabh Mehta | cca33b2 | 2016-07-08 18:24:46 +0530 | [diff] [blame] | 306 | |
Rushabh Mehta | dc8067e | 2016-06-29 18:38:32 +0530 | [diff] [blame] | 307 | ss.insert() |
Rohit Waghchaure | 8002d47 | 2016-07-13 16:03:05 +0530 | [diff] [blame] | 308 | |
| 309 | def setup_salary_structure_for_timesheet(): |
| 310 | for e in frappe.get_all('Salary Structure', fields=['name'], filters={'is_active': 'Yes'}, limit=2): |
| 311 | ss_doc = frappe.get_doc("Salary Structure", e.name) |
| 312 | ss_doc.salary_slip_based_on_timesheet = 1 |
| 313 | ss_doc.salary_component = 'Basic' |
| 314 | ss_doc.hour_rate = flt(random.random() * 10, 2) |
| 315 | ss_doc.save(ignore_permissions=True) |
Rushabh Mehta | dc8067e | 2016-06-29 18:38:32 +0530 | [diff] [blame] | 316 | |
| 317 | def setup_account(): |
| 318 | frappe.flags.in_import = True |
| 319 | data = json.loads(open(frappe.get_app_path('erpnext', 'demo', 'data', |
| 320 | 'account.json')).read()) |
| 321 | for d in data: |
| 322 | doc = frappe.new_doc('Account') |
| 323 | doc.update(d) |
| 324 | doc.parent_account = frappe.db.get_value('Account', {'account_name': doc.parent_account}) |
| 325 | doc.insert() |
| 326 | |
Saurabh | f589c82 | 2016-07-15 18:28:05 +0530 | [diff] [blame] | 327 | def setup_account_to_expense_type(): |
| 328 | expense_types = [{'name': _('Calls'), "account": "Sales Expenses - WPL"}, |
| 329 | {'name': _('Food'), "account": "Entertainment Expenses - WPL"}, |
| 330 | {'name': _('Medical'), "account": "Utility Expenses - WPL"}, |
| 331 | {'name': _('Others'), "account": "Miscellaneous Expenses - WPL"}, |
| 332 | {'name': _('Travel'), "account": "Travel Expenses - WPL"}] |
| 333 | |
| 334 | for expense_type in expense_types: |
| 335 | doc = frappe.get_doc("Expense Claim Type", expense_type["name"]) |
Saurabh | 718d835 | 2016-07-18 15:20:47 +0530 | [diff] [blame] | 336 | doc.append("accounts", { |
| 337 | "company" : erpnext.get_default_company(), |
| 338 | "default_account" : expense_type["account"] |
| 339 | }) |
Saurabh | f589c82 | 2016-07-15 18:28:05 +0530 | [diff] [blame] | 340 | doc.save(ignore_permissions=True) |
| 341 | |
Rushabh Mehta | dc8067e | 2016-06-29 18:38:32 +0530 | [diff] [blame] | 342 | def setup_user_roles(): |
| 343 | if not frappe.db.get_global('demo_hr_user'): |
| 344 | user = frappe.get_doc('User', 'CharmaineGaudreau@example.com') |
| 345 | user.add_roles('HR User', 'HR Manager', 'Accounts User') |
| 346 | frappe.db.set_global('demo_hr_user', user.name) |
| 347 | |
| 348 | if not frappe.db.get_global('demo_sales_user_1'): |
| 349 | user = frappe.get_doc('User', 'VakhitaRyzaev@example.com') |
| 350 | user.add_roles('Sales User') |
| 351 | frappe.db.set_global('demo_sales_user_1', user.name) |
| 352 | |
| 353 | if not frappe.db.get_global('demo_sales_user_2'): |
| 354 | user = frappe.get_doc('User', 'GabrielleLoftus@example.com') |
| 355 | user.add_roles('Sales User', 'Sales Manager', 'Accounts User') |
| 356 | frappe.db.set_global('demo_sales_user_2', user.name) |
Rushabh Mehta | ea0ff23 | 2016-07-07 14:02:26 +0530 | [diff] [blame] | 357 | |
| 358 | if not frappe.db.get_global('demo_purchase_user'): |
| 359 | user = frappe.get_doc('User', 'MichalSobczak@example.com') |
Rushabh Mehta | cca33b2 | 2016-07-08 18:24:46 +0530 | [diff] [blame] | 360 | user.add_roles('Purchase User', 'Purchase Manager', 'Accounts User', 'Stock User') |
Rushabh Mehta | ea0ff23 | 2016-07-07 14:02:26 +0530 | [diff] [blame] | 361 | frappe.db.set_global('demo_purchase_user', user.name) |
Rushabh Mehta | cca33b2 | 2016-07-08 18:24:46 +0530 | [diff] [blame] | 362 | |
| 363 | if not frappe.db.get_global('demo_manufacturing_user'): |
| 364 | user = frappe.get_doc('User', 'NuranVerkleij@example.com') |
| 365 | user.add_roles('Manufacturing User', 'Stock User', 'Purchase User', 'Accounts User') |
| 366 | frappe.db.set_global('demo_manufacturing_user', user.name) |
| 367 | |
| 368 | if not frappe.db.get_global('demo_stock_user'): |
| 369 | user = frappe.get_doc('User', 'HatsueKashiwagi@example.com') |
| 370 | user.add_roles('Manufacturing User', 'Stock User', 'Purchase User', 'Accounts User') |
| 371 | frappe.db.set_global('demo_stock_user', user.name) |
| 372 | |
Rushabh Mehta | 8cfe18e | 2016-07-13 11:29:59 +0530 | [diff] [blame] | 373 | if not frappe.db.get_global('demo_accounts_user'): |
| 374 | user = frappe.get_doc('User', 'LeonAbdulov@example.com') |
Rushabh Mehta | 92d1b8c | 2016-07-14 15:46:12 +0530 | [diff] [blame] | 375 | user.add_roles('Accounts User', 'Accounts Manager', 'Sales User', 'Purchase User') |
Rushabh Mehta | 8cfe18e | 2016-07-13 11:29:59 +0530 | [diff] [blame] | 376 | frappe.db.set_global('demo_accounts_user', user.name) |
Rohit Waghchaure | 8002d47 | 2016-07-13 16:03:05 +0530 | [diff] [blame] | 377 | |
| 378 | if not frappe.db.get_global('demo_projects_user'): |
| 379 | user = frappe.get_doc('User', 'panca@example.com') |
| 380 | user.add_roles('HR User', 'Projects User') |
| 381 | frappe.db.set_global('demo_projects_user', user.name) |
Rushabh Mehta | 8cfe18e | 2016-07-13 11:29:59 +0530 | [diff] [blame] | 382 | |