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