blob: a7707a179f90c306673653e6488b3b4271429861 [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()
Anand Doshie9baaa62014-02-26 12:35:33 +053013 frappe.db.set_value('Control Panel', None, '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 Doshi44077d22013-01-27 17:02:49 +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])
26 frappe.doc({
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053027 "doctype": "Country",
28 "country_name": name,
Nabin Hait813a93d2014-03-06 18:21:56 +053029 "code": country.code,
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053030 "date_format": country.date_format or "dd-mm-yyyy",
31 "time_zones": "\n".join(country.timezones or [])
32 }).insert()
33
Anand Doshie9baaa62014-02-26 12:35:33 +053034 if country.currency and not frappe.db.exists("Currency", country.currency):
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053035 frappe.doc({
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053036 "doctype": "Currency",
37 "currency_name": country.currency,
38 "fraction": country.currency_fraction,
39 "symbol": country.currency_symbol,
Rushabh Mehtaf5b04cf2013-01-21 10:14:10 +053040 "fraction_units": country.currency_fraction_units,
41 "number_format": country.number_format
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053042 }).insert()
43
44def import_defaults():
Rushabh Mehta6f9915c2013-01-16 17:48:17 +053045 records = [
46 # item group
Rushabh Mehtaad714732013-07-10 18:59:55 +053047 {'doctype': 'Item Group', 'item_group_name': 'All Item Groups', 'is_group': 'Yes', 'parent_item_group': ''},
48 {'doctype': 'Item Group', 'item_group_name': 'Products', 'is_group': 'No', 'parent_item_group': 'All Item Groups'},
49 {'doctype': 'Item Group', 'item_group_name': 'Raw Material', 'is_group': 'No', 'parent_item_group': 'All Item Groups'},
50 {'doctype': 'Item Group', 'item_group_name': 'Services', 'is_group': 'No', 'parent_item_group': 'All Item Groups'},
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +053051 {'doctype': 'Item Group', 'item_group_name': 'Sub Assemblies', 'is_group': 'No', 'parent_item_group': 'All Item Groups'},
Rushabh Mehtaddca90e2013-10-09 16:08:54 +053052 {'doctype': 'Item Group', 'item_group_name': 'Consumable', 'is_group': 'No', 'parent_item_group': 'All Item Groups'},
Rushabh Mehta6f9915c2013-01-16 17:48:17 +053053
54 # deduction type
55 {'doctype': 'Deduction Type', 'name': 'Income Tax', 'description': 'Income Tax', 'deduction_name': 'Income Tax'},
56 {'doctype': 'Deduction Type', 'name': 'Professional Tax', 'description': 'Professional Tax', 'deduction_name': 'Professional Tax'},
57 {'doctype': 'Deduction Type', 'name': 'Provident Fund', 'description': 'Provident fund', 'deduction_name': 'Provident Fund'},
58
59 # earning type
60 {'doctype': 'Earning Type', 'name': 'Basic', 'description': 'Basic', 'earning_name': 'Basic', 'taxable': 'Yes'},
61 {'doctype': 'Earning Type', 'name': 'House Rent Allowance', 'description': 'House Rent Allowance', 'earning_name': 'House Rent Allowance', 'taxable': 'No'},
62
63 # expense claim type
64 {'doctype': 'Expense Claim Type', 'name': 'Calls', 'expense_type': 'Calls'},
65 {'doctype': 'Expense Claim Type', 'name': 'Food', 'expense_type': 'Food'},
66 {'doctype': 'Expense Claim Type', 'name': 'Medical', 'expense_type': 'Medical'},
67 {'doctype': 'Expense Claim Type', 'name': 'Others', 'expense_type': 'Others'},
68 {'doctype': 'Expense Claim Type', 'name': 'Travel', 'expense_type': 'Travel'},
69
70 # leave type
71 {'doctype': 'Leave Type', 'leave_type_name': 'Casual Leave', 'name': 'Casual Leave', 'is_encash': 1, 'is_carry_forward': 1, 'max_days_allowed': '3', },
72 {'doctype': 'Leave Type', 'leave_type_name': 'Compensatory Off', 'name': 'Compensatory Off', 'is_encash': 0, 'is_carry_forward': 0, },
73 {'doctype': 'Leave Type', 'leave_type_name': 'Sick Leave', 'name': 'Sick Leave', 'is_encash': 0, 'is_carry_forward': 0, },
74 {'doctype': 'Leave Type', 'leave_type_name': 'Privilege Leave', 'name': 'Privilege Leave', 'is_encash': 0, 'is_carry_forward': 0, },
75 {'doctype': 'Leave Type', 'leave_type_name': 'Leave Without Pay', 'name': 'Leave Without Pay', 'is_encash': 0, 'is_carry_forward': 0, 'is_lwp':1},
76
77 # territory
78 {'doctype': 'Territory', 'territory_name': 'All Territories', 'is_group': 'Yes', 'name': 'All Territories', 'parent_territory': ''},
Rushabh Mehta6f9915c2013-01-16 17:48:17 +053079
80 # customer group
81 {'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 +053082 {'doctype': 'Customer Group', 'customer_group_name': 'Individual', 'is_group': 'No', 'parent_customer_group': 'All Customer Groups'},
83 {'doctype': 'Customer Group', 'customer_group_name': 'Commercial', 'is_group': 'No', 'parent_customer_group': 'All Customer Groups'},
84 {'doctype': 'Customer Group', 'customer_group_name': 'Non Profit', 'is_group': 'No', 'parent_customer_group': 'All Customer Groups'},
85 {'doctype': 'Customer Group', 'customer_group_name': 'Government', 'is_group': 'No', 'parent_customer_group': 'All Customer Groups'},
Rushabh Mehta6f9915c2013-01-16 17:48:17 +053086
87 # supplier type
Rushabh Mehtaad714732013-07-10 18:59:55 +053088 {'doctype': 'Supplier Type', 'supplier_type': 'Services'},
89 {'doctype': 'Supplier Type', 'supplier_type': 'Local'},
90 {'doctype': 'Supplier Type', 'supplier_type': 'Raw Material'},
91 {'doctype': 'Supplier Type', 'supplier_type': 'Electrical'},
92 {'doctype': 'Supplier Type', 'supplier_type': 'Hardware'},
93 {'doctype': 'Supplier Type', 'supplier_type': 'Pharmaceutical'},
94 {'doctype': 'Supplier Type', 'supplier_type': 'Distributor'},
Rushabh Mehta6f9915c2013-01-16 17:48:17 +053095
96 # Sales Person
Rushabh Mehtaad714732013-07-10 18:59:55 +053097 {'doctype': 'Sales Person', 'sales_person_name': 'Sales Team', 'is_group': "Yes", "parent_sales_person": ""},
Rushabh Mehta6f9915c2013-01-16 17:48:17 +053098
99 # UOM
Rushabh Mehta4dca4012013-07-25 17:45:59 +0530100 {'uom_name': 'Unit', 'doctype': 'UOM', 'name': 'Unit', "must_be_whole_number": 1},
101 {'uom_name': 'Box', 'doctype': 'UOM', 'name': 'Box', "must_be_whole_number": 1},
Rushabh Mehta6f9915c2013-01-16 17:48:17 +0530102 {'uom_name': 'Kg', 'doctype': 'UOM', 'name': 'Kg'},
Rushabh Mehta4dca4012013-07-25 17:45:59 +0530103 {'uom_name': 'Nos', 'doctype': 'UOM', 'name': 'Nos', "must_be_whole_number": 1},
104 {'uom_name': 'Pair', 'doctype': 'UOM', 'name': 'Pair', "must_be_whole_number": 1},
105 {'uom_name': 'Set', 'doctype': 'UOM', 'name': 'Set', "must_be_whole_number": 1},
106 {'uom_name': 'Hour', 'doctype': 'UOM', 'name': 'Hour'},
Rushabh Mehtadb7139a2013-01-17 18:22:22 +0530107 {'uom_name': 'Minute', 'doctype': 'UOM', 'name': 'Minute'},
Rushabh Mehtad8de9212014-03-06 15:40:22 +0530108
Rushabh Mehta6f9915c2013-01-16 17:48:17 +0530109 ]
110
Rushabh Mehta793ba6b2014-02-14 15:47:51 +0530111 from frappe.modules import scrub
Rushabh Mehta6f9915c2013-01-16 17:48:17 +0530112 for r in records:
Rushabh Mehta793ba6b2014-02-14 15:47:51 +0530113 bean = frappe.bean(r)
Rushabh Mehtae41bceb2013-07-10 20:42:44 +0530114
115 # ignore mandatory for root
116 parent_link_field = ("parent_" + scrub(bean.doc.doctype))
117 if parent_link_field in bean.doc.fields and not bean.doc.fields.get(parent_link_field):
118 bean.ignore_mandatory = True
119
Rushabh Mehta1f847992013-12-12 19:12:19 +0530120 bean.insert()
121
122def feature_setup():
123 """save global defaults and features setup"""
Rushabh Mehta793ba6b2014-02-14 15:47:51 +0530124 bean = frappe.bean("Features Setup", "Features Setup")
Rushabh Mehta1f847992013-12-12 19:12:19 +0530125 bean.ignore_permissions = True
126
127 # store value as 1 for all these fields
128 flds = ['fs_item_serial_nos', 'fs_item_batch_nos', 'fs_brands', 'fs_item_barcode',
129 'fs_item_advanced', 'fs_packing_details', 'fs_item_group_in_details',
130 'fs_exports', 'fs_imports', 'fs_discounts', 'fs_purchase_discounts',
131 'fs_after_sales_installations', 'fs_projects', 'fs_sales_extras',
132 'fs_recurring_invoice', 'fs_pos', 'fs_manufacturing', 'fs_quality',
133 'fs_page_break', 'fs_more_info', 'fs_pos_view'
134 ]
135 bean.doc.fields.update(dict(zip(flds, [1]*len(flds))))
Pratik Vyas28da7522014-02-19 20:53:45 +0530136 bean.save()
137
138def set_single_defaults():
Anand Doshieb7fea62014-03-19 17:10:01 +0530139 for dt in frappe.db.sql_list("""select name from `tabDocType` where issingle=1"""):
140 default_values = frappe.db.sql("""select fieldname, `default` from `tabDocField`
141 where parent=%s""", dt, as_dict=True)
142 if default_values:
143 try:
144 b = frappe.bean(dt, dt)
145 for fieldname, value in default_values:
146 b.doc.fields[fieldname] = value
147 b.save()
148 except frappe.MandatoryError:
149 pass
150
Anand Doshie9baaa62014-02-26 12:35:33 +0530151 frappe.db.set_default("date_format", "dd-mm-yyyy")