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 | |
Rushabh Mehta | 6f9915c | 2013-01-16 17:48:17 +0530 | [diff] [blame] | 4 | |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 5 | import frappe |
Rushabh Mehta | d42167e | 2016-05-11 16:47:14 +0530 | [diff] [blame] | 6 | from frappe import _ |
Sagar Vora | aafb735 | 2022-08-18 15:31:20 +0000 | [diff] [blame] | 7 | from frappe.custom.doctype.custom_field.custom_field import create_custom_fields |
Chillar Anand | 915b343 | 2021-09-02 16:44:59 +0530 | [diff] [blame] | 8 | from frappe.desk.page.setup_wizard.setup_wizard import add_all_roles_to |
Chillar Anand | 915b343 | 2021-09-02 16:44:59 +0530 | [diff] [blame] | 9 | from frappe.utils import cint |
Rushabh Mehta | 6f9915c | 2013-01-16 17:48:17 +0530 | [diff] [blame] | 10 | |
Chillar Anand | 915b343 | 2021-09-02 16:44:59 +0530 | [diff] [blame] | 11 | from erpnext.accounts.doctype.cash_flow_mapper.default_cash_flow_mapper import DEFAULT_MAPPERS |
| 12 | from erpnext.setup.default_energy_point_rules import get_default_energy_point_rules |
| 13 | |
| 14 | from .default_success_action import get_default_success_action |
| 15 | |
Anand Doshi | 56198f4 | 2014-06-26 12:47:45 +0530 | [diff] [blame] | 16 | 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] | 17 | <a style="color: #888" href="http://erpnext.org">ERPNext</a></div>""" |
| 18 | |
tundebabzy | cad22db | 2018-02-22 06:38:36 +0100 | [diff] [blame] | 19 | |
Rushabh Mehta | 1f84799 | 2013-12-12 19:12:19 +0530 | [diff] [blame] | 20 | def after_install(): |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 21 | frappe.get_doc({"doctype": "Role", "role_name": "Analytics"}).insert() |
Rushabh Mehta | 33003c6 | 2014-04-30 11:16:02 +0530 | [diff] [blame] | 22 | set_single_defaults() |
Ankush Menat | 9a99f99 | 2022-01-23 17:38:04 +0530 | [diff] [blame] | 23 | create_print_setting_custom_fields() |
Rushabh Mehta | db7139a | 2013-01-17 18:22:22 +0530 | [diff] [blame] | 24 | add_all_roles_to("Administrator") |
tundebabzy | cad22db | 2018-02-22 06:38:36 +0100 | [diff] [blame] | 25 | create_default_cash_flow_mapper_templates() |
Suraj Shetty | 00cced1 | 2018-05-03 19:06:32 +0530 | [diff] [blame] | 26 | create_default_success_action() |
Suraj Shetty | 627a3dc | 2019-09-17 15:54:41 +0530 | [diff] [blame] | 27 | create_default_energy_point_rules() |
Rucha Mahabal | 4865eab | 2019-07-24 13:37:54 +0530 | [diff] [blame] | 28 | add_company_to_session_defaults() |
Deepesh Garg | a306af8 | 2020-08-06 20:52:02 +0530 | [diff] [blame] | 29 | add_standard_navbar_items() |
Shivam Mishra | 1323a9a | 2020-09-30 16:33:14 +0530 | [diff] [blame] | 30 | add_app_name() |
Anand Doshi | e9baaa6 | 2014-02-26 12:35:33 +0530 | [diff] [blame] | 31 | frappe.db.commit() |
Rushabh Mehta | db7139a | 2013-01-17 18:22:22 +0530 | [diff] [blame] | 32 | |
tundebabzy | cad22db | 2018-02-22 06:38:36 +0100 | [diff] [blame] | 33 | |
Rushabh Mehta | d55bdcf | 2015-12-31 11:12:48 +0530 | [diff] [blame] | 34 | def check_setup_wizard_not_completed(): |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 35 | if cint(frappe.db.get_single_value("System Settings", "setup_complete") or 0): |
Deepesh Garg | a306af8 | 2020-08-06 20:52:02 +0530 | [diff] [blame] | 36 | message = """ERPNext can only be installed on a fresh site where the setup wizard is not completed. |
Faris Ansari | f3a6e30 | 2020-07-08 10:45:55 +0530 | [diff] [blame] | 37 | You can reinstall this site (after saving your data) using: bench --site [sitename] reinstall""" |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 38 | frappe.throw(message) # nosemgrep |
Rushabh Mehta | d55bdcf | 2015-12-31 11:12:48 +0530 | [diff] [blame] | 39 | |
tundebabzy | cad22db | 2018-02-22 06:38:36 +0100 | [diff] [blame] | 40 | |
Pratik Vyas | 28da752 | 2014-02-19 20:53:45 +0530 | [diff] [blame] | 41 | def set_single_defaults(): |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 42 | for dt in ( |
| 43 | "Accounts Settings", |
| 44 | "Print Settings", |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 45 | "Buying Settings", |
| 46 | "Selling Settings", |
| 47 | "Stock Settings", |
| 48 | ): |
| 49 | default_values = frappe.db.sql( |
| 50 | """select fieldname, `default` from `tabDocField` |
| 51 | where parent=%s""", |
| 52 | dt, |
| 53 | ) |
Anand Doshi | eb7fea6 | 2014-03-19 17:10:01 +0530 | [diff] [blame] | 54 | if default_values: |
| 55 | try: |
Ankush Menat | c3e1f0e | 2022-03-27 11:52:31 +0530 | [diff] [blame] | 56 | doc = frappe.get_doc(dt, dt) |
Anand Doshi | eb7fea6 | 2014-03-19 17:10:01 +0530 | [diff] [blame] | 57 | for fieldname, value in default_values: |
Ankush Menat | c3e1f0e | 2022-03-27 11:52:31 +0530 | [diff] [blame] | 58 | doc.set(fieldname, value) |
| 59 | doc.flags.ignore_mandatory = True |
| 60 | doc.save() |
Rushabh Mehta | b62ed7a | 2016-10-13 11:00:00 +0530 | [diff] [blame] | 61 | except frappe.ValidationError: |
| 62 | pass |
Rushabh Mehta | d42167e | 2016-05-11 16:47:14 +0530 | [diff] [blame] | 63 | |
rtdany10 | 227466c | 2021-09-04 14:04:56 +0530 | [diff] [blame] | 64 | frappe.db.set_default("date_format", "dd-mm-yyyy") |
Deepesh Garg | e2dab6f | 2022-01-10 17:31:38 +0530 | [diff] [blame] | 65 | |
| 66 | setup_currency_exchange() |
| 67 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 68 | |
Deepesh Garg | e2dab6f | 2022-01-10 17:31:38 +0530 | [diff] [blame] | 69 | def setup_currency_exchange(): |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 70 | ces = frappe.get_single("Currency Exchange Settings") |
rtdany10 | 227466c | 2021-09-04 14:04:56 +0530 | [diff] [blame] | 71 | try: |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 72 | ces.set("result_key", []) |
| 73 | ces.set("req_params", []) |
Deepesh Garg | e2dab6f | 2022-01-10 17:31:38 +0530 | [diff] [blame] | 74 | |
| 75 | ces.api_endpoint = "https://frankfurter.app/{transaction_date}" |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 76 | ces.append("result_key", {"key": "rates"}) |
| 77 | ces.append("result_key", {"key": "{to_currency}"}) |
| 78 | ces.append("req_params", {"key": "base", "value": "{from_currency}"}) |
| 79 | ces.append("req_params", {"key": "symbols", "value": "{to_currency}"}) |
rtdany10 | 227466c | 2021-09-04 14:04:56 +0530 | [diff] [blame] | 80 | ces.save() |
| 81 | except frappe.ValidationError: |
| 82 | pass |
tundebabzy | cad22db | 2018-02-22 06:38:36 +0100 | [diff] [blame] | 83 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 84 | |
Ankush Menat | 9a99f99 | 2022-01-23 17:38:04 +0530 | [diff] [blame] | 85 | def create_print_setting_custom_fields(): |
Sagar Vora | aafb735 | 2022-08-18 15:31:20 +0000 | [diff] [blame] | 86 | create_custom_fields( |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 87 | { |
Sagar Vora | aafb735 | 2022-08-18 15:31:20 +0000 | [diff] [blame] | 88 | "Print Settings": [ |
| 89 | { |
| 90 | "label": _("Compact Item Print"), |
| 91 | "fieldname": "compact_item_print", |
| 92 | "fieldtype": "Check", |
| 93 | "default": "1", |
| 94 | "insert_after": "with_letterhead", |
| 95 | }, |
| 96 | { |
| 97 | "label": _("Print UOM after Quantity"), |
| 98 | "fieldname": "print_uom_after_quantity", |
| 99 | "fieldtype": "Check", |
| 100 | "default": "0", |
| 101 | "insert_after": "compact_item_print", |
| 102 | }, |
| 103 | { |
| 104 | "label": _("Print taxes with zero amount"), |
| 105 | "fieldname": "print_taxes_with_zero_amount", |
| 106 | "fieldtype": "Check", |
| 107 | "default": "0", |
| 108 | "insert_after": "allow_print_for_cancelled", |
| 109 | }, |
| 110 | ] |
| 111 | } |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 112 | ) |
tundebabzy | cad22db | 2018-02-22 06:38:36 +0100 | [diff] [blame] | 113 | |
| 114 | |
| 115 | def create_default_cash_flow_mapper_templates(): |
Suraj Shetty | 00cced1 | 2018-05-03 19:06:32 +0530 | [diff] [blame] | 116 | for mapper in DEFAULT_MAPPERS: |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 117 | if not frappe.db.exists("Cash Flow Mapper", mapper["section_name"]): |
tundebabzy | cad22db | 2018-02-22 06:38:36 +0100 | [diff] [blame] | 118 | doc = frappe.get_doc(mapper) |
| 119 | doc.insert(ignore_permissions=True) |
Suraj Shetty | 00cced1 | 2018-05-03 19:06:32 +0530 | [diff] [blame] | 120 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 121 | |
Suraj Shetty | 00cced1 | 2018-05-03 19:06:32 +0530 | [diff] [blame] | 122 | def create_default_success_action(): |
| 123 | for success_action in get_default_success_action(): |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 124 | if not frappe.db.exists("Success Action", success_action.get("ref_doctype")): |
Suraj Shetty | 00cced1 | 2018-05-03 19:06:32 +0530 | [diff] [blame] | 125 | doc = frappe.get_doc(success_action) |
| 126 | doc.insert(ignore_permissions=True) |
Rucha Mahabal | 4865eab | 2019-07-24 13:37:54 +0530 | [diff] [blame] | 127 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 128 | |
Suraj Shetty | 627a3dc | 2019-09-17 15:54:41 +0530 | [diff] [blame] | 129 | def create_default_energy_point_rules(): |
| 130 | |
| 131 | for rule in get_default_energy_point_rules(): |
| 132 | # check if any rule for ref. doctype exists |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 133 | rule_exists = frappe.db.exists( |
| 134 | "Energy Point Rule", {"reference_doctype": rule.get("reference_doctype")} |
| 135 | ) |
| 136 | if rule_exists: |
| 137 | continue |
Suraj Shetty | 627a3dc | 2019-09-17 15:54:41 +0530 | [diff] [blame] | 138 | doc = frappe.get_doc(rule) |
| 139 | doc.insert(ignore_permissions=True) |
| 140 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 141 | |
Rucha Mahabal | 4865eab | 2019-07-24 13:37:54 +0530 | [diff] [blame] | 142 | def add_company_to_session_defaults(): |
| 143 | settings = frappe.get_single("Session Default Settings") |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 144 | settings.append("session_defaults", {"ref_doctype": "Company"}) |
Rucha Mahabal | 4865eab | 2019-07-24 13:37:54 +0530 | [diff] [blame] | 145 | settings.save() |
Deepesh Garg | a306af8 | 2020-08-06 20:52:02 +0530 | [diff] [blame] | 146 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 147 | |
Deepesh Garg | a306af8 | 2020-08-06 20:52:02 +0530 | [diff] [blame] | 148 | def add_standard_navbar_items(): |
| 149 | navbar_settings = frappe.get_single("Navbar Settings") |
| 150 | |
| 151 | erpnext_navbar_items = [ |
| 152 | { |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 153 | "item_label": "Documentation", |
| 154 | "item_type": "Route", |
| 155 | "route": "https://erpnext.com/docs/user/manual", |
| 156 | "is_standard": 1, |
Deepesh Garg | a306af8 | 2020-08-06 20:52:02 +0530 | [diff] [blame] | 157 | }, |
| 158 | { |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 159 | "item_label": "User Forum", |
| 160 | "item_type": "Route", |
| 161 | "route": "https://discuss.erpnext.com", |
| 162 | "is_standard": 1, |
Deepesh Garg | a306af8 | 2020-08-06 20:52:02 +0530 | [diff] [blame] | 163 | }, |
| 164 | { |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 165 | "item_label": "Report an Issue", |
| 166 | "item_type": "Route", |
| 167 | "route": "https://github.com/frappe/erpnext/issues", |
| 168 | "is_standard": 1, |
| 169 | }, |
Deepesh Garg | a306af8 | 2020-08-06 20:52:02 +0530 | [diff] [blame] | 170 | ] |
| 171 | |
prssanna | 194dd12 | 2021-03-24 16:45:32 +0530 | [diff] [blame] | 172 | current_navbar_items = navbar_settings.help_dropdown |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 173 | navbar_settings.set("help_dropdown", []) |
Deepesh Garg | a306af8 | 2020-08-06 20:52:02 +0530 | [diff] [blame] | 174 | |
| 175 | for item in erpnext_navbar_items: |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 176 | current_labels = [item.get("item_label") for item in current_navbar_items] |
| 177 | if not item.get("item_label") in current_labels: |
| 178 | navbar_settings.append("help_dropdown", item) |
Deepesh Garg | a306af8 | 2020-08-06 20:52:02 +0530 | [diff] [blame] | 179 | |
prssanna | 194dd12 | 2021-03-24 16:45:32 +0530 | [diff] [blame] | 180 | for item in current_navbar_items: |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 181 | navbar_settings.append( |
| 182 | "help_dropdown", |
| 183 | { |
| 184 | "item_label": item.item_label, |
| 185 | "item_type": item.item_type, |
| 186 | "route": item.route, |
| 187 | "action": item.action, |
| 188 | "is_standard": item.is_standard, |
| 189 | "hidden": item.hidden, |
| 190 | }, |
| 191 | ) |
Deepesh Garg | a306af8 | 2020-08-06 20:52:02 +0530 | [diff] [blame] | 192 | |
| 193 | navbar_settings.save() |
Shivam Mishra | 1323a9a | 2020-09-30 16:33:14 +0530 | [diff] [blame] | 194 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 195 | |
Shivam Mishra | 1323a9a | 2020-09-30 16:33:14 +0530 | [diff] [blame] | 196 | def add_app_name(): |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 197 | frappe.db.set_value("System Settings", None, "app_name", "ERPNext") |