Anand Doshi | 885e074 | 2015-03-03 14:55:30 +0530 | [diff] [blame] | 1 | # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors |
Rushabh Mehta | e67d1fb | 2013-08-05 14:59:54 +0530 | [diff] [blame] | 2 | # License: GNU General Public License v3. See license.txt |
| 3 | |
Aditya Hase | 6ccb656 | 2017-08-28 18:17:36 +0530 | [diff] [blame] | 4 | from __future__ import print_function, unicode_literals |
Rushabh Mehta | 6f9915c | 2013-01-16 17:48:17 +0530 | [diff] [blame] | 5 | |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 6 | import frappe |
tundebabzy | cad22db | 2018-02-22 06:38:36 +0100 | [diff] [blame] | 7 | from erpnext.accounts.doctype.cash_flow_mapper.default_cash_flow_mapper import DEFAULT_MAPPERS |
Suraj Shetty | 00cced1 | 2018-05-03 19:06:32 +0530 | [diff] [blame] | 8 | from .default_success_action import get_default_success_action |
Rushabh Mehta | d42167e | 2016-05-11 16:47:14 +0530 | [diff] [blame] | 9 | from frappe import _ |
Nabin Hait | 45dce89 | 2017-09-14 15:17:38 +0530 | [diff] [blame] | 10 | from frappe.desk.page.setup_wizard.setup_wizard import add_all_roles_to |
| 11 | from frappe.custom.doctype.custom_field.custom_field import create_custom_field |
Suraj Shetty | 627a3dc | 2019-09-17 15:54:41 +0530 | [diff] [blame] | 12 | from erpnext.setup.default_energy_point_rules import get_default_energy_point_rules |
Rushabh Mehta | 6f9915c | 2013-01-16 17:48:17 +0530 | [diff] [blame] | 13 | |
Anand Doshi | 56198f4 | 2014-06-26 12:47:45 +0530 | [diff] [blame] | 14 | default_mail_footer = """<div style="padding: 7px; text-align: right; color: #888"><small>Sent via |
Anand Doshi | 7f41ff2 | 2014-06-26 12:02:55 +0530 | [diff] [blame] | 15 | <a style="color: #888" href="http://erpnext.org">ERPNext</a></div>""" |
| 16 | |
tundebabzy | cad22db | 2018-02-22 06:38:36 +0100 | [diff] [blame] | 17 | |
Rushabh Mehta | 1f84799 | 2013-12-12 19:12:19 +0530 | [diff] [blame] | 18 | def after_install(): |
Rushabh Mehta | 40b2b03 | 2014-04-21 13:43:11 +0530 | [diff] [blame] | 19 | frappe.get_doc({'doctype': "Role", "role_name": "Analytics"}).insert() |
Rushabh Mehta | 33003c6 | 2014-04-30 11:16:02 +0530 | [diff] [blame] | 20 | set_single_defaults() |
Rushabh Mehta | d42167e | 2016-05-11 16:47:14 +0530 | [diff] [blame] | 21 | create_compact_item_print_custom_field() |
Nabin Hait | 45dce89 | 2017-09-14 15:17:38 +0530 | [diff] [blame] | 22 | create_print_zero_amount_taxes_custom_field() |
Rushabh Mehta | db7139a | 2013-01-17 18:22:22 +0530 | [diff] [blame] | 23 | add_all_roles_to("Administrator") |
tundebabzy | cad22db | 2018-02-22 06:38:36 +0100 | [diff] [blame] | 24 | create_default_cash_flow_mapper_templates() |
Suraj Shetty | 00cced1 | 2018-05-03 19:06:32 +0530 | [diff] [blame] | 25 | create_default_success_action() |
Suraj Shetty | 627a3dc | 2019-09-17 15:54:41 +0530 | [diff] [blame] | 26 | create_default_energy_point_rules() |
Rucha Mahabal | 4865eab | 2019-07-24 13:37:54 +0530 | [diff] [blame] | 27 | add_company_to_session_defaults() |
Anand Doshi | e9baaa6 | 2014-02-26 12:35:33 +0530 | [diff] [blame] | 28 | frappe.db.commit() |
Rushabh Mehta | db7139a | 2013-01-17 18:22:22 +0530 | [diff] [blame] | 29 | |
tundebabzy | cad22db | 2018-02-22 06:38:36 +0100 | [diff] [blame] | 30 | |
Rushabh Mehta | d55bdcf | 2015-12-31 11:12:48 +0530 | [diff] [blame] | 31 | def check_setup_wizard_not_completed(): |
| 32 | if frappe.db.get_default('desktop:home_page') == 'desktop': |
Aditya Hase | 6ccb656 | 2017-08-28 18:17:36 +0530 | [diff] [blame] | 33 | print() |
| 34 | print("ERPNext can only be installed on a fresh site where the setup wizard is not completed") |
| 35 | print("You can reinstall this site (after saving your data) using: bench --site [sitename] reinstall") |
| 36 | print() |
Rushabh Mehta | d55bdcf | 2015-12-31 11:12:48 +0530 | [diff] [blame] | 37 | return False |
| 38 | |
tundebabzy | cad22db | 2018-02-22 06:38:36 +0100 | [diff] [blame] | 39 | |
Pratik Vyas | 28da752 | 2014-02-19 20:53:45 +0530 | [diff] [blame] | 40 | def set_single_defaults(): |
Rushabh Mehta | b62ed7a | 2016-10-13 11:00:00 +0530 | [diff] [blame] | 41 | for dt in ('Accounts Settings', 'Print Settings', 'HR Settings', 'Buying Settings', |
Suraj Shetty | d3069fe | 2018-02-21 15:15:43 +0530 | [diff] [blame] | 42 | 'Selling Settings', 'Stock Settings'): |
Anand Doshi | eb7fea6 | 2014-03-19 17:10:01 +0530 | [diff] [blame] | 43 | default_values = frappe.db.sql("""select fieldname, `default` from `tabDocField` |
Rushabh Mehta | f14b809 | 2014-04-03 14:30:42 +0530 | [diff] [blame] | 44 | where parent=%s""", dt) |
Anand Doshi | eb7fea6 | 2014-03-19 17:10:01 +0530 | [diff] [blame] | 45 | if default_values: |
| 46 | try: |
Rushabh Mehta | b385ecf | 2014-03-28 16:44:37 +0530 | [diff] [blame] | 47 | b = frappe.get_doc(dt, dt) |
Anand Doshi | eb7fea6 | 2014-03-19 17:10:01 +0530 | [diff] [blame] | 48 | for fieldname, value in default_values: |
Anand Doshi | f78d1ae | 2014-03-28 13:55:00 +0530 | [diff] [blame] | 49 | b.set(fieldname, value) |
Anand Doshi | eb7fea6 | 2014-03-19 17:10:01 +0530 | [diff] [blame] | 50 | b.save() |
| 51 | except frappe.MandatoryError: |
| 52 | pass |
Rushabh Mehta | b62ed7a | 2016-10-13 11:00:00 +0530 | [diff] [blame] | 53 | except frappe.ValidationError: |
| 54 | pass |
Anand Doshi | eb7fea6 | 2014-03-19 17:10:01 +0530 | [diff] [blame] | 55 | |
Anand Doshi | e9baaa6 | 2014-02-26 12:35:33 +0530 | [diff] [blame] | 56 | frappe.db.set_default("date_format", "dd-mm-yyyy") |
Rushabh Mehta | d42167e | 2016-05-11 16:47:14 +0530 | [diff] [blame] | 57 | |
tundebabzy | cad22db | 2018-02-22 06:38:36 +0100 | [diff] [blame] | 58 | |
Rushabh Mehta | d42167e | 2016-05-11 16:47:14 +0530 | [diff] [blame] | 59 | def create_compact_item_print_custom_field(): |
Rushabh Mehta | d42167e | 2016-05-11 16:47:14 +0530 | [diff] [blame] | 60 | create_custom_field('Print Settings', { |
| 61 | 'label': _('Compact Item Print'), |
| 62 | 'fieldname': 'compact_item_print', |
| 63 | 'fieldtype': 'Check', |
| 64 | 'default': 1, |
| 65 | 'insert_after': 'with_letterhead' |
Nabin Hait | 45dce89 | 2017-09-14 15:17:38 +0530 | [diff] [blame] | 66 | }) |
| 67 | |
tundebabzy | cad22db | 2018-02-22 06:38:36 +0100 | [diff] [blame] | 68 | |
Nabin Hait | 45dce89 | 2017-09-14 15:17:38 +0530 | [diff] [blame] | 69 | def create_print_zero_amount_taxes_custom_field(): |
| 70 | create_custom_field('Print Settings', { |
| 71 | 'label': _('Print taxes with zero amount'), |
| 72 | 'fieldname': 'print_taxes_with_zero_amount', |
| 73 | 'fieldtype': 'Check', |
| 74 | 'default': 0, |
| 75 | 'insert_after': 'allow_print_for_cancelled' |
tundebabzy | cad22db | 2018-02-22 06:38:36 +0100 | [diff] [blame] | 76 | }) |
| 77 | |
| 78 | |
| 79 | def create_default_cash_flow_mapper_templates(): |
Suraj Shetty | 00cced1 | 2018-05-03 19:06:32 +0530 | [diff] [blame] | 80 | for mapper in DEFAULT_MAPPERS: |
tundebabzy | cad22db | 2018-02-22 06:38:36 +0100 | [diff] [blame] | 81 | if not frappe.db.exists('Cash Flow Mapper', mapper['section_name']): |
| 82 | doc = frappe.get_doc(mapper) |
| 83 | doc.insert(ignore_permissions=True) |
Suraj Shetty | 00cced1 | 2018-05-03 19:06:32 +0530 | [diff] [blame] | 84 | |
| 85 | def create_default_success_action(): |
| 86 | for success_action in get_default_success_action(): |
| 87 | if not frappe.db.exists('Success Action', success_action.get("ref_doctype")): |
| 88 | doc = frappe.get_doc(success_action) |
| 89 | doc.insert(ignore_permissions=True) |
Rucha Mahabal | 4865eab | 2019-07-24 13:37:54 +0530 | [diff] [blame] | 90 | |
Suraj Shetty | 627a3dc | 2019-09-17 15:54:41 +0530 | [diff] [blame] | 91 | def create_default_energy_point_rules(): |
| 92 | |
| 93 | for rule in get_default_energy_point_rules(): |
| 94 | # check if any rule for ref. doctype exists |
| 95 | rule_exists = frappe.db.exists('Energy Point Rule', { |
| 96 | 'reference_doctype': rule.get('reference_doctype') |
| 97 | }) |
| 98 | if rule_exists: continue |
| 99 | doc = frappe.get_doc(rule) |
| 100 | doc.insert(ignore_permissions=True) |
| 101 | |
Rucha Mahabal | 4865eab | 2019-07-24 13:37:54 +0530 | [diff] [blame] | 102 | def add_company_to_session_defaults(): |
| 103 | settings = frappe.get_single("Session Default Settings") |
| 104 | settings.append("session_defaults", { |
| 105 | "ref_doctype": "Company" |
| 106 | }) |
| 107 | settings.save() |