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