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.setup.default_energy_point_rules import get_default_energy_point_rules |
barredterra | ce83f02 | 2022-11-17 22:17:19 +0100 | [diff] [blame] | 12 | from erpnext.setup.doctype.incoterm.incoterm import create_incoterms |
Chillar Anand | 915b343 | 2021-09-02 16:44:59 +0530 | [diff] [blame] | 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(): |
Rucha Mahabal | 29f91a7 | 2024-02-29 10:53:30 +0530 | [diff] [blame] | 21 | if not frappe.db.exists("Role", "Analytics"): |
| 22 | frappe.get_doc({"doctype": "Role", "role_name": "Analytics"}).insert() |
| 23 | |
Rushabh Mehta | 33003c6 | 2014-04-30 11:16:02 +0530 | [diff] [blame] | 24 | set_single_defaults() |
Ankush Menat | 9a99f99 | 2022-01-23 17:38:04 +0530 | [diff] [blame] | 25 | create_print_setting_custom_fields() |
Rushabh Mehta | db7139a | 2013-01-17 18:22:22 +0530 | [diff] [blame] | 26 | add_all_roles_to("Administrator") |
Suraj Shetty | 00cced1 | 2018-05-03 19:06:32 +0530 | [diff] [blame] | 27 | create_default_success_action() |
Suraj Shetty | 627a3dc | 2019-09-17 15:54:41 +0530 | [diff] [blame] | 28 | create_default_energy_point_rules() |
barredterra | ce83f02 | 2022-11-17 22:17:19 +0100 | [diff] [blame] | 29 | create_incoterms() |
Deepesh Garg | 76197cc | 2023-06-07 10:11:32 +0530 | [diff] [blame] | 30 | create_default_role_profiles() |
Rucha Mahabal | 4865eab | 2019-07-24 13:37:54 +0530 | [diff] [blame] | 31 | add_company_to_session_defaults() |
Deepesh Garg | a306af8 | 2020-08-06 20:52:02 +0530 | [diff] [blame] | 32 | add_standard_navbar_items() |
Shivam Mishra | 1323a9a | 2020-09-30 16:33:14 +0530 | [diff] [blame] | 33 | add_app_name() |
Ankush Menat | d2096cf | 2023-10-16 16:53:43 +0530 | [diff] [blame] | 34 | update_roles() |
Anand Doshi | e9baaa6 | 2014-02-26 12:35:33 +0530 | [diff] [blame] | 35 | frappe.db.commit() |
Rushabh Mehta | db7139a | 2013-01-17 18:22:22 +0530 | [diff] [blame] | 36 | |
tundebabzy | cad22db | 2018-02-22 06:38:36 +0100 | [diff] [blame] | 37 | |
Rushabh Mehta | d55bdcf | 2015-12-31 11:12:48 +0530 | [diff] [blame] | 38 | def check_setup_wizard_not_completed(): |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 39 | 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] | 40 | 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] | 41 | 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] | 42 | frappe.throw(message) # nosemgrep |
Rushabh Mehta | d55bdcf | 2015-12-31 11:12:48 +0530 | [diff] [blame] | 43 | |
tundebabzy | cad22db | 2018-02-22 06:38:36 +0100 | [diff] [blame] | 44 | |
Pratik Vyas | 28da752 | 2014-02-19 20:53:45 +0530 | [diff] [blame] | 45 | def set_single_defaults(): |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 46 | for dt in ( |
| 47 | "Accounts Settings", |
| 48 | "Print Settings", |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 49 | "Buying Settings", |
| 50 | "Selling Settings", |
| 51 | "Stock Settings", |
| 52 | ): |
| 53 | default_values = frappe.db.sql( |
| 54 | """select fieldname, `default` from `tabDocField` |
| 55 | where parent=%s""", |
| 56 | dt, |
| 57 | ) |
Anand Doshi | eb7fea6 | 2014-03-19 17:10:01 +0530 | [diff] [blame] | 58 | if default_values: |
| 59 | try: |
Ankush Menat | c3e1f0e | 2022-03-27 11:52:31 +0530 | [diff] [blame] | 60 | doc = frappe.get_doc(dt, dt) |
Anand Doshi | eb7fea6 | 2014-03-19 17:10:01 +0530 | [diff] [blame] | 61 | for fieldname, value in default_values: |
Ankush Menat | c3e1f0e | 2022-03-27 11:52:31 +0530 | [diff] [blame] | 62 | doc.set(fieldname, value) |
| 63 | doc.flags.ignore_mandatory = True |
| 64 | doc.save() |
Rushabh Mehta | b62ed7a | 2016-10-13 11:00:00 +0530 | [diff] [blame] | 65 | except frappe.ValidationError: |
| 66 | pass |
Rushabh Mehta | d42167e | 2016-05-11 16:47:14 +0530 | [diff] [blame] | 67 | |
Deepesh Garg | e2dab6f | 2022-01-10 17:31:38 +0530 | [diff] [blame] | 68 | setup_currency_exchange() |
| 69 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 70 | |
Deepesh Garg | e2dab6f | 2022-01-10 17:31:38 +0530 | [diff] [blame] | 71 | def setup_currency_exchange(): |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 72 | ces = frappe.get_single("Currency Exchange Settings") |
rtdany10 | 227466c | 2021-09-04 14:04:56 +0530 | [diff] [blame] | 73 | try: |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 74 | ces.set("result_key", []) |
| 75 | ces.set("req_params", []) |
Deepesh Garg | e2dab6f | 2022-01-10 17:31:38 +0530 | [diff] [blame] | 76 | |
| 77 | ces.api_endpoint = "https://frankfurter.app/{transaction_date}" |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 78 | ces.append("result_key", {"key": "rates"}) |
| 79 | ces.append("result_key", {"key": "{to_currency}"}) |
| 80 | ces.append("req_params", {"key": "base", "value": "{from_currency}"}) |
| 81 | ces.append("req_params", {"key": "symbols", "value": "{to_currency}"}) |
rtdany10 | 227466c | 2021-09-04 14:04:56 +0530 | [diff] [blame] | 82 | ces.save() |
| 83 | except frappe.ValidationError: |
| 84 | pass |
tundebabzy | cad22db | 2018-02-22 06:38:36 +0100 | [diff] [blame] | 85 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 86 | |
Ankush Menat | 9a99f99 | 2022-01-23 17:38:04 +0530 | [diff] [blame] | 87 | def create_print_setting_custom_fields(): |
Sagar Vora | aafb735 | 2022-08-18 15:31:20 +0000 | [diff] [blame] | 88 | create_custom_fields( |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 89 | { |
Sagar Vora | aafb735 | 2022-08-18 15:31:20 +0000 | [diff] [blame] | 90 | "Print Settings": [ |
| 91 | { |
| 92 | "label": _("Compact Item Print"), |
| 93 | "fieldname": "compact_item_print", |
| 94 | "fieldtype": "Check", |
| 95 | "default": "1", |
| 96 | "insert_after": "with_letterhead", |
| 97 | }, |
| 98 | { |
| 99 | "label": _("Print UOM after Quantity"), |
| 100 | "fieldname": "print_uom_after_quantity", |
| 101 | "fieldtype": "Check", |
| 102 | "default": "0", |
| 103 | "insert_after": "compact_item_print", |
| 104 | }, |
| 105 | { |
| 106 | "label": _("Print taxes with zero amount"), |
| 107 | "fieldname": "print_taxes_with_zero_amount", |
| 108 | "fieldtype": "Check", |
| 109 | "default": "0", |
| 110 | "insert_after": "allow_print_for_cancelled", |
| 111 | }, |
| 112 | ] |
| 113 | } |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 114 | ) |
tundebabzy | cad22db | 2018-02-22 06:38:36 +0100 | [diff] [blame] | 115 | |
| 116 | |
Suraj Shetty | 00cced1 | 2018-05-03 19:06:32 +0530 | [diff] [blame] | 117 | def create_default_success_action(): |
| 118 | for success_action in get_default_success_action(): |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 119 | if not frappe.db.exists("Success Action", success_action.get("ref_doctype")): |
Suraj Shetty | 00cced1 | 2018-05-03 19:06:32 +0530 | [diff] [blame] | 120 | doc = frappe.get_doc(success_action) |
| 121 | doc.insert(ignore_permissions=True) |
Rucha Mahabal | 4865eab | 2019-07-24 13:37:54 +0530 | [diff] [blame] | 122 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 123 | |
Suraj Shetty | 627a3dc | 2019-09-17 15:54:41 +0530 | [diff] [blame] | 124 | def create_default_energy_point_rules(): |
| 125 | |
| 126 | for rule in get_default_energy_point_rules(): |
| 127 | # check if any rule for ref. doctype exists |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 128 | rule_exists = frappe.db.exists( |
| 129 | "Energy Point Rule", {"reference_doctype": rule.get("reference_doctype")} |
| 130 | ) |
| 131 | if rule_exists: |
| 132 | continue |
Suraj Shetty | 627a3dc | 2019-09-17 15:54:41 +0530 | [diff] [blame] | 133 | doc = frappe.get_doc(rule) |
| 134 | doc.insert(ignore_permissions=True) |
| 135 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 136 | |
Rucha Mahabal | 4865eab | 2019-07-24 13:37:54 +0530 | [diff] [blame] | 137 | def add_company_to_session_defaults(): |
| 138 | settings = frappe.get_single("Session Default Settings") |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 139 | settings.append("session_defaults", {"ref_doctype": "Company"}) |
Rucha Mahabal | 4865eab | 2019-07-24 13:37:54 +0530 | [diff] [blame] | 140 | settings.save() |
Deepesh Garg | a306af8 | 2020-08-06 20:52:02 +0530 | [diff] [blame] | 141 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 142 | |
Deepesh Garg | a306af8 | 2020-08-06 20:52:02 +0530 | [diff] [blame] | 143 | def add_standard_navbar_items(): |
| 144 | navbar_settings = frappe.get_single("Navbar Settings") |
| 145 | |
| 146 | erpnext_navbar_items = [ |
| 147 | { |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 148 | "item_label": "Documentation", |
| 149 | "item_type": "Route", |
Ankush Menat | a449a4b | 2023-07-04 14:58:45 +0530 | [diff] [blame] | 150 | "route": "https://docs.erpnext.com/", |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 151 | "is_standard": 1, |
Deepesh Garg | a306af8 | 2020-08-06 20:52:02 +0530 | [diff] [blame] | 152 | }, |
| 153 | { |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 154 | "item_label": "User Forum", |
| 155 | "item_type": "Route", |
MohsinAli | dd93ea0 | 2023-04-17 17:00:52 +0530 | [diff] [blame] | 156 | "route": "https://discuss.frappe.io", |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 157 | "is_standard": 1, |
Deepesh Garg | a306af8 | 2020-08-06 20:52:02 +0530 | [diff] [blame] | 158 | }, |
| 159 | { |
Ankush Menat | a449a4b | 2023-07-04 14:58:45 +0530 | [diff] [blame] | 160 | "item_label": "Frappe School", |
| 161 | "item_type": "Route", |
| 162 | "route": "https://frappe.school?utm_source=in_app", |
| 163 | "is_standard": 1, |
| 164 | }, |
| 165 | { |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 166 | "item_label": "Report an Issue", |
| 167 | "item_type": "Route", |
| 168 | "route": "https://github.com/frappe/erpnext/issues", |
| 169 | "is_standard": 1, |
| 170 | }, |
Deepesh Garg | a306af8 | 2020-08-06 20:52:02 +0530 | [diff] [blame] | 171 | ] |
| 172 | |
prssanna | 194dd12 | 2021-03-24 16:45:32 +0530 | [diff] [blame] | 173 | current_navbar_items = navbar_settings.help_dropdown |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 174 | navbar_settings.set("help_dropdown", []) |
Deepesh Garg | a306af8 | 2020-08-06 20:52:02 +0530 | [diff] [blame] | 175 | |
| 176 | for item in erpnext_navbar_items: |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 177 | current_labels = [item.get("item_label") for item in current_navbar_items] |
barredterra | eb9ee3f | 2023-12-05 11:22:55 +0100 | [diff] [blame] | 178 | if item.get("item_label") not in current_labels: |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 179 | navbar_settings.append("help_dropdown", item) |
Deepesh Garg | a306af8 | 2020-08-06 20:52:02 +0530 | [diff] [blame] | 180 | |
prssanna | 194dd12 | 2021-03-24 16:45:32 +0530 | [diff] [blame] | 181 | for item in current_navbar_items: |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 182 | navbar_settings.append( |
| 183 | "help_dropdown", |
| 184 | { |
| 185 | "item_label": item.item_label, |
| 186 | "item_type": item.item_type, |
| 187 | "route": item.route, |
| 188 | "action": item.action, |
| 189 | "is_standard": item.is_standard, |
| 190 | "hidden": item.hidden, |
| 191 | }, |
| 192 | ) |
Deepesh Garg | a306af8 | 2020-08-06 20:52:02 +0530 | [diff] [blame] | 193 | |
| 194 | navbar_settings.save() |
Shivam Mishra | 1323a9a | 2020-09-30 16:33:14 +0530 | [diff] [blame] | 195 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 196 | |
Shivam Mishra | 1323a9a | 2020-09-30 16:33:14 +0530 | [diff] [blame] | 197 | def add_app_name(): |
Ankush Menat | a3ea985 | 2023-06-13 17:30:38 +0530 | [diff] [blame] | 198 | frappe.db.set_single_value("System Settings", "app_name", "ERPNext") |
Rohit Waghchaure | 5949a7e | 2022-12-01 15:59:42 +0530 | [diff] [blame] | 199 | |
| 200 | |
Ankush Menat | d2096cf | 2023-10-16 16:53:43 +0530 | [diff] [blame] | 201 | def update_roles(): |
| 202 | website_user_roles = ("Customer", "Supplier") |
| 203 | for role in website_user_roles: |
| 204 | frappe.db.set_value("Role", role, "desk_access", 0) |
| 205 | |
| 206 | |
Deepesh Garg | 76197cc | 2023-06-07 10:11:32 +0530 | [diff] [blame] | 207 | def create_default_role_profiles(): |
Ankush Menat | 0166f69 | 2023-06-07 15:09:49 +0530 | [diff] [blame] | 208 | for role_profile_name, roles in DEFAULT_ROLE_PROFILES.items(): |
| 209 | role_profile = frappe.new_doc("Role Profile") |
| 210 | role_profile.role_profile = role_profile_name |
| 211 | for role in roles: |
| 212 | role_profile.append("roles", {"role": role}) |
| 213 | |
| 214 | role_profile.insert(ignore_permissions=True) |
Deepesh Garg | 76197cc | 2023-06-07 10:11:32 +0530 | [diff] [blame] | 215 | |
| 216 | |
Ankush Menat | 0166f69 | 2023-06-07 15:09:49 +0530 | [diff] [blame] | 217 | DEFAULT_ROLE_PROFILES = { |
| 218 | "Inventory": [ |
| 219 | "Stock User", |
| 220 | "Stock Manager", |
| 221 | "Item Manager", |
| 222 | ], |
| 223 | "Manufacturing": [ |
| 224 | "Stock User", |
| 225 | "Manufacturing User", |
| 226 | "Manufacturing Manager", |
| 227 | ], |
| 228 | "Accounts": [ |
| 229 | "Accounts User", |
| 230 | "Accounts Manager", |
| 231 | ], |
| 232 | "Sales": [ |
| 233 | "Sales User", |
| 234 | "Stock User", |
| 235 | "Sales Manager", |
| 236 | ], |
| 237 | "Purchase": [ |
| 238 | "Item Manager", |
| 239 | "Stock User", |
| 240 | "Purchase User", |
| 241 | "Purchase Manager", |
| 242 | ], |
| 243 | } |