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