blob: eb851abe4a856c03cbd6c6e90741190b75a47cb6 [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()
Anand Doshie9baaa62014-02-26 12:35:33 +053011 frappe.db.set_value('Control Panel', None, 'home_page', 'setup-wizard')
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053012 feature_setup()
Rushabh Mehta1f847992013-12-12 19:12:19 +053013 from erpnext.setup.page.setup_wizard.setup_wizard import add_all_roles_to
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053014 add_all_roles_to("Administrator")
Pratik Vyas28da7522014-02-19 20:53:45 +053015 set_single_defaults()
Anand Doshie9baaa62014-02-26 12:35:33 +053016 frappe.db.commit()
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053017
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053018def import_country_and_currency():
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053019 from frappe.country_info import get_all
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053020 data = get_all()
Anand Doshi44077d22013-01-27 17:02:49 +053021
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053022 for name in data:
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053023 country = frappe._dict(data[name])
24 frappe.doc({
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053025 "doctype": "Country",
26 "country_name": name,
27 "date_format": country.date_format or "dd-mm-yyyy",
28 "time_zones": "\n".join(country.timezones or [])
29 }).insert()
30
Anand Doshie9baaa62014-02-26 12:35:33 +053031 if country.currency and not frappe.db.exists("Currency", country.currency):
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053032 frappe.doc({
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053033 "doctype": "Currency",
34 "currency_name": country.currency,
35 "fraction": country.currency_fraction,
36 "symbol": country.currency_symbol,
Rushabh Mehtaf5b04cf2013-01-21 10:14:10 +053037 "fraction_units": country.currency_fraction_units,
38 "number_format": country.number_format
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053039 }).insert()
40
41def import_defaults():
Rushabh Mehta6f9915c2013-01-16 17:48:17 +053042 records = [
43 # item group
Rushabh Mehtaad714732013-07-10 18:59:55 +053044 {'doctype': 'Item Group', 'item_group_name': 'All Item Groups', 'is_group': 'Yes', 'parent_item_group': ''},
45 {'doctype': 'Item Group', 'item_group_name': 'Products', 'is_group': 'No', 'parent_item_group': 'All Item Groups'},
46 {'doctype': 'Item Group', 'item_group_name': 'Raw Material', 'is_group': 'No', 'parent_item_group': 'All Item Groups'},
47 {'doctype': 'Item Group', 'item_group_name': 'Services', 'is_group': 'No', 'parent_item_group': 'All Item Groups'},
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +053048 {'doctype': 'Item Group', 'item_group_name': 'Sub Assemblies', 'is_group': 'No', 'parent_item_group': 'All Item Groups'},
Rushabh Mehtaddca90e2013-10-09 16:08:54 +053049 {'doctype': 'Item Group', 'item_group_name': 'Consumable', 'is_group': 'No', 'parent_item_group': 'All Item Groups'},
Rushabh Mehta6f9915c2013-01-16 17:48:17 +053050
51 # deduction type
52 {'doctype': 'Deduction Type', 'name': 'Income Tax', 'description': 'Income Tax', 'deduction_name': 'Income Tax'},
53 {'doctype': 'Deduction Type', 'name': 'Professional Tax', 'description': 'Professional Tax', 'deduction_name': 'Professional Tax'},
54 {'doctype': 'Deduction Type', 'name': 'Provident Fund', 'description': 'Provident fund', 'deduction_name': 'Provident Fund'},
55
56 # earning type
57 {'doctype': 'Earning Type', 'name': 'Basic', 'description': 'Basic', 'earning_name': 'Basic', 'taxable': 'Yes'},
58 {'doctype': 'Earning Type', 'name': 'House Rent Allowance', 'description': 'House Rent Allowance', 'earning_name': 'House Rent Allowance', 'taxable': 'No'},
59
60 # expense claim type
61 {'doctype': 'Expense Claim Type', 'name': 'Calls', 'expense_type': 'Calls'},
62 {'doctype': 'Expense Claim Type', 'name': 'Food', 'expense_type': 'Food'},
63 {'doctype': 'Expense Claim Type', 'name': 'Medical', 'expense_type': 'Medical'},
64 {'doctype': 'Expense Claim Type', 'name': 'Others', 'expense_type': 'Others'},
65 {'doctype': 'Expense Claim Type', 'name': 'Travel', 'expense_type': 'Travel'},
66
67 # leave type
68 {'doctype': 'Leave Type', 'leave_type_name': 'Casual Leave', 'name': 'Casual Leave', 'is_encash': 1, 'is_carry_forward': 1, 'max_days_allowed': '3', },
69 {'doctype': 'Leave Type', 'leave_type_name': 'Compensatory Off', 'name': 'Compensatory Off', 'is_encash': 0, 'is_carry_forward': 0, },
70 {'doctype': 'Leave Type', 'leave_type_name': 'Sick Leave', 'name': 'Sick Leave', 'is_encash': 0, 'is_carry_forward': 0, },
71 {'doctype': 'Leave Type', 'leave_type_name': 'Privilege Leave', 'name': 'Privilege Leave', 'is_encash': 0, 'is_carry_forward': 0, },
72 {'doctype': 'Leave Type', 'leave_type_name': 'Leave Without Pay', 'name': 'Leave Without Pay', 'is_encash': 0, 'is_carry_forward': 0, 'is_lwp':1},
73
74 # territory
75 {'doctype': 'Territory', 'territory_name': 'All Territories', 'is_group': 'Yes', 'name': 'All Territories', 'parent_territory': ''},
Rushabh Mehta6f9915c2013-01-16 17:48:17 +053076
77 # customer group
78 {'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 +053079 {'doctype': 'Customer Group', 'customer_group_name': 'Individual', 'is_group': 'No', 'parent_customer_group': 'All Customer Groups'},
80 {'doctype': 'Customer Group', 'customer_group_name': 'Commercial', 'is_group': 'No', 'parent_customer_group': 'All Customer Groups'},
81 {'doctype': 'Customer Group', 'customer_group_name': 'Non Profit', 'is_group': 'No', 'parent_customer_group': 'All Customer Groups'},
82 {'doctype': 'Customer Group', 'customer_group_name': 'Government', 'is_group': 'No', 'parent_customer_group': 'All Customer Groups'},
Rushabh Mehta6f9915c2013-01-16 17:48:17 +053083
84 # supplier type
Rushabh Mehtaad714732013-07-10 18:59:55 +053085 {'doctype': 'Supplier Type', 'supplier_type': 'Services'},
86 {'doctype': 'Supplier Type', 'supplier_type': 'Local'},
87 {'doctype': 'Supplier Type', 'supplier_type': 'Raw Material'},
88 {'doctype': 'Supplier Type', 'supplier_type': 'Electrical'},
89 {'doctype': 'Supplier Type', 'supplier_type': 'Hardware'},
90 {'doctype': 'Supplier Type', 'supplier_type': 'Pharmaceutical'},
91 {'doctype': 'Supplier Type', 'supplier_type': 'Distributor'},
Rushabh Mehta6f9915c2013-01-16 17:48:17 +053092
93 # Sales Person
Rushabh Mehtaad714732013-07-10 18:59:55 +053094 {'doctype': 'Sales Person', 'sales_person_name': 'Sales Team', 'is_group': "Yes", "parent_sales_person": ""},
Rushabh Mehta6f9915c2013-01-16 17:48:17 +053095
96 # UOM
Rushabh Mehta4dca4012013-07-25 17:45:59 +053097 {'uom_name': 'Unit', 'doctype': 'UOM', 'name': 'Unit', "must_be_whole_number": 1},
98 {'uom_name': 'Box', 'doctype': 'UOM', 'name': 'Box', "must_be_whole_number": 1},
Rushabh Mehta6f9915c2013-01-16 17:48:17 +053099 {'uom_name': 'Kg', 'doctype': 'UOM', 'name': 'Kg'},
Rushabh Mehta4dca4012013-07-25 17:45:59 +0530100 {'uom_name': 'Nos', 'doctype': 'UOM', 'name': 'Nos', "must_be_whole_number": 1},
101 {'uom_name': 'Pair', 'doctype': 'UOM', 'name': 'Pair', "must_be_whole_number": 1},
102 {'uom_name': 'Set', 'doctype': 'UOM', 'name': 'Set', "must_be_whole_number": 1},
103 {'uom_name': 'Hour', 'doctype': 'UOM', 'name': 'Hour'},
Rushabh Mehtadb7139a2013-01-17 18:22:22 +0530104 {'uom_name': 'Minute', 'doctype': 'UOM', 'name': 'Minute'},
Rushabh Mehtad8de9212014-03-06 15:40:22 +0530105
Rushabh Mehta6f9915c2013-01-16 17:48:17 +0530106 ]
107
Rushabh Mehta793ba6b2014-02-14 15:47:51 +0530108 from frappe.modules import scrub
Rushabh Mehta6f9915c2013-01-16 17:48:17 +0530109 for r in records:
Rushabh Mehta793ba6b2014-02-14 15:47:51 +0530110 bean = frappe.bean(r)
Rushabh Mehtae41bceb2013-07-10 20:42:44 +0530111
112 # ignore mandatory for root
113 parent_link_field = ("parent_" + scrub(bean.doc.doctype))
114 if parent_link_field in bean.doc.fields and not bean.doc.fields.get(parent_link_field):
115 bean.ignore_mandatory = True
116
Rushabh Mehta1f847992013-12-12 19:12:19 +0530117 bean.insert()
118
119def feature_setup():
120 """save global defaults and features setup"""
Rushabh Mehta793ba6b2014-02-14 15:47:51 +0530121 bean = frappe.bean("Features Setup", "Features Setup")
Rushabh Mehta1f847992013-12-12 19:12:19 +0530122 bean.ignore_permissions = True
123
124 # store value as 1 for all these fields
125 flds = ['fs_item_serial_nos', 'fs_item_batch_nos', 'fs_brands', 'fs_item_barcode',
126 'fs_item_advanced', 'fs_packing_details', 'fs_item_group_in_details',
127 'fs_exports', 'fs_imports', 'fs_discounts', 'fs_purchase_discounts',
128 'fs_after_sales_installations', 'fs_projects', 'fs_sales_extras',
129 'fs_recurring_invoice', 'fs_pos', 'fs_manufacturing', 'fs_quality',
130 'fs_page_break', 'fs_more_info', 'fs_pos_view'
131 ]
132 bean.doc.fields.update(dict(zip(flds, [1]*len(flds))))
Pratik Vyas28da7522014-02-19 20:53:45 +0530133 bean.save()
134
135def set_single_defaults():
Anand Doshieb7fea62014-03-19 17:10:01 +0530136 for dt in frappe.db.sql_list("""select name from `tabDocType` where issingle=1"""):
137 default_values = frappe.db.sql("""select fieldname, `default` from `tabDocField`
138 where parent=%s""", dt, as_dict=True)
139 if default_values:
140 try:
141 b = frappe.bean(dt, dt)
142 for fieldname, value in default_values:
143 b.doc.fields[fieldname] = value
144 b.save()
145 except frappe.MandatoryError:
146 pass
147
Anand Doshie9baaa62014-02-26 12:35:33 +0530148 frappe.db.set_default("date_format", "dd-mm-yyyy")