blob: 0bb480bd4b67b9633f507313a7247442dccf8547 [file] [log] [blame]
Anand Doshi885e0742015-03-03 14:55:30 +05301# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
Rushabh Mehtae67d1fb2013-08-05 14:59:54 +05302# License: GNU General Public License v3. See license.txt
3
Aditya Hase6ccb6562017-08-28 18:17:36 +05304from __future__ import print_function, unicode_literals
Rushabh Mehta6f9915c2013-01-16 17:48:17 +05305
Rushabh Mehta793ba6b2014-02-14 15:47:51 +05306import frappe
tundebabzycad22db2018-02-22 06:38:36 +01007from erpnext.accounts.doctype.cash_flow_mapper.default_cash_flow_mapper import DEFAULT_MAPPERS
Suraj Shetty00cced12018-05-03 19:06:32 +05308from .default_success_action import get_default_success_action
Rushabh Mehtad42167e2016-05-11 16:47:14 +05309from frappe import _
Saurabh58d05ac2020-08-10 19:36:45 +053010from frappe.utils import cint
Nabin Hait45dce892017-09-14 15:17:38 +053011from frappe.desk.page.setup_wizard.setup_wizard import add_all_roles_to
12from frappe.custom.doctype.custom_field.custom_field import create_custom_field
Suraj Shetty627a3dc2019-09-17 15:54:41 +053013from erpnext.setup.default_energy_point_rules import get_default_energy_point_rules
Rushabh Mehta6f9915c2013-01-16 17:48:17 +053014
Anand Doshi56198f42014-06-26 12:47:45 +053015default_mail_footer = """<div style="padding: 7px; text-align: right; color: #888"><small>Sent via
Anand Doshi7f41ff22014-06-26 12:02:55 +053016 <a style="color: #888" href="http://erpnext.org">ERPNext</a></div>"""
17
tundebabzycad22db2018-02-22 06:38:36 +010018
Rushabh Mehta1f847992013-12-12 19:12:19 +053019def after_install():
Rushabh Mehta40b2b032014-04-21 13:43:11 +053020 frappe.get_doc({'doctype': "Role", "role_name": "Analytics"}).insert()
Rushabh Mehta33003c62014-04-30 11:16:02 +053021 set_single_defaults()
Rushabh Mehtad42167e2016-05-11 16:47:14 +053022 create_compact_item_print_custom_field()
Frappe ERPnextf28bef82020-09-02 21:42:52 +020023 create_print_uom_after_qty_custom_field()
Nabin Hait45dce892017-09-14 15:17:38 +053024 create_print_zero_amount_taxes_custom_field()
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053025 add_all_roles_to("Administrator")
tundebabzycad22db2018-02-22 06:38:36 +010026 create_default_cash_flow_mapper_templates()
Suraj Shetty00cced12018-05-03 19:06:32 +053027 create_default_success_action()
Suraj Shetty627a3dc2019-09-17 15:54:41 +053028 create_default_energy_point_rules()
Rucha Mahabal4865eab2019-07-24 13:37:54 +053029 add_company_to_session_defaults()
Deepesh Garga306af82020-08-06 20:52:02 +053030 add_standard_navbar_items()
Shivam Mishra1323a9a2020-09-30 16:33:14 +053031 add_app_name()
Anand Doshie9baaa62014-02-26 12:35:33 +053032 frappe.db.commit()
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053033
tundebabzycad22db2018-02-22 06:38:36 +010034
Rushabh Mehtad55bdcf2015-12-31 11:12:48 +053035def check_setup_wizard_not_completed():
Saurabh58d05ac2020-08-10 19:36:45 +053036 if cint(frappe.db.get_single_value('System Settings', 'setup_complete') or 0):
Deepesh Garga306af82020-08-06 20:52:02 +053037 message = """ERPNext can only be installed on a fresh site where the setup wizard is not completed.
Faris Ansarif3a6e302020-07-08 10:45:55 +053038You can reinstall this site (after saving your data) using: bench --site [sitename] reinstall"""
Faris Ansari70aa3c02020-07-10 16:13:21 +053039 frappe.throw(message)
Rushabh Mehtad55bdcf2015-12-31 11:12:48 +053040
tundebabzycad22db2018-02-22 06:38:36 +010041
Pratik Vyas28da7522014-02-19 20:53:45 +053042def set_single_defaults():
Rushabh Mehtab62ed7a2016-10-13 11:00:00 +053043 for dt in ('Accounts Settings', 'Print Settings', 'HR Settings', 'Buying Settings',
Suraj Shettyd3069fe2018-02-21 15:15:43 +053044 'Selling Settings', 'Stock Settings'):
Anand Doshieb7fea62014-03-19 17:10:01 +053045 default_values = frappe.db.sql("""select fieldname, `default` from `tabDocField`
Rushabh Mehtaf14b8092014-04-03 14:30:42 +053046 where parent=%s""", dt)
Anand Doshieb7fea62014-03-19 17:10:01 +053047 if default_values:
48 try:
Rushabh Mehtab385ecf2014-03-28 16:44:37 +053049 b = frappe.get_doc(dt, dt)
Anand Doshieb7fea62014-03-19 17:10:01 +053050 for fieldname, value in default_values:
Anand Doshif78d1ae2014-03-28 13:55:00 +053051 b.set(fieldname, value)
Anand Doshieb7fea62014-03-19 17:10:01 +053052 b.save()
53 except frappe.MandatoryError:
54 pass
Rushabh Mehtab62ed7a2016-10-13 11:00:00 +053055 except frappe.ValidationError:
56 pass
Anand Doshieb7fea62014-03-19 17:10:01 +053057
Anand Doshie9baaa62014-02-26 12:35:33 +053058 frappe.db.set_default("date_format", "dd-mm-yyyy")
Rushabh Mehtad42167e2016-05-11 16:47:14 +053059
tundebabzycad22db2018-02-22 06:38:36 +010060
Rushabh Mehtad42167e2016-05-11 16:47:14 +053061def create_compact_item_print_custom_field():
Rushabh Mehtad42167e2016-05-11 16:47:14 +053062 create_custom_field('Print Settings', {
63 'label': _('Compact Item Print'),
64 'fieldname': 'compact_item_print',
65 'fieldtype': 'Check',
66 'default': 1,
67 'insert_after': 'with_letterhead'
Nabin Hait45dce892017-09-14 15:17:38 +053068 })
69
tundebabzycad22db2018-02-22 06:38:36 +010070
Frappe ERPnextf28bef82020-09-02 21:42:52 +020071def create_print_uom_after_qty_custom_field():
72 create_custom_field('Print Settings', {
73 'label': _('Print UOM after Quantity'),
74 'fieldname': 'print_uom_after_quantity',
75 'fieldtype': 'Check',
76 'default': 0,
77 'insert_after': 'compact_item_print'
78 })
79
80
Nabin Hait45dce892017-09-14 15:17:38 +053081def create_print_zero_amount_taxes_custom_field():
82 create_custom_field('Print Settings', {
83 'label': _('Print taxes with zero amount'),
84 'fieldname': 'print_taxes_with_zero_amount',
85 'fieldtype': 'Check',
86 'default': 0,
87 'insert_after': 'allow_print_for_cancelled'
tundebabzycad22db2018-02-22 06:38:36 +010088 })
89
90
91def create_default_cash_flow_mapper_templates():
Suraj Shetty00cced12018-05-03 19:06:32 +053092 for mapper in DEFAULT_MAPPERS:
tundebabzycad22db2018-02-22 06:38:36 +010093 if not frappe.db.exists('Cash Flow Mapper', mapper['section_name']):
94 doc = frappe.get_doc(mapper)
95 doc.insert(ignore_permissions=True)
Suraj Shetty00cced12018-05-03 19:06:32 +053096
97def create_default_success_action():
98 for success_action in get_default_success_action():
99 if not frappe.db.exists('Success Action', success_action.get("ref_doctype")):
100 doc = frappe.get_doc(success_action)
101 doc.insert(ignore_permissions=True)
Rucha Mahabal4865eab2019-07-24 13:37:54 +0530102
Suraj Shetty627a3dc2019-09-17 15:54:41 +0530103def create_default_energy_point_rules():
104
105 for rule in get_default_energy_point_rules():
106 # check if any rule for ref. doctype exists
107 rule_exists = frappe.db.exists('Energy Point Rule', {
108 'reference_doctype': rule.get('reference_doctype')
109 })
110 if rule_exists: continue
111 doc = frappe.get_doc(rule)
112 doc.insert(ignore_permissions=True)
113
Rucha Mahabal4865eab2019-07-24 13:37:54 +0530114def add_company_to_session_defaults():
115 settings = frappe.get_single("Session Default Settings")
116 settings.append("session_defaults", {
117 "ref_doctype": "Company"
118 })
119 settings.save()
Deepesh Garga306af82020-08-06 20:52:02 +0530120
121def add_standard_navbar_items():
122 navbar_settings = frappe.get_single("Navbar Settings")
123
124 erpnext_navbar_items = [
125 {
126 'item_label': 'Documentation',
127 'item_type': 'Route',
128 'route': 'https://erpnext.com/docs/user/manual',
129 'is_standard': 1
130 },
131 {
132 'item_label': 'User Forum',
133 'item_type': 'Route',
134 'route': 'https://discuss.erpnext.com',
135 'is_standard': 1
136 },
137 {
138 'item_label': 'Report an Issue',
139 'item_type': 'Route',
140 'route': 'https://github.com/frappe/erpnext/issues',
141 'is_standard': 1
142 }
143 ]
144
145 current_nabvar_items = navbar_settings.help_dropdown
146 navbar_settings.set('help_dropdown', [])
147
148 for item in erpnext_navbar_items:
149 navbar_settings.append('help_dropdown', item)
150
151 for item in current_nabvar_items:
152 navbar_settings.append('help_dropdown', {
153 'item_label': item.item_label,
154 'item_type': item.item_type,
155 'route': item.route,
156 'action': item.action,
157 'is_standard': item.is_standard,
158 'hidden': item.hidden
159 })
160
161 navbar_settings.save()
Shivam Mishra1323a9a2020-09-30 16:33:14 +0530162
163def add_app_name():
164 settings = frappe.get_doc("System Settings")
165 settings.app_name = _("ERPNext")