Rushabh Mehta | e67d1fb | 2013-08-05 14:59:54 +0530 | [diff] [blame] | 1 | # Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. |
| 2 | # License: GNU General Public License v3. See license.txt |
| 3 | |
Rushabh Mehta | 6f9915c | 2013-01-16 17:48:17 +0530 | [diff] [blame] | 4 | from __future__ import unicode_literals |
| 5 | |
| 6 | import webnotes |
| 7 | |
| 8 | def pre_import(): |
Rushabh Mehta | db7139a | 2013-01-17 18:22:22 +0530 | [diff] [blame] | 9 | webnotes.conn.begin() |
Rushabh Mehta | 6f9915c | 2013-01-16 17:48:17 +0530 | [diff] [blame] | 10 | make_modules() |
| 11 | make_roles() |
Rushabh Mehta | db7139a | 2013-01-17 18:22:22 +0530 | [diff] [blame] | 12 | webnotes.conn.commit() |
Rushabh Mehta | 6f9915c | 2013-01-16 17:48:17 +0530 | [diff] [blame] | 13 | |
| 14 | def make_modules(): |
| 15 | modules = [ |
Rushabh Mehta | 982ad35 | 2013-07-10 18:39:06 +0530 | [diff] [blame] | 16 | "Home", "System", "Utilities", "Website", "Setup", |
| 17 | "Selling", "Buying", "Projects", "Accounts", "Stock", |
| 18 | "Support", "HR", "Manufacturing"] |
Rushabh Mehta | 6f9915c | 2013-01-16 17:48:17 +0530 | [diff] [blame] | 19 | |
| 20 | for m in modules: |
| 21 | doc = webnotes.doc(fielddata = { |
| 22 | "doctype": "Module Def", |
| 23 | "module_name": m, |
Rushabh Mehta | 6f9915c | 2013-01-16 17:48:17 +0530 | [diff] [blame] | 24 | }) |
| 25 | doc.insert() |
| 26 | |
| 27 | def make_roles(): |
| 28 | roles = [ |
Rushabh Mehta | db7139a | 2013-01-17 18:22:22 +0530 | [diff] [blame] | 29 | "Accounts Manager", "Accounts User", "Analytics", "Auditor", |
| 30 | "Blogger", "Customer", "Employee", "Expense Approver", |
| 31 | "HR Manager", "HR User", "Leave Approver", "Maintenance Manager", |
| 32 | "Maintenance User", "Manufacturing Manager", "Manufacturing User", |
| 33 | "Material Manager", "Material Master Manager", "Material User", |
Rushabh Mehta | ed19666 | 2013-02-26 16:36:41 +0530 | [diff] [blame] | 34 | "Partner", "Projects User", "Projects Manager", "Purchase Manager", "Purchase Master Manager", |
Rushabh Mehta | db7139a | 2013-01-17 18:22:22 +0530 | [diff] [blame] | 35 | "Purchase User", "Quality Manager", "Sales Manager", |
| 36 | "Sales Master Manager", "Sales User", "Supplier", "Support Manager", |
Anand Doshi | 3422bdf | 2013-02-12 13:03:25 +0530 | [diff] [blame] | 37 | "Support Team", "Website Manager"] |
Rushabh Mehta | db7139a | 2013-01-17 18:22:22 +0530 | [diff] [blame] | 38 | |
Rushabh Mehta | 6f9915c | 2013-01-16 17:48:17 +0530 | [diff] [blame] | 39 | for r in roles: |
| 40 | doc = webnotes.doc(fielddata = { |
| 41 | "doctype":"Role", |
| 42 | "role_name": r |
| 43 | }) |
| 44 | doc.insert() |
Rushabh Mehta | db7139a | 2013-01-17 18:22:22 +0530 | [diff] [blame] | 45 | |
Rushabh Mehta | 6f9915c | 2013-01-16 17:48:17 +0530 | [diff] [blame] | 46 | def post_import(): |
Rushabh Mehta | db7139a | 2013-01-17 18:22:22 +0530 | [diff] [blame] | 47 | webnotes.conn.begin() |
Rushabh Mehta | a94d1af | 2013-06-25 12:36:13 +0530 | [diff] [blame] | 48 | |
Rushabh Mehta | db7139a | 2013-01-17 18:22:22 +0530 | [diff] [blame] | 49 | # feature setup |
| 50 | import_defaults() |
| 51 | import_country_and_currency() |
| 52 | |
| 53 | # home page |
| 54 | webnotes.conn.set_value('Control Panel', None, 'home_page', 'desktop') |
| 55 | |
| 56 | # features |
| 57 | feature_setup() |
| 58 | |
| 59 | # all roles to Administrator |
| 60 | from setup.doctype.setup_control.setup_control import add_all_roles_to |
| 61 | add_all_roles_to("Administrator") |
| 62 | |
| 63 | webnotes.conn.commit() |
| 64 | |
| 65 | def feature_setup(): |
| 66 | """save global defaults and features setup""" |
| 67 | doc = webnotes.doc("Features Setup", "Features Setup") |
| 68 | |
| 69 | # store value as 1 for all these fields |
| 70 | flds = ['fs_item_serial_nos', 'fs_item_batch_nos', 'fs_brands', 'fs_item_barcode', |
| 71 | 'fs_item_advanced', 'fs_packing_details', 'fs_item_group_in_details', |
| 72 | 'fs_exports', 'fs_imports', 'fs_discounts', 'fs_purchase_discounts', |
| 73 | 'fs_after_sales_installations', 'fs_projects', 'fs_sales_extras', |
| 74 | 'fs_recurring_invoice', 'fs_pos', 'fs_manufacturing', 'fs_quality', |
| 75 | 'fs_page_break', 'fs_more_info' |
| 76 | ] |
| 77 | doc.fields.update(dict(zip(flds, [1]*len(flds)))) |
| 78 | doc.save() |
| 79 | |
| 80 | def import_country_and_currency(): |
| 81 | from webnotes.country_info import get_all |
| 82 | data = get_all() |
Anand Doshi | 44077d2 | 2013-01-27 17:02:49 +0530 | [diff] [blame] | 83 | |
Rushabh Mehta | db7139a | 2013-01-17 18:22:22 +0530 | [diff] [blame] | 84 | for name in data: |
| 85 | country = webnotes._dict(data[name]) |
| 86 | webnotes.doc({ |
| 87 | "doctype": "Country", |
| 88 | "country_name": name, |
| 89 | "date_format": country.date_format or "dd-mm-yyyy", |
| 90 | "time_zones": "\n".join(country.timezones or []) |
| 91 | }).insert() |
| 92 | |
Anand Doshi | 44077d2 | 2013-01-27 17:02:49 +0530 | [diff] [blame] | 93 | if country.currency and not webnotes.conn.exists("Currency", country.currency): |
Rushabh Mehta | db7139a | 2013-01-17 18:22:22 +0530 | [diff] [blame] | 94 | webnotes.doc({ |
| 95 | "doctype": "Currency", |
| 96 | "currency_name": country.currency, |
| 97 | "fraction": country.currency_fraction, |
| 98 | "symbol": country.currency_symbol, |
Rushabh Mehta | f5b04cf | 2013-01-21 10:14:10 +0530 | [diff] [blame] | 99 | "fraction_units": country.currency_fraction_units, |
| 100 | "number_format": country.number_format |
Rushabh Mehta | db7139a | 2013-01-17 18:22:22 +0530 | [diff] [blame] | 101 | }).insert() |
| 102 | |
| 103 | def import_defaults(): |
Rushabh Mehta | 6f9915c | 2013-01-16 17:48:17 +0530 | [diff] [blame] | 104 | records = [ |
| 105 | # item group |
Rushabh Mehta | ad71473 | 2013-07-10 18:59:55 +0530 | [diff] [blame] | 106 | {'doctype': 'Item Group', 'item_group_name': 'All Item Groups', 'is_group': 'Yes', 'parent_item_group': ''}, |
| 107 | {'doctype': 'Item Group', 'item_group_name': 'Products', 'is_group': 'No', 'parent_item_group': 'All Item Groups'}, |
| 108 | {'doctype': 'Item Group', 'item_group_name': 'Raw Material', 'is_group': 'No', 'parent_item_group': 'All Item Groups'}, |
| 109 | {'doctype': 'Item Group', 'item_group_name': 'Services', 'is_group': 'No', 'parent_item_group': 'All Item Groups'}, |
Rushabh Mehta | 7cfefbc | 2013-08-07 17:46:35 +0530 | [diff] [blame] | 110 | {'doctype': 'Item Group', 'item_group_name': 'Sub Assemblies', 'is_group': 'No', 'parent_item_group': 'All Item Groups'}, |
Rushabh Mehta | 6f9915c | 2013-01-16 17:48:17 +0530 | [diff] [blame] | 111 | |
| 112 | # deduction type |
| 113 | {'doctype': 'Deduction Type', 'name': 'Income Tax', 'description': 'Income Tax', 'deduction_name': 'Income Tax'}, |
| 114 | {'doctype': 'Deduction Type', 'name': 'Professional Tax', 'description': 'Professional Tax', 'deduction_name': 'Professional Tax'}, |
| 115 | {'doctype': 'Deduction Type', 'name': 'Provident Fund', 'description': 'Provident fund', 'deduction_name': 'Provident Fund'}, |
| 116 | |
| 117 | # earning type |
| 118 | {'doctype': 'Earning Type', 'name': 'Basic', 'description': 'Basic', 'earning_name': 'Basic', 'taxable': 'Yes'}, |
| 119 | {'doctype': 'Earning Type', 'name': 'House Rent Allowance', 'description': 'House Rent Allowance', 'earning_name': 'House Rent Allowance', 'taxable': 'No'}, |
| 120 | |
| 121 | # expense claim type |
| 122 | {'doctype': 'Expense Claim Type', 'name': 'Calls', 'expense_type': 'Calls'}, |
| 123 | {'doctype': 'Expense Claim Type', 'name': 'Food', 'expense_type': 'Food'}, |
| 124 | {'doctype': 'Expense Claim Type', 'name': 'Medical', 'expense_type': 'Medical'}, |
| 125 | {'doctype': 'Expense Claim Type', 'name': 'Others', 'expense_type': 'Others'}, |
| 126 | {'doctype': 'Expense Claim Type', 'name': 'Travel', 'expense_type': 'Travel'}, |
| 127 | |
| 128 | # leave type |
| 129 | {'doctype': 'Leave Type', 'leave_type_name': 'Casual Leave', 'name': 'Casual Leave', 'is_encash': 1, 'is_carry_forward': 1, 'max_days_allowed': '3', }, |
| 130 | {'doctype': 'Leave Type', 'leave_type_name': 'Compensatory Off', 'name': 'Compensatory Off', 'is_encash': 0, 'is_carry_forward': 0, }, |
| 131 | {'doctype': 'Leave Type', 'leave_type_name': 'Sick Leave', 'name': 'Sick Leave', 'is_encash': 0, 'is_carry_forward': 0, }, |
| 132 | {'doctype': 'Leave Type', 'leave_type_name': 'Privilege Leave', 'name': 'Privilege Leave', 'is_encash': 0, 'is_carry_forward': 0, }, |
| 133 | {'doctype': 'Leave Type', 'leave_type_name': 'Leave Without Pay', 'name': 'Leave Without Pay', 'is_encash': 0, 'is_carry_forward': 0, 'is_lwp':1}, |
| 134 | |
| 135 | # territory |
| 136 | {'doctype': 'Territory', 'territory_name': 'All Territories', 'is_group': 'Yes', 'name': 'All Territories', 'parent_territory': ''}, |
Rushabh Mehta | 6f9915c | 2013-01-16 17:48:17 +0530 | [diff] [blame] | 137 | |
| 138 | # customer group |
| 139 | {'doctype': 'Customer Group', 'customer_group_name': 'All Customer Groups', 'is_group': 'Yes', 'name': 'All Customer Groups', 'parent_customer_group': ''}, |
Rushabh Mehta | ad71473 | 2013-07-10 18:59:55 +0530 | [diff] [blame] | 140 | {'doctype': 'Customer Group', 'customer_group_name': 'Individual', 'is_group': 'No', 'parent_customer_group': 'All Customer Groups'}, |
| 141 | {'doctype': 'Customer Group', 'customer_group_name': 'Commercial', 'is_group': 'No', 'parent_customer_group': 'All Customer Groups'}, |
| 142 | {'doctype': 'Customer Group', 'customer_group_name': 'Non Profit', 'is_group': 'No', 'parent_customer_group': 'All Customer Groups'}, |
| 143 | {'doctype': 'Customer Group', 'customer_group_name': 'Government', 'is_group': 'No', 'parent_customer_group': 'All Customer Groups'}, |
Rushabh Mehta | 6f9915c | 2013-01-16 17:48:17 +0530 | [diff] [blame] | 144 | |
| 145 | # supplier type |
Rushabh Mehta | ad71473 | 2013-07-10 18:59:55 +0530 | [diff] [blame] | 146 | {'doctype': 'Supplier Type', 'supplier_type': 'Services'}, |
| 147 | {'doctype': 'Supplier Type', 'supplier_type': 'Local'}, |
| 148 | {'doctype': 'Supplier Type', 'supplier_type': 'Raw Material'}, |
| 149 | {'doctype': 'Supplier Type', 'supplier_type': 'Electrical'}, |
| 150 | {'doctype': 'Supplier Type', 'supplier_type': 'Hardware'}, |
| 151 | {'doctype': 'Supplier Type', 'supplier_type': 'Pharmaceutical'}, |
| 152 | {'doctype': 'Supplier Type', 'supplier_type': 'Distributor'}, |
Rushabh Mehta | 6f9915c | 2013-01-16 17:48:17 +0530 | [diff] [blame] | 153 | |
| 154 | # Sales Person |
Rushabh Mehta | ad71473 | 2013-07-10 18:59:55 +0530 | [diff] [blame] | 155 | {'doctype': 'Sales Person', 'sales_person_name': 'Sales Team', 'is_group': "Yes", "parent_sales_person": ""}, |
Rushabh Mehta | 6f9915c | 2013-01-16 17:48:17 +0530 | [diff] [blame] | 156 | |
| 157 | # UOM |
Rushabh Mehta | 4dca401 | 2013-07-25 17:45:59 +0530 | [diff] [blame] | 158 | {'uom_name': 'Unit', 'doctype': 'UOM', 'name': 'Unit', "must_be_whole_number": 1}, |
| 159 | {'uom_name': 'Box', 'doctype': 'UOM', 'name': 'Box', "must_be_whole_number": 1}, |
Rushabh Mehta | 6f9915c | 2013-01-16 17:48:17 +0530 | [diff] [blame] | 160 | {'uom_name': 'Kg', 'doctype': 'UOM', 'name': 'Kg'}, |
Rushabh Mehta | 4dca401 | 2013-07-25 17:45:59 +0530 | [diff] [blame] | 161 | {'uom_name': 'Nos', 'doctype': 'UOM', 'name': 'Nos', "must_be_whole_number": 1}, |
| 162 | {'uom_name': 'Pair', 'doctype': 'UOM', 'name': 'Pair', "must_be_whole_number": 1}, |
| 163 | {'uom_name': 'Set', 'doctype': 'UOM', 'name': 'Set', "must_be_whole_number": 1}, |
| 164 | {'uom_name': 'Hour', 'doctype': 'UOM', 'name': 'Hour'}, |
Rushabh Mehta | db7139a | 2013-01-17 18:22:22 +0530 | [diff] [blame] | 165 | {'uom_name': 'Minute', 'doctype': 'UOM', 'name': 'Minute'}, |
Rushabh Mehta | 6f9915c | 2013-01-16 17:48:17 +0530 | [diff] [blame] | 166 | ] |
| 167 | |
Anand Doshi | 4ee647e | 2013-07-08 18:50:45 +0530 | [diff] [blame] | 168 | from webnotes.modules import scrub |
Rushabh Mehta | 6f9915c | 2013-01-16 17:48:17 +0530 | [diff] [blame] | 169 | for r in records: |
Rushabh Mehta | e41bceb | 2013-07-10 20:42:44 +0530 | [diff] [blame] | 170 | bean = webnotes.bean(r) |
| 171 | |
| 172 | # ignore mandatory for root |
| 173 | parent_link_field = ("parent_" + scrub(bean.doc.doctype)) |
| 174 | if parent_link_field in bean.doc.fields and not bean.doc.fields.get(parent_link_field): |
| 175 | bean.ignore_mandatory = True |
| 176 | |
| 177 | bean.insert() |