blob: 71b62032bc27b2d1efa440cfe213c30c24783129 [file] [log] [blame]
Rushabh Mehtaad45e312013-11-20 12:59:58 +05301# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
Rushabh Mehtae67d1fb2013-08-05 14:59:54 +05302# License: GNU General Public License v3. See license.txt
3
Rushabh Mehta6f9915c2013-01-16 17:48:17 +05304from __future__ import unicode_literals
5
Rushabh Mehta793ba6b2014-02-14 15:47:51 +05306import frappe
Rushabh Mehta6f9915c2013-01-16 17:48:17 +05307
Rushabh Mehta1f847992013-12-12 19:12:19 +05308def after_install():
Rushabh Mehtadb7139a2013-01-17 18:22:22 +05309 import_defaults()
10 import_country_and_currency()
Nabin Hait813a93d2014-03-06 18:21:56 +053011 from erpnext.accounts.doctype.chart_of_accounts.import_charts import import_charts
12 import_charts()
Rushabh Mehta558a9aa2014-04-04 12:00:36 +053013 frappe.db.set_default('desktop:home_page', 'setup-wizard')
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053014 feature_setup()
Rushabh Mehta1f847992013-12-12 19:12:19 +053015 from erpnext.setup.page.setup_wizard.setup_wizard import add_all_roles_to
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053016 add_all_roles_to("Administrator")
Pratik Vyas28da7522014-02-19 20:53:45 +053017 set_single_defaults()
Anand Doshie9baaa62014-02-26 12:35:33 +053018 frappe.db.commit()
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053019
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053020def import_country_and_currency():
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053021 from frappe.country_info import get_all
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053022 data = get_all()
Anand Doshi13ae5482014-04-10 18:40:57 +053023
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053024 for name in data:
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053025 country = frappe._dict(data[name])
Anand Doshi7fbdba02014-03-25 13:50:52 +053026 if not frappe.db.exists("Country", name):
Rushabh Mehtab385ecf2014-03-28 16:44:37 +053027 frappe.get_doc({
Anand Doshi7fbdba02014-03-25 13:50:52 +053028 "doctype": "Country",
29 "country_name": name,
30 "code": country.code,
31 "date_format": country.date_format or "dd-mm-yyyy",
32 "time_zones": "\n".join(country.timezones or [])
33 }).insert()
Anand Doshi13ae5482014-04-10 18:40:57 +053034
Anand Doshie9baaa62014-02-26 12:35:33 +053035 if country.currency and not frappe.db.exists("Currency", country.currency):
Rushabh Mehtab385ecf2014-03-28 16:44:37 +053036 frappe.get_doc({
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053037 "doctype": "Currency",
38 "currency_name": country.currency,
39 "fraction": country.currency_fraction,
40 "symbol": country.currency_symbol,
Rushabh Mehtaf5b04cf2013-01-21 10:14:10 +053041 "fraction_units": country.currency_fraction_units,
42 "number_format": country.number_format
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053043 }).insert()
44
45def import_defaults():
Rushabh Mehta6f9915c2013-01-16 17:48:17 +053046 records = [
Anand Doshi13ae5482014-04-10 18:40:57 +053047 # role
48 {'doctype': "Role", "role_name": "Analytics"},
49
Rushabh Mehta6f9915c2013-01-16 17:48:17 +053050 # item group
Rushabh Mehtaad714732013-07-10 18:59:55 +053051 {'doctype': 'Item Group', 'item_group_name': 'All Item Groups', 'is_group': 'Yes', 'parent_item_group': ''},
52 {'doctype': 'Item Group', 'item_group_name': 'Products', 'is_group': 'No', 'parent_item_group': 'All Item Groups'},
53 {'doctype': 'Item Group', 'item_group_name': 'Raw Material', 'is_group': 'No', 'parent_item_group': 'All Item Groups'},
54 {'doctype': 'Item Group', 'item_group_name': 'Services', 'is_group': 'No', 'parent_item_group': 'All Item Groups'},
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +053055 {'doctype': 'Item Group', 'item_group_name': 'Sub Assemblies', 'is_group': 'No', 'parent_item_group': 'All Item Groups'},
Rushabh Mehtaddca90e2013-10-09 16:08:54 +053056 {'doctype': 'Item Group', 'item_group_name': 'Consumable', 'is_group': 'No', 'parent_item_group': 'All Item Groups'},
Anand Doshi13ae5482014-04-10 18:40:57 +053057
Rushabh Mehta6f9915c2013-01-16 17:48:17 +053058 # deduction type
59 {'doctype': 'Deduction Type', 'name': 'Income Tax', 'description': 'Income Tax', 'deduction_name': 'Income Tax'},
60 {'doctype': 'Deduction Type', 'name': 'Professional Tax', 'description': 'Professional Tax', 'deduction_name': 'Professional Tax'},
61 {'doctype': 'Deduction Type', 'name': 'Provident Fund', 'description': 'Provident fund', 'deduction_name': 'Provident Fund'},
Anand Doshi13ae5482014-04-10 18:40:57 +053062
Rushabh Mehta6f9915c2013-01-16 17:48:17 +053063 # earning type
64 {'doctype': 'Earning Type', 'name': 'Basic', 'description': 'Basic', 'earning_name': 'Basic', 'taxable': 'Yes'},
65 {'doctype': 'Earning Type', 'name': 'House Rent Allowance', 'description': 'House Rent Allowance', 'earning_name': 'House Rent Allowance', 'taxable': 'No'},
Anand Doshi13ae5482014-04-10 18:40:57 +053066
Rushabh Mehta6f9915c2013-01-16 17:48:17 +053067 # expense claim type
68 {'doctype': 'Expense Claim Type', 'name': 'Calls', 'expense_type': 'Calls'},
69 {'doctype': 'Expense Claim Type', 'name': 'Food', 'expense_type': 'Food'},
70 {'doctype': 'Expense Claim Type', 'name': 'Medical', 'expense_type': 'Medical'},
71 {'doctype': 'Expense Claim Type', 'name': 'Others', 'expense_type': 'Others'},
72 {'doctype': 'Expense Claim Type', 'name': 'Travel', 'expense_type': 'Travel'},
Anand Doshi13ae5482014-04-10 18:40:57 +053073
Rushabh Mehta6f9915c2013-01-16 17:48:17 +053074 # leave type
75 {'doctype': 'Leave Type', 'leave_type_name': 'Casual Leave', 'name': 'Casual Leave', 'is_encash': 1, 'is_carry_forward': 1, 'max_days_allowed': '3', },
76 {'doctype': 'Leave Type', 'leave_type_name': 'Compensatory Off', 'name': 'Compensatory Off', 'is_encash': 0, 'is_carry_forward': 0, },
77 {'doctype': 'Leave Type', 'leave_type_name': 'Sick Leave', 'name': 'Sick Leave', 'is_encash': 0, 'is_carry_forward': 0, },
78 {'doctype': 'Leave Type', 'leave_type_name': 'Privilege Leave', 'name': 'Privilege Leave', 'is_encash': 0, 'is_carry_forward': 0, },
79 {'doctype': 'Leave Type', 'leave_type_name': 'Leave Without Pay', 'name': 'Leave Without Pay', 'is_encash': 0, 'is_carry_forward': 0, 'is_lwp':1},
Anand Doshi13ae5482014-04-10 18:40:57 +053080
Rushabh Mehta6f9915c2013-01-16 17:48:17 +053081 # territory
82 {'doctype': 'Territory', 'territory_name': 'All Territories', 'is_group': 'Yes', 'name': 'All Territories', 'parent_territory': ''},
Anand Doshi13ae5482014-04-10 18:40:57 +053083
Rushabh Mehta6f9915c2013-01-16 17:48:17 +053084 # customer group
85 {'doctype': 'Customer Group', 'customer_group_name': 'All Customer Groups', 'is_group': 'Yes', 'name': 'All Customer Groups', 'parent_customer_group': ''},
Rushabh Mehtaad714732013-07-10 18:59:55 +053086 {'doctype': 'Customer Group', 'customer_group_name': 'Individual', 'is_group': 'No', 'parent_customer_group': 'All Customer Groups'},
87 {'doctype': 'Customer Group', 'customer_group_name': 'Commercial', 'is_group': 'No', 'parent_customer_group': 'All Customer Groups'},
88 {'doctype': 'Customer Group', 'customer_group_name': 'Non Profit', 'is_group': 'No', 'parent_customer_group': 'All Customer Groups'},
89 {'doctype': 'Customer Group', 'customer_group_name': 'Government', 'is_group': 'No', 'parent_customer_group': 'All Customer Groups'},
Anand Doshi13ae5482014-04-10 18:40:57 +053090
Rushabh Mehta6f9915c2013-01-16 17:48:17 +053091 # supplier type
Rushabh Mehtaad714732013-07-10 18:59:55 +053092 {'doctype': 'Supplier Type', 'supplier_type': 'Services'},
93 {'doctype': 'Supplier Type', 'supplier_type': 'Local'},
94 {'doctype': 'Supplier Type', 'supplier_type': 'Raw Material'},
95 {'doctype': 'Supplier Type', 'supplier_type': 'Electrical'},
96 {'doctype': 'Supplier Type', 'supplier_type': 'Hardware'},
97 {'doctype': 'Supplier Type', 'supplier_type': 'Pharmaceutical'},
98 {'doctype': 'Supplier Type', 'supplier_type': 'Distributor'},
Anand Doshi13ae5482014-04-10 18:40:57 +053099
Rushabh Mehta6f9915c2013-01-16 17:48:17 +0530100 # Sales Person
Rushabh Mehtaad714732013-07-10 18:59:55 +0530101 {'doctype': 'Sales Person', 'sales_person_name': 'Sales Team', 'is_group': "Yes", "parent_sales_person": ""},
Anand Doshi13ae5482014-04-10 18:40:57 +0530102
Rushabh Mehta6f9915c2013-01-16 17:48:17 +0530103 # UOM
Anand Doshi13ae5482014-04-10 18:40:57 +0530104 {'uom_name': 'Unit', 'doctype': 'UOM', 'name': 'Unit', "must_be_whole_number": 1},
105 {'uom_name': 'Box', 'doctype': 'UOM', 'name': 'Box', "must_be_whole_number": 1},
106 {'uom_name': 'Kg', 'doctype': 'UOM', 'name': 'Kg'},
107 {'uom_name': 'Nos', 'doctype': 'UOM', 'name': 'Nos', "must_be_whole_number": 1},
108 {'uom_name': 'Pair', 'doctype': 'UOM', 'name': 'Pair', "must_be_whole_number": 1},
109 {'uom_name': 'Set', 'doctype': 'UOM', 'name': 'Set', "must_be_whole_number": 1},
Rushabh Mehta4dca4012013-07-25 17:45:59 +0530110 {'uom_name': 'Hour', 'doctype': 'UOM', 'name': 'Hour'},
Anand Doshi13ae5482014-04-10 18:40:57 +0530111 {'uom_name': 'Minute', 'doctype': 'UOM', 'name': 'Minute'},
Rushabh Mehtad8de9212014-03-06 15:40:22 +0530112
Rushabh Mehta6f9915c2013-01-16 17:48:17 +0530113 ]
Anand Doshi13ae5482014-04-10 18:40:57 +0530114
Rushabh Mehta793ba6b2014-02-14 15:47:51 +0530115 from frappe.modules import scrub
Rushabh Mehta6f9915c2013-01-16 17:48:17 +0530116 for r in records:
Rushabh Mehtaf191f852014-04-02 18:09:34 +0530117 doc = frappe.get_doc(r)
Anand Doshi13ae5482014-04-10 18:40:57 +0530118
Rushabh Mehtae41bceb2013-07-10 20:42:44 +0530119 # ignore mandatory for root
Rushabh Mehtaf191f852014-04-02 18:09:34 +0530120 parent_link_field = ("parent_" + scrub(doc.doctype))
121 if doc.meta.get_field(parent_link_field) and not doc.get(parent_link_field):
122 doc.ignore_mandatory = True
Anand Doshi13ae5482014-04-10 18:40:57 +0530123
Rushabh Mehtaf191f852014-04-02 18:09:34 +0530124 doc.insert()
Anand Doshi13ae5482014-04-10 18:40:57 +0530125
Rushabh Mehta1f847992013-12-12 19:12:19 +0530126def feature_setup():
127 """save global defaults and features setup"""
Rushabh Mehtaf191f852014-04-02 18:09:34 +0530128 doc = frappe.get_doc("Features Setup", "Features Setup")
129 doc.ignore_permissions = True
Rushabh Mehta1f847992013-12-12 19:12:19 +0530130
131 # store value as 1 for all these fields
132 flds = ['fs_item_serial_nos', 'fs_item_batch_nos', 'fs_brands', 'fs_item_barcode',
133 'fs_item_advanced', 'fs_packing_details', 'fs_item_group_in_details',
134 'fs_exports', 'fs_imports', 'fs_discounts', 'fs_purchase_discounts',
135 'fs_after_sales_installations', 'fs_projects', 'fs_sales_extras',
136 'fs_recurring_invoice', 'fs_pos', 'fs_manufacturing', 'fs_quality',
137 'fs_page_break', 'fs_more_info', 'fs_pos_view'
138 ]
Rushabh Mehtaf191f852014-04-02 18:09:34 +0530139 doc.update(dict(zip(flds, [1]*len(flds))))
140 doc.save()
Pratik Vyas28da7522014-02-19 20:53:45 +0530141
142def set_single_defaults():
Nabin Haite7885e32014-04-04 13:26:50 +0530143 for dt in frappe.db.sql_list("""select name from `tabDocType` where issingle=1"""):
Anand Doshieb7fea62014-03-19 17:10:01 +0530144 default_values = frappe.db.sql("""select fieldname, `default` from `tabDocField`
Rushabh Mehtaf14b8092014-04-03 14:30:42 +0530145 where parent=%s""", dt)
Anand Doshieb7fea62014-03-19 17:10:01 +0530146 if default_values:
147 try:
Rushabh Mehtab385ecf2014-03-28 16:44:37 +0530148 b = frappe.get_doc(dt, dt)
Anand Doshieb7fea62014-03-19 17:10:01 +0530149 for fieldname, value in default_values:
Anand Doshif78d1ae2014-03-28 13:55:00 +0530150 b.set(fieldname, value)
Anand Doshieb7fea62014-03-19 17:10:01 +0530151 b.save()
152 except frappe.MandatoryError:
153 pass
154
Anand Doshie9baaa62014-02-26 12:35:33 +0530155 frappe.db.set_default("date_format", "dd-mm-yyyy")