blob: 9fe243d96659c0523fbc7ba88257b05f0fc2e16f [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])
Anand Doshi7fbdba02014-03-25 13:50:52 +053026 if not frappe.db.exists("Country", name):
27 frappe.doc({
28 "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()
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053034
Anand Doshie9baaa62014-02-26 12:35:33 +053035 if country.currency and not frappe.db.exists("Currency", country.currency):
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053036 frappe.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 = [
47 # item group
Rushabh Mehtaad714732013-07-10 18:59:55 +053048 {'doctype': 'Item Group', 'item_group_name': 'All Item Groups', 'is_group': 'Yes', 'parent_item_group': ''},
49 {'doctype': 'Item Group', 'item_group_name': 'Products', 'is_group': 'No', 'parent_item_group': 'All Item Groups'},
50 {'doctype': 'Item Group', 'item_group_name': 'Raw Material', 'is_group': 'No', 'parent_item_group': 'All Item Groups'},
51 {'doctype': 'Item Group', 'item_group_name': 'Services', 'is_group': 'No', 'parent_item_group': 'All Item Groups'},
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +053052 {'doctype': 'Item Group', 'item_group_name': 'Sub Assemblies', 'is_group': 'No', 'parent_item_group': 'All Item Groups'},
Rushabh Mehtaddca90e2013-10-09 16:08:54 +053053 {'doctype': 'Item Group', 'item_group_name': 'Consumable', 'is_group': 'No', 'parent_item_group': 'All Item Groups'},
Rushabh Mehta6f9915c2013-01-16 17:48:17 +053054
55 # deduction type
56 {'doctype': 'Deduction Type', 'name': 'Income Tax', 'description': 'Income Tax', 'deduction_name': 'Income Tax'},
57 {'doctype': 'Deduction Type', 'name': 'Professional Tax', 'description': 'Professional Tax', 'deduction_name': 'Professional Tax'},
58 {'doctype': 'Deduction Type', 'name': 'Provident Fund', 'description': 'Provident fund', 'deduction_name': 'Provident Fund'},
59
60 # earning type
61 {'doctype': 'Earning Type', 'name': 'Basic', 'description': 'Basic', 'earning_name': 'Basic', 'taxable': 'Yes'},
62 {'doctype': 'Earning Type', 'name': 'House Rent Allowance', 'description': 'House Rent Allowance', 'earning_name': 'House Rent Allowance', 'taxable': 'No'},
63
64 # expense claim type
65 {'doctype': 'Expense Claim Type', 'name': 'Calls', 'expense_type': 'Calls'},
66 {'doctype': 'Expense Claim Type', 'name': 'Food', 'expense_type': 'Food'},
67 {'doctype': 'Expense Claim Type', 'name': 'Medical', 'expense_type': 'Medical'},
68 {'doctype': 'Expense Claim Type', 'name': 'Others', 'expense_type': 'Others'},
69 {'doctype': 'Expense Claim Type', 'name': 'Travel', 'expense_type': 'Travel'},
70
71 # leave type
72 {'doctype': 'Leave Type', 'leave_type_name': 'Casual Leave', 'name': 'Casual Leave', 'is_encash': 1, 'is_carry_forward': 1, 'max_days_allowed': '3', },
73 {'doctype': 'Leave Type', 'leave_type_name': 'Compensatory Off', 'name': 'Compensatory Off', 'is_encash': 0, 'is_carry_forward': 0, },
74 {'doctype': 'Leave Type', 'leave_type_name': 'Sick Leave', 'name': 'Sick Leave', 'is_encash': 0, 'is_carry_forward': 0, },
75 {'doctype': 'Leave Type', 'leave_type_name': 'Privilege Leave', 'name': 'Privilege Leave', 'is_encash': 0, 'is_carry_forward': 0, },
76 {'doctype': 'Leave Type', 'leave_type_name': 'Leave Without Pay', 'name': 'Leave Without Pay', 'is_encash': 0, 'is_carry_forward': 0, 'is_lwp':1},
77
78 # territory
79 {'doctype': 'Territory', 'territory_name': 'All Territories', 'is_group': 'Yes', 'name': 'All Territories', 'parent_territory': ''},
Rushabh Mehta6f9915c2013-01-16 17:48:17 +053080
81 # customer group
82 {'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 +053083 {'doctype': 'Customer Group', 'customer_group_name': 'Individual', 'is_group': 'No', 'parent_customer_group': 'All Customer Groups'},
84 {'doctype': 'Customer Group', 'customer_group_name': 'Commercial', 'is_group': 'No', 'parent_customer_group': 'All Customer Groups'},
85 {'doctype': 'Customer Group', 'customer_group_name': 'Non Profit', 'is_group': 'No', 'parent_customer_group': 'All Customer Groups'},
86 {'doctype': 'Customer Group', 'customer_group_name': 'Government', 'is_group': 'No', 'parent_customer_group': 'All Customer Groups'},
Rushabh Mehta6f9915c2013-01-16 17:48:17 +053087
88 # supplier type
Rushabh Mehtaad714732013-07-10 18:59:55 +053089 {'doctype': 'Supplier Type', 'supplier_type': 'Services'},
90 {'doctype': 'Supplier Type', 'supplier_type': 'Local'},
91 {'doctype': 'Supplier Type', 'supplier_type': 'Raw Material'},
92 {'doctype': 'Supplier Type', 'supplier_type': 'Electrical'},
93 {'doctype': 'Supplier Type', 'supplier_type': 'Hardware'},
94 {'doctype': 'Supplier Type', 'supplier_type': 'Pharmaceutical'},
95 {'doctype': 'Supplier Type', 'supplier_type': 'Distributor'},
Rushabh Mehta6f9915c2013-01-16 17:48:17 +053096
97 # Sales Person
Rushabh Mehtaad714732013-07-10 18:59:55 +053098 {'doctype': 'Sales Person', 'sales_person_name': 'Sales Team', 'is_group': "Yes", "parent_sales_person": ""},
Rushabh Mehta6f9915c2013-01-16 17:48:17 +053099
100 # UOM
Rushabh Mehta4dca4012013-07-25 17:45:59 +0530101 {'uom_name': 'Unit', 'doctype': 'UOM', 'name': 'Unit', "must_be_whole_number": 1},
102 {'uom_name': 'Box', 'doctype': 'UOM', 'name': 'Box', "must_be_whole_number": 1},
Rushabh Mehta6f9915c2013-01-16 17:48:17 +0530103 {'uom_name': 'Kg', 'doctype': 'UOM', 'name': 'Kg'},
Rushabh Mehta4dca4012013-07-25 17:45:59 +0530104 {'uom_name': 'Nos', 'doctype': 'UOM', 'name': 'Nos', "must_be_whole_number": 1},
105 {'uom_name': 'Pair', 'doctype': 'UOM', 'name': 'Pair', "must_be_whole_number": 1},
106 {'uom_name': 'Set', 'doctype': 'UOM', 'name': 'Set', "must_be_whole_number": 1},
107 {'uom_name': 'Hour', 'doctype': 'UOM', 'name': 'Hour'},
Rushabh Mehtadb7139a2013-01-17 18:22:22 +0530108 {'uom_name': 'Minute', 'doctype': 'UOM', 'name': 'Minute'},
Rushabh Mehtad8de9212014-03-06 15:40:22 +0530109
Rushabh Mehta6f9915c2013-01-16 17:48:17 +0530110 ]
111
Rushabh Mehta793ba6b2014-02-14 15:47:51 +0530112 from frappe.modules import scrub
Rushabh Mehta6f9915c2013-01-16 17:48:17 +0530113 for r in records:
Rushabh Mehta793ba6b2014-02-14 15:47:51 +0530114 bean = frappe.bean(r)
Rushabh Mehtae41bceb2013-07-10 20:42:44 +0530115
116 # ignore mandatory for root
Anand Doshif78d1ae2014-03-28 13:55:00 +0530117 parent_link_field = ("parent_" + scrub(bean.doctype))
118 if parent_link_field in bean.fields and not bean.get(parent_link_field):
Rushabh Mehtae41bceb2013-07-10 20:42:44 +0530119 bean.ignore_mandatory = True
120
Rushabh Mehta1f847992013-12-12 19:12:19 +0530121 bean.insert()
122
123def feature_setup():
124 """save global defaults and features setup"""
Rushabh Mehta793ba6b2014-02-14 15:47:51 +0530125 bean = frappe.bean("Features Setup", "Features Setup")
Rushabh Mehta1f847992013-12-12 19:12:19 +0530126 bean.ignore_permissions = True
127
128 # store value as 1 for all these fields
129 flds = ['fs_item_serial_nos', 'fs_item_batch_nos', 'fs_brands', 'fs_item_barcode',
130 'fs_item_advanced', 'fs_packing_details', 'fs_item_group_in_details',
131 'fs_exports', 'fs_imports', 'fs_discounts', 'fs_purchase_discounts',
132 'fs_after_sales_installations', 'fs_projects', 'fs_sales_extras',
133 'fs_recurring_invoice', 'fs_pos', 'fs_manufacturing', 'fs_quality',
134 'fs_page_break', 'fs_more_info', 'fs_pos_view'
135 ]
Anand Doshif78d1ae2014-03-28 13:55:00 +0530136 bean.update(dict(zip(flds, [1]*len(flds))))
Pratik Vyas28da7522014-02-19 20:53:45 +0530137 bean.save()
138
139def set_single_defaults():
Anand Doshieb7fea62014-03-19 17:10:01 +0530140 for dt in frappe.db.sql_list("""select name from `tabDocType` where issingle=1"""):
141 default_values = frappe.db.sql("""select fieldname, `default` from `tabDocField`
142 where parent=%s""", dt, as_dict=True)
143 if default_values:
144 try:
145 b = frappe.bean(dt, dt)
146 for fieldname, value in default_values:
Anand Doshif78d1ae2014-03-28 13:55:00 +0530147 b.set(fieldname, value)
Anand Doshieb7fea62014-03-19 17:10:01 +0530148 b.save()
149 except frappe.MandatoryError:
150 pass
151
Anand Doshie9baaa62014-02-26 12:35:33 +0530152 frappe.db.set_default("date_format", "dd-mm-yyyy")