Rushabh Mehta | dc8067e | 2016-06-29 18:38:32 +0530 | [diff] [blame] | 1 | from __future__ import unicode_literals |
| 2 | |
| 3 | import random, json |
Neil Trini Lasrado | 0672459 | 2016-08-22 12:57:09 +0530 | [diff] [blame] | 4 | import frappe, erpnext |
Rushabh Mehta | e9d9b8e | 2016-12-15 11:27:35 +0530 | [diff] [blame] | 5 | from frappe.utils import flt, now_datetime, cstr, random_string |
Nabin Hait | 74edfff | 2016-07-21 11:39:46 +0530 | [diff] [blame] | 6 | from frappe.utils.make_random import add_random_children, get_random |
Rushabh Mehta | dc8067e | 2016-06-29 18:38:32 +0530 | [diff] [blame] | 7 | from erpnext.demo.domains import data |
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 | |
Neil Trini Lasrado | 0672459 | 2016-08-22 12:57:09 +0530 | [diff] [blame] | 10 | def setup(domain): |
Rushabh Mehta | dc8067e | 2016-06-29 18:38:32 +0530 | [diff] [blame] | 11 | complete_setup(domain) |
| 12 | setup_demo_page() |
| 13 | setup_fiscal_year() |
| 14 | setup_holiday_list() |
Rushabh Mehta | dc8067e | 2016-06-29 18:38:32 +0530 | [diff] [blame] | 15 | setup_user() |
| 16 | setup_employee() |
Saurabh | b3134d3 | 2017-03-02 08:41:44 +0530 | [diff] [blame] | 17 | setup_user_roles() |
Rushabh Mehta | e9d9b8e | 2016-12-15 11:27:35 +0530 | [diff] [blame] | 18 | |
| 19 | employees = frappe.get_all('Employee', fields=['name', 'date_of_joining']) |
| 20 | |
| 21 | # monthly salary |
| 22 | setup_salary_structure(employees[:5], 0) |
| 23 | |
| 24 | # based on timesheet |
| 25 | setup_salary_structure(employees[5:], 1) |
| 26 | |
Kanchan Chauhan | db0e57c | 2016-07-29 15:59:39 +0530 | [diff] [blame] | 27 | setup_leave_allocation() |
Neil Trini Lasrado | 0672459 | 2016-08-22 12:57:09 +0530 | [diff] [blame] | 28 | setup_customer() |
| 29 | setup_supplier() |
| 30 | setup_warehouse() |
| 31 | import_json('Address') |
| 32 | import_json('Contact') |
| 33 | import_json('Lead') |
| 34 | setup_currency_exchange() |
Rushabh Mehta | 95439db | 2017-01-14 00:25:22 +0530 | [diff] [blame] | 35 | #setup_mode_of_payment() |
Saurabh | f589c82 | 2016-07-15 18:28:05 +0530 | [diff] [blame] | 36 | setup_account_to_expense_type() |
Nabin Hait | 74edfff | 2016-07-21 11:39:46 +0530 | [diff] [blame] | 37 | setup_budget() |
Rohit Waghchaure | 7d439ec | 2016-07-21 14:50:59 +0530 | [diff] [blame] | 38 | setup_pos_profile() |
Rushabh Mehta | e9d9b8e | 2016-12-15 11:27:35 +0530 | [diff] [blame] | 39 | |
Rushabh Mehta | 391c0ef | 2016-07-11 13:01:44 +0530 | [diff] [blame] | 40 | frappe.db.commit() |
| 41 | frappe.clear_cache() |
Rushabh Mehta | dc8067e | 2016-06-29 18:38:32 +0530 | [diff] [blame] | 42 | |
| 43 | def 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({ |
Rushabh Mehta | cf99dc0 | 2017-02-09 18:06:11 +0530 | [diff] [blame] | 49 | "full_name": "Test User", |
Saurabh | 9ca3f28 | 2017-02-02 19:22:16 +0530 | [diff] [blame] | 50 | "email": "test_demo@erpnext.com", |
Rushabh Mehta | dc8067e | 2016-06-29 18:38:32 +0530 | [diff] [blame] | 51 | "company_tagline": 'Awesome Products and Services', |
Neil Trini Lasrado | 29cae17 | 2016-10-28 16:39:45 +0530 | [diff] [blame] | 52 | "password": "demo", |
Rushabh Mehta | dc8067e | 2016-06-29 18:38:32 +0530 | [diff] [blame] | 53 | "fy_start_date": "2015-01-01", |
| 54 | "fy_end_date": "2015-12-31", |
| 55 | "bank_account": "National Bank", |
Rushabh Mehta | 04a64a7 | 2016-07-22 12:19:18 +0530 | [diff] [blame] | 56 | "domain": domain, |
Rushabh Mehta | dc8067e | 2016-06-29 18:38:32 +0530 | [diff] [blame] | 57 | "company_name": data.get(domain).get('company_name'), |
| 58 | "chart_of_accounts": "Standard", |
| 59 | "company_abbr": ''.join([d[0] for d in data.get(domain).get('company_name').split()]).upper(), |
| 60 | "currency": 'USD', |
| 61 | "timezone": 'America/New_York', |
| 62 | "country": 'United States', |
| 63 | "language": "english" |
| 64 | }) |
| 65 | |
| 66 | def setup_demo_page(): |
| 67 | # home page should always be "start" |
| 68 | website_settings = frappe.get_doc("Website Settings", "Website Settings") |
| 69 | website_settings.home_page = "demo" |
| 70 | website_settings.save() |
| 71 | |
| 72 | def setup_fiscal_year(): |
| 73 | fiscal_year = None |
Nabin Hait | 1606626 | 2016-07-21 11:00:28 +0530 | [diff] [blame] | 74 | for year in xrange(2010, now_datetime().year + 1, 1): |
Rushabh Mehta | dc8067e | 2016-06-29 18:38:32 +0530 | [diff] [blame] | 75 | try: |
| 76 | fiscal_year = frappe.get_doc({ |
| 77 | "doctype": "Fiscal Year", |
Saurabh | f589c82 | 2016-07-15 18:28:05 +0530 | [diff] [blame] | 78 | "year": cstr(year), |
Rushabh Mehta | dc8067e | 2016-06-29 18:38:32 +0530 | [diff] [blame] | 79 | "year_start_date": "{0}-01-01".format(year), |
| 80 | "year_end_date": "{0}-12-31".format(year) |
| 81 | }).insert() |
| 82 | except frappe.DuplicateEntryError: |
| 83 | pass |
| 84 | |
| 85 | # set the last fiscal year (current year) as default |
| 86 | fiscal_year.set_as_default() |
| 87 | |
| 88 | def setup_holiday_list(): |
| 89 | """Setup Holiday List for the current year""" |
Saurabh | f589c82 | 2016-07-15 18:28:05 +0530 | [diff] [blame] | 90 | year = now_datetime().year |
Rushabh Mehta | dc8067e | 2016-06-29 18:38:32 +0530 | [diff] [blame] | 91 | holiday_list = frappe.get_doc({ |
| 92 | "doctype": "Holiday List", |
| 93 | "holiday_list_name": str(year), |
| 94 | "from_date": "{0}-01-01".format(year), |
| 95 | "to_date": "{0}-12-31".format(year), |
| 96 | }) |
| 97 | holiday_list.insert() |
| 98 | holiday_list.weekly_off = "Saturday" |
| 99 | holiday_list.get_weekly_off_dates() |
| 100 | holiday_list.weekly_off = "Sunday" |
| 101 | holiday_list.get_weekly_off_dates() |
| 102 | holiday_list.save() |
| 103 | |
| 104 | frappe.set_value("Company", erpnext.get_default_company(), "default_holiday_list", holiday_list.name) |
| 105 | |
Rushabh Mehta | dc8067e | 2016-06-29 18:38:32 +0530 | [diff] [blame] | 106 | |
| 107 | def setup_user(): |
| 108 | frappe.db.sql('delete from tabUser where name not in ("Guest", "Administrator")') |
| 109 | for u in json.loads(open(frappe.get_app_path('erpnext', 'demo', 'data', 'user.json')).read()): |
| 110 | user = frappe.new_doc("User") |
| 111 | user.update(u) |
| 112 | user.flags.no_welcome_mail |
Rushabh Mehta | efe1ab7 | 2016-08-04 17:29:35 +0530 | [diff] [blame] | 113 | user.new_password = 'demo' |
Rushabh Mehta | dc8067e | 2016-06-29 18:38:32 +0530 | [diff] [blame] | 114 | user.insert() |
| 115 | |
Rushabh Mehta | dc8067e | 2016-06-29 18:38:32 +0530 | [diff] [blame] | 116 | def setup_employee(): |
| 117 | frappe.db.set_value("HR Settings", None, "emp_created_by", "Naming Series") |
| 118 | frappe.db.commit() |
| 119 | |
Rushabh Mehta | e9d9b8e | 2016-12-15 11:27:35 +0530 | [diff] [blame] | 120 | for d in frappe.get_all('Salary Component'): |
| 121 | salary_component = frappe.get_doc('Salary Component', d.name) |
| 122 | salary_component.append('accounts', dict( |
| 123 | company=erpnext.get_default_company(), |
| 124 | default_account=frappe.get_value('Account', dict(account_name=('like', 'Salary%'))) |
| 125 | )) |
| 126 | salary_component.save() |
| 127 | |
Rushabh Mehta | dc8067e | 2016-06-29 18:38:32 +0530 | [diff] [blame] | 128 | import_json('Employee') |
| 129 | |
Rushabh Mehta | e9d9b8e | 2016-12-15 11:27:35 +0530 | [diff] [blame] | 130 | def setup_salary_structure(employees, salary_slip_based_on_timesheet=0): |
Rushabh Mehta | dc8067e | 2016-06-29 18:38:32 +0530 | [diff] [blame] | 131 | f = frappe.get_doc('Fiscal Year', frappe.defaults.get_global_default('fiscal_year')) |
| 132 | |
Kanchan Chauhan | db197d5 | 2016-08-20 00:30:59 +0530 | [diff] [blame] | 133 | ss = frappe.new_doc('Salary Structure') |
Rushabh Mehta | e9d9b8e | 2016-12-15 11:27:35 +0530 | [diff] [blame] | 134 | ss.name = "Sample Salary Structure - " + random_string(5) |
| 135 | for e in employees: |
Kanchan Chauhan | db197d5 | 2016-08-20 00:30:59 +0530 | [diff] [blame] | 136 | ss.append('employees', { |
| 137 | 'employee': e.name, |
Saurabh | b3134d3 | 2017-03-02 08:41:44 +0530 | [diff] [blame] | 138 | 'from_date': "2015-01-01", |
Kanchan Chauhan | db197d5 | 2016-08-20 00:30:59 +0530 | [diff] [blame] | 139 | 'base': random.random() * 10000 |
| 140 | }) |
Rushabh Mehta | dc8067e | 2016-06-29 18:38:32 +0530 | [diff] [blame] | 141 | |
Rushabh Mehta | e9d9b8e | 2016-12-15 11:27:35 +0530 | [diff] [blame] | 142 | ss.from_date = e.date_of_joining if (e.date_of_joining |
| 143 | and e.date_of_joining > f.year_start_date) else f.year_start_date |
| 144 | ss.to_date = f.year_end_date |
| 145 | ss.salary_slip_based_on_timesheet = salary_slip_based_on_timesheet |
Rushabh Mehta | dc8067e | 2016-06-29 18:38:32 +0530 | [diff] [blame] | 146 | |
Rushabh Mehta | e9d9b8e | 2016-12-15 11:27:35 +0530 | [diff] [blame] | 147 | if salary_slip_based_on_timesheet: |
| 148 | ss.salary_component = 'Basic' |
| 149 | ss.hour_rate = flt(random.random() * 10, 2) |
| 150 | else: |
| 151 | ss.payroll_frequency = 'Monthly' |
| 152 | |
| 153 | ss.payment_account = frappe.get_value('Account', |
| 154 | {'account_type': 'Cash', 'company': erpnext.get_default_company(),'is_group':0}, "name") |
| 155 | |
Kanchan Chauhan | db197d5 | 2016-08-20 00:30:59 +0530 | [diff] [blame] | 156 | ss.append('earnings', { |
| 157 | 'salary_component': 'Basic', |
| 158 | "abbr":'B', |
Kanchan Chauhan | db197d5 | 2016-08-20 00:30:59 +0530 | [diff] [blame] | 159 | 'formula': 'base*.2', |
| 160 | 'amount_based_on_formula': 1, |
| 161 | "idx": 1 |
| 162 | }) |
| 163 | ss.append('deductions', { |
| 164 | 'salary_component': 'Income Tax', |
| 165 | "abbr":'IT', |
KanchanChauhan | b89be1e | 2017-01-16 12:57:14 +0530 | [diff] [blame] | 166 | 'condition': 'base > 10000', |
| 167 | 'formula': 'base*.1', |
Kanchan Chauhan | db197d5 | 2016-08-20 00:30:59 +0530 | [diff] [blame] | 168 | "idx": 1 |
| 169 | }) |
Kanchan Chauhan | db197d5 | 2016-08-20 00:30:59 +0530 | [diff] [blame] | 170 | ss.insert() |
Rushabh Mehta | 04a64a7 | 2016-07-22 12:19:18 +0530 | [diff] [blame] | 171 | |
Rushabh Mehta | e9d9b8e | 2016-12-15 11:27:35 +0530 | [diff] [blame] | 172 | return ss |
Rushabh Mehta | dc8067e | 2016-06-29 18:38:32 +0530 | [diff] [blame] | 173 | |
Rushabh Mehta | dc8067e | 2016-06-29 18:38:32 +0530 | [diff] [blame] | 174 | def setup_user_roles(): |
Rushabh Mehta | efe1ab7 | 2016-08-04 17:29:35 +0530 | [diff] [blame] | 175 | user = frappe.get_doc('User', 'demo@erpnext.com') |
| 176 | user.add_roles('HR User', 'HR Manager', 'Accounts User', 'Accounts Manager', |
| 177 | 'Stock User', 'Stock Manager', 'Sales User', 'Sales Manager', 'Purchase User', |
| 178 | 'Purchase Manager', 'Projects User', 'Manufacturing User', 'Manufacturing Manager', |
Neil Trini Lasrado | 0672459 | 2016-08-22 12:57:09 +0530 | [diff] [blame] | 179 | 'Support Team', 'Academics User') |
Rushabh Mehta | efe1ab7 | 2016-08-04 17:29:35 +0530 | [diff] [blame] | 180 | |
Rushabh Mehta | dc8067e | 2016-06-29 18:38:32 +0530 | [diff] [blame] | 181 | if not frappe.db.get_global('demo_hr_user'): |
| 182 | user = frappe.get_doc('User', 'CharmaineGaudreau@example.com') |
| 183 | user.add_roles('HR User', 'HR Manager', 'Accounts User') |
| 184 | frappe.db.set_global('demo_hr_user', user.name) |
| 185 | |
| 186 | if not frappe.db.get_global('demo_sales_user_1'): |
| 187 | user = frappe.get_doc('User', 'VakhitaRyzaev@example.com') |
| 188 | user.add_roles('Sales User') |
| 189 | frappe.db.set_global('demo_sales_user_1', user.name) |
| 190 | |
| 191 | if not frappe.db.get_global('demo_sales_user_2'): |
| 192 | user = frappe.get_doc('User', 'GabrielleLoftus@example.com') |
| 193 | user.add_roles('Sales User', 'Sales Manager', 'Accounts User') |
| 194 | frappe.db.set_global('demo_sales_user_2', user.name) |
Rushabh Mehta | ea0ff23 | 2016-07-07 14:02:26 +0530 | [diff] [blame] | 195 | |
| 196 | if not frappe.db.get_global('demo_purchase_user'): |
| 197 | user = frappe.get_doc('User', 'MichalSobczak@example.com') |
Rushabh Mehta | cca33b2 | 2016-07-08 18:24:46 +0530 | [diff] [blame] | 198 | user.add_roles('Purchase User', 'Purchase Manager', 'Accounts User', 'Stock User') |
Rushabh Mehta | ea0ff23 | 2016-07-07 14:02:26 +0530 | [diff] [blame] | 199 | frappe.db.set_global('demo_purchase_user', user.name) |
Rushabh Mehta | cca33b2 | 2016-07-08 18:24:46 +0530 | [diff] [blame] | 200 | |
| 201 | if not frappe.db.get_global('demo_manufacturing_user'): |
| 202 | user = frappe.get_doc('User', 'NuranVerkleij@example.com') |
| 203 | user.add_roles('Manufacturing User', 'Stock User', 'Purchase User', 'Accounts User') |
| 204 | frappe.db.set_global('demo_manufacturing_user', user.name) |
| 205 | |
| 206 | if not frappe.db.get_global('demo_stock_user'): |
| 207 | user = frappe.get_doc('User', 'HatsueKashiwagi@example.com') |
| 208 | user.add_roles('Manufacturing User', 'Stock User', 'Purchase User', 'Accounts User') |
| 209 | frappe.db.set_global('demo_stock_user', user.name) |
| 210 | |
Rushabh Mehta | 8cfe18e | 2016-07-13 11:29:59 +0530 | [diff] [blame] | 211 | if not frappe.db.get_global('demo_accounts_user'): |
| 212 | user = frappe.get_doc('User', 'LeonAbdulov@example.com') |
Rushabh Mehta | 92d1b8c | 2016-07-14 15:46:12 +0530 | [diff] [blame] | 213 | user.add_roles('Accounts User', 'Accounts Manager', 'Sales User', 'Purchase User') |
Rushabh Mehta | 8cfe18e | 2016-07-13 11:29:59 +0530 | [diff] [blame] | 214 | frappe.db.set_global('demo_accounts_user', user.name) |
Rushabh Mehta | 04a64a7 | 2016-07-22 12:19:18 +0530 | [diff] [blame] | 215 | |
Rohit Waghchaure | 8002d47 | 2016-07-13 16:03:05 +0530 | [diff] [blame] | 216 | if not frappe.db.get_global('demo_projects_user'): |
| 217 | user = frappe.get_doc('User', 'panca@example.com') |
| 218 | user.add_roles('HR User', 'Projects User') |
| 219 | frappe.db.set_global('demo_projects_user', user.name) |
Rushabh Mehta | 8cfe18e | 2016-07-13 11:29:59 +0530 | [diff] [blame] | 220 | |
Neil Trini Lasrado | 0672459 | 2016-08-22 12:57:09 +0530 | [diff] [blame] | 221 | if not frappe.db.get_global('demo_schools_user'): |
| 222 | user = frappe.get_doc('User', 'aromn@example.com') |
| 223 | user.add_roles('Academics User') |
| 224 | frappe.db.set_global('demo_schools_user', user.name) |
Rushabh Mehta | e9d9b8e | 2016-12-15 11:27:35 +0530 | [diff] [blame] | 225 | |
Neil Trini Lasrado | 0672459 | 2016-08-22 12:57:09 +0530 | [diff] [blame] | 226 | #Add Expense Approver |
| 227 | user = frappe.get_doc('User', 'WanMai@example.com') |
| 228 | user.add_roles('Expense Approver') |
Rushabh Mehta | e9d9b8e | 2016-12-15 11:27:35 +0530 | [diff] [blame] | 229 | |
Kanchan Chauhan | db0e57c | 2016-07-29 15:59:39 +0530 | [diff] [blame] | 230 | def setup_leave_allocation(): |
| 231 | year = now_datetime().year |
| 232 | for employee in frappe.get_all('Employee', fields=['name']): |
| 233 | leave_types = frappe.get_all("Leave Type", fields=['name', 'max_days_allowed']) |
| 234 | for leave_type in leave_types: |
| 235 | if not leave_type.max_days_allowed: |
| 236 | leave_type.max_days_allowed = 10 |
Rushabh Mehta | efe1ab7 | 2016-08-04 17:29:35 +0530 | [diff] [blame] | 237 | |
Kanchan Chauhan | db0e57c | 2016-07-29 15:59:39 +0530 | [diff] [blame] | 238 | leave_allocation = frappe.get_doc({ |
| 239 | "doctype": "Leave Allocation", |
| 240 | "employee": employee.name, |
| 241 | "from_date": "{0}-01-01".format(year), |
| 242 | "to_date": "{0}-12-31".format(year), |
| 243 | "leave_type": leave_type.name, |
| 244 | "new_leaves_allocated": random.randint(1, int(leave_type.max_days_allowed)) |
| 245 | }) |
| 246 | leave_allocation.insert() |
| 247 | leave_allocation.submit() |
Rushabh Mehta | efe1ab7 | 2016-08-04 17:29:35 +0530 | [diff] [blame] | 248 | frappe.db.commit() |
Neil Trini Lasrado | 0672459 | 2016-08-22 12:57:09 +0530 | [diff] [blame] | 249 | |
| 250 | def setup_customer(): |
| 251 | 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'] |
| 252 | for c in customers: |
| 253 | frappe.get_doc({ |
| 254 | "doctype": "Customer", |
| 255 | "customer_name": c, |
| 256 | "customer_group": "Commercial", |
| 257 | "customer_type": random.choice(["Company", "Individual"]), |
| 258 | "territory": "Rest Of The World" |
| 259 | }).insert() |
| 260 | |
| 261 | def setup_supplier(): |
| 262 | 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'] |
| 263 | for s in suppliers: |
| 264 | frappe.get_doc({ |
| 265 | "doctype": "Supplier", |
| 266 | "supplier_name": s, |
| 267 | "supplier_type": random.choice(["Services", "Raw Material"]), |
| 268 | }).insert() |
| 269 | |
| 270 | def setup_warehouse(): |
| 271 | w = frappe.new_doc('Warehouse') |
| 272 | w.warehouse_name = 'Supplier' |
| 273 | w.insert() |
| 274 | |
| 275 | def setup_currency_exchange(): |
| 276 | frappe.get_doc({ |
| 277 | 'doctype': 'Currency Exchange', |
| 278 | 'from_currency': 'EUR', |
| 279 | 'to_currency': 'USD', |
| 280 | 'exchange_rate': 1.13 |
| 281 | }).insert() |
| 282 | |
| 283 | frappe.get_doc({ |
| 284 | 'doctype': 'Currency Exchange', |
| 285 | 'from_currency': 'CNY', |
| 286 | 'to_currency': 'USD', |
| 287 | 'exchange_rate': 0.16 |
| 288 | }).insert() |
| 289 | |
| 290 | def setup_mode_of_payment(): |
| 291 | company_abbr = frappe.db.get_value("Company", erpnext.get_default_company(), "abbr") |
| 292 | account_dict = {'Cash': 'Cash - '+ company_abbr , 'Bank': 'National Bank - '+ company_abbr} |
| 293 | for payment_mode in frappe.get_all('Mode of Payment', fields = ["name", "type"]): |
| 294 | if payment_mode.type: |
| 295 | mop = frappe.get_doc('Mode of Payment', payment_mode.name) |
| 296 | mop.append('accounts', { |
| 297 | 'company': erpnext.get_default_company(), |
| 298 | 'default_account': account_dict.get(payment_mode.type) |
| 299 | }) |
| 300 | mop.save(ignore_permissions=True) |
| 301 | |
| 302 | def setup_account(): |
| 303 | frappe.flags.in_import = True |
| 304 | data = json.loads(open(frappe.get_app_path('erpnext', 'demo', 'data', |
| 305 | 'account.json')).read()) |
| 306 | for d in data: |
| 307 | doc = frappe.new_doc('Account') |
| 308 | doc.update(d) |
| 309 | doc.parent_account = frappe.db.get_value('Account', {'account_name': doc.parent_account}) |
| 310 | doc.insert() |
| 311 | |
| 312 | def setup_account_to_expense_type(): |
| 313 | company_abbr = frappe.db.get_value("Company", erpnext.get_default_company(), "abbr") |
| 314 | expense_types = [{'name': _('Calls'), "account": "Sales Expenses - "+ company_abbr}, |
| 315 | {'name': _('Food'), "account": "Entertainment Expenses - "+ company_abbr}, |
| 316 | {'name': _('Medical'), "account": "Utility Expenses - "+ company_abbr}, |
| 317 | {'name': _('Others'), "account": "Miscellaneous Expenses - "+ company_abbr}, |
| 318 | {'name': _('Travel'), "account": "Travel Expenses - "+ company_abbr}] |
| 319 | |
| 320 | for expense_type in expense_types: |
| 321 | doc = frappe.get_doc("Expense Claim Type", expense_type["name"]) |
| 322 | doc.append("accounts", { |
| 323 | "company" : erpnext.get_default_company(), |
| 324 | "default_account" : expense_type["account"] |
| 325 | }) |
| 326 | doc.save(ignore_permissions=True) |
| 327 | |
| 328 | def setup_budget(): |
| 329 | fiscal_years = frappe.get_all("Fiscal Year", order_by="year_start_date")[-2:] |
| 330 | |
| 331 | for fy in fiscal_years: |
| 332 | budget = frappe.new_doc("Budget") |
| 333 | budget.cost_center = get_random("Cost Center") |
| 334 | budget.fiscal_year = fy.name |
| 335 | budget.action_if_annual_budget_exceeded = "Warn" |
| 336 | expense_ledger_count = frappe.db.count("Account", {"is_group": "0", "root_type": "Expense"}) |
| 337 | |
| 338 | add_random_children(budget, "accounts", rows=random.randint(10, expense_ledger_count), randomize = { "account": ("Account", {"is_group": "0", "root_type": "Expense"}) |
| 339 | }, unique="account") |
| 340 | |
| 341 | for d in budget.accounts: |
| 342 | d.budget_amount = random.randint(5, 100) * 10000 |
| 343 | |
| 344 | budget.save() |
| 345 | budget.submit() |
| 346 | |
| 347 | def setup_pos_profile(): |
| 348 | company_abbr = frappe.db.get_value("Company", erpnext.get_default_company(), "abbr") |
| 349 | pos = frappe.new_doc('POS Profile') |
| 350 | pos.user = frappe.db.get_global('demo_accounts_user') |
| 351 | pos.naming_series = 'SINV-' |
| 352 | pos.update_stock = 0 |
| 353 | pos.write_off_account = 'Cost of Goods Sold - '+ company_abbr |
| 354 | pos.write_off_cost_center = 'Main - '+ company_abbr |
| 355 | |
| 356 | pos.append('payments', { |
| 357 | 'mode_of_payment': frappe.db.get_value('Mode of Payment', {'type': 'Cash'}, 'name'), |
| 358 | 'amount': 0.0 |
| 359 | }) |
| 360 | |
| 361 | pos.insert() |
Rushabh Mehta | e9d9b8e | 2016-12-15 11:27:35 +0530 | [diff] [blame] | 362 | |
Neil Trini Lasrado | 0672459 | 2016-08-22 12:57:09 +0530 | [diff] [blame] | 363 | def import_json(doctype, submit=False, values=None): |
| 364 | frappe.flags.in_import = True |
| 365 | data = json.loads(open(frappe.get_app_path('erpnext', 'demo', 'data', |
| 366 | frappe.scrub(doctype) + '.json')).read()) |
| 367 | for d in data: |
| 368 | doc = frappe.new_doc(doctype) |
| 369 | doc.update(d) |
| 370 | doc.insert() |
| 371 | if submit: |
| 372 | doc.submit() |
| 373 | |
| 374 | frappe.db.commit() |
| 375 | |
| 376 | |