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