blob: 5e85f7d52650a786c102b786b68bb7b3511f15d2 [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 _
Nabin Hait45dce892017-09-14 15:17:38 +053010from frappe.desk.page.setup_wizard.setup_wizard import add_all_roles_to
11from frappe.custom.doctype.custom_field.custom_field import create_custom_field
Rushabh Mehta6f9915c2013-01-16 17:48:17 +053012
Anand Doshi56198f42014-06-26 12:47:45 +053013default_mail_footer = """<div style="padding: 7px; text-align: right; color: #888"><small>Sent via
Anand Doshi7f41ff22014-06-26 12:02:55 +053014 <a style="color: #888" href="http://erpnext.org">ERPNext</a></div>"""
15
tundebabzycad22db2018-02-22 06:38:36 +010016
Rushabh Mehta1f847992013-12-12 19:12:19 +053017def after_install():
Rushabh Mehta40b2b032014-04-21 13:43:11 +053018 frappe.get_doc({'doctype': "Role", "role_name": "Analytics"}).insert()
Rushabh Mehta33003c62014-04-30 11:16:02 +053019 set_single_defaults()
Rushabh Mehtad42167e2016-05-11 16:47:14 +053020 create_compact_item_print_custom_field()
Nabin Hait45dce892017-09-14 15:17:38 +053021 create_print_zero_amount_taxes_custom_field()
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053022 add_all_roles_to("Administrator")
tundebabzycad22db2018-02-22 06:38:36 +010023 create_default_cash_flow_mapper_templates()
Suraj Shetty00cced12018-05-03 19:06:32 +053024 create_default_success_action()
Rucha Mahabal4865eab2019-07-24 13:37:54 +053025 add_company_to_session_defaults()
Anand Doshie9baaa62014-02-26 12:35:33 +053026 frappe.db.commit()
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053027
tundebabzycad22db2018-02-22 06:38:36 +010028
Rushabh Mehtad55bdcf2015-12-31 11:12:48 +053029def check_setup_wizard_not_completed():
30 if frappe.db.get_default('desktop:home_page') == 'desktop':
Aditya Hase6ccb6562017-08-28 18:17:36 +053031 print()
32 print("ERPNext can only be installed on a fresh site where the setup wizard is not completed")
33 print("You can reinstall this site (after saving your data) using: bench --site [sitename] reinstall")
34 print()
Rushabh Mehtad55bdcf2015-12-31 11:12:48 +053035 return False
36
tundebabzycad22db2018-02-22 06:38:36 +010037
Pratik Vyas28da7522014-02-19 20:53:45 +053038def set_single_defaults():
Rushabh Mehtab62ed7a2016-10-13 11:00:00 +053039 for dt in ('Accounts Settings', 'Print Settings', 'HR Settings', 'Buying Settings',
Suraj Shettyd3069fe2018-02-21 15:15:43 +053040 'Selling Settings', 'Stock Settings'):
Anand Doshieb7fea62014-03-19 17:10:01 +053041 default_values = frappe.db.sql("""select fieldname, `default` from `tabDocField`
Rushabh Mehtaf14b8092014-04-03 14:30:42 +053042 where parent=%s""", dt)
Anand Doshieb7fea62014-03-19 17:10:01 +053043 if default_values:
44 try:
Rushabh Mehtab385ecf2014-03-28 16:44:37 +053045 b = frappe.get_doc(dt, dt)
Anand Doshieb7fea62014-03-19 17:10:01 +053046 for fieldname, value in default_values:
Anand Doshif78d1ae2014-03-28 13:55:00 +053047 b.set(fieldname, value)
Anand Doshieb7fea62014-03-19 17:10:01 +053048 b.save()
49 except frappe.MandatoryError:
50 pass
Rushabh Mehtab62ed7a2016-10-13 11:00:00 +053051 except frappe.ValidationError:
52 pass
Anand Doshieb7fea62014-03-19 17:10:01 +053053
Anand Doshie9baaa62014-02-26 12:35:33 +053054 frappe.db.set_default("date_format", "dd-mm-yyyy")
Rushabh Mehtad42167e2016-05-11 16:47:14 +053055
tundebabzycad22db2018-02-22 06:38:36 +010056
Rushabh Mehtad42167e2016-05-11 16:47:14 +053057def create_compact_item_print_custom_field():
Rushabh Mehtad42167e2016-05-11 16:47:14 +053058 create_custom_field('Print Settings', {
59 'label': _('Compact Item Print'),
60 'fieldname': 'compact_item_print',
61 'fieldtype': 'Check',
62 'default': 1,
63 'insert_after': 'with_letterhead'
Nabin Hait45dce892017-09-14 15:17:38 +053064 })
65
tundebabzycad22db2018-02-22 06:38:36 +010066
Nabin Hait45dce892017-09-14 15:17:38 +053067def create_print_zero_amount_taxes_custom_field():
68 create_custom_field('Print Settings', {
69 'label': _('Print taxes with zero amount'),
70 'fieldname': 'print_taxes_with_zero_amount',
71 'fieldtype': 'Check',
72 'default': 0,
73 'insert_after': 'allow_print_for_cancelled'
tundebabzycad22db2018-02-22 06:38:36 +010074 })
75
76
77def create_default_cash_flow_mapper_templates():
Suraj Shetty00cced12018-05-03 19:06:32 +053078 for mapper in DEFAULT_MAPPERS:
tundebabzycad22db2018-02-22 06:38:36 +010079 if not frappe.db.exists('Cash Flow Mapper', mapper['section_name']):
80 doc = frappe.get_doc(mapper)
81 doc.insert(ignore_permissions=True)
Suraj Shetty00cced12018-05-03 19:06:32 +053082
83def create_default_success_action():
84 for success_action in get_default_success_action():
85 if not frappe.db.exists('Success Action', success_action.get("ref_doctype")):
86 doc = frappe.get_doc(success_action)
87 doc.insert(ignore_permissions=True)
Rucha Mahabal4865eab2019-07-24 13:37:54 +053088
89def add_company_to_session_defaults():
90 settings = frappe.get_single("Session Default Settings")
91 settings.append("session_defaults", {
92 "ref_doctype": "Company"
93 })
94 settings.save()