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" |
Rushabh Mehta | 74506e9 | 2013-03-25 17:52:14 +0530 | [diff] [blame] | 3 | |
| 4 | |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 5 | import frappe |
rohitwaghchaure | 7677ff0 | 2017-11-02 18:12:14 +0530 | [diff] [blame] | 6 | from frappe.utils import cint |
Rushabh Mehta | 74506e9 | 2013-03-25 17:52:14 +0530 | [diff] [blame] | 7 | |
Chillar Anand | 915b343 | 2021-09-02 16:44:59 +0530 | [diff] [blame] | 8 | |
Rushabh Mehta | 74506e9 | 2013-03-25 17:52:14 +0530 | [diff] [blame] | 9 | def boot_session(bootinfo): |
| 10 | """boot session - send website info if guest""" |
Rushabh Mehta | 430d132 | 2014-05-31 10:36:04 +0530 | [diff] [blame] | 11 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 12 | if frappe.session["user"] != "Guest": |
Rushabh Mehta | 430d132 | 2014-05-31 10:36:04 +0530 | [diff] [blame] | 13 | update_page_info(bootinfo) |
| 14 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 15 | bootinfo.sysdefaults.territory = frappe.db.get_single_value("Selling Settings", "territory") |
| 16 | bootinfo.sysdefaults.customer_group = frappe.db.get_single_value( |
| 17 | "Selling Settings", "customer_group" |
| 18 | ) |
| 19 | bootinfo.sysdefaults.allow_stale = cint( |
| 20 | frappe.db.get_single_value("Accounts Settings", "allow_stale") |
| 21 | ) |
Raffael Meyer | 870b02b | 2023-05-14 05:29:58 +0200 | [diff] [blame] | 22 | bootinfo.sysdefaults.over_billing_allowance = frappe.db.get_single_value( |
| 23 | "Accounts Settings", "over_billing_allowance" |
| 24 | ) |
| 25 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 26 | bootinfo.sysdefaults.quotation_valid_till = cint( |
| 27 | frappe.db.get_single_value("CRM Settings", "default_valid_till") |
| 28 | ) |
Rushabh Mehta | 430d132 | 2014-05-31 10:36:04 +0530 | [diff] [blame] | 29 | |
Deepesh Garg | 148703b | 2023-02-13 10:27:55 +0530 | [diff] [blame] | 30 | bootinfo.sysdefaults.allow_sales_order_creation_for_expired_quotation = cint( |
| 31 | frappe.db.get_single_value( |
| 32 | "Selling Settings", "allow_sales_order_creation_for_expired_quotation" |
| 33 | ) |
| 34 | ) |
| 35 | |
Rushabh Mehta | 430d132 | 2014-05-31 10:36:04 +0530 | [diff] [blame] | 36 | # if no company, show a dialog box to create a new company |
Suraj Shetty | bfc195d | 2018-09-21 10:20:52 +0530 | [diff] [blame] | 37 | bootinfo.customer_count = frappe.db.sql("""SELECT count(*) FROM `tabCustomer`""")[0][0] |
Rushabh Mehta | 430d132 | 2014-05-31 10:36:04 +0530 | [diff] [blame] | 38 | |
| 39 | if not bootinfo.customer_count: |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 40 | bootinfo.setup_complete = ( |
| 41 | frappe.db.sql( |
| 42 | """SELECT `name` |
Suraj Shetty | bfc195d | 2018-09-21 10:20:52 +0530 | [diff] [blame] | 43 | FROM `tabCompany` |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 44 | LIMIT 1""" |
| 45 | ) |
| 46 | and "Yes" |
| 47 | or "No" |
| 48 | ) |
Rushabh Mehta | 430d132 | 2014-05-31 10:36:04 +0530 | [diff] [blame] | 49 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 50 | bootinfo.docs += frappe.db.sql( |
| 51 | """select name, default_currency, cost_center, default_selling_terms, default_buying_terms, |
Gaurav | b30a9b1 | 2019-03-01 12:33:19 +0530 | [diff] [blame] | 52 | default_letter_head, default_bank_account, enable_perpetual_inventory, country from `tabCompany`""", |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 53 | as_dict=1, |
| 54 | update={"doctype": ":Company"}, |
| 55 | ) |
Rushabh Mehta | 9dd25b3 | 2013-09-03 17:36:41 +0530 | [diff] [blame] | 56 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 57 | party_account_types = frappe.db.sql( |
| 58 | """ select name, ifnull(account_type, '') from `tabParty Type`""" |
| 59 | ) |
rohitwaghchaure | e8358f3 | 2018-05-16 11:02:26 +0530 | [diff] [blame] | 60 | bootinfo.party_account_types = frappe._dict(party_account_types) |
| 61 | |
Deepesh Garg | 371413a | 2023-07-29 22:39:07 +0530 | [diff] [blame] | 62 | bootinfo.sysdefaults.demo_company = frappe.db.get_single_value("Global Defaults", "demo_company") |
| 63 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 64 | |
Rushabh Mehta | 430d132 | 2014-05-31 10:36:04 +0530 | [diff] [blame] | 65 | def update_page_info(bootinfo): |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 66 | bootinfo.page_info.update( |
| 67 | { |
| 68 | "Chart of Accounts": {"title": "Chart of Accounts", "route": "Tree/Account"}, |
| 69 | "Chart of Cost Centers": {"title": "Chart of Cost Centers", "route": "Tree/Cost Center"}, |
| 70 | "Item Group Tree": {"title": "Item Group Tree", "route": "Tree/Item Group"}, |
| 71 | "Customer Group Tree": {"title": "Customer Group Tree", "route": "Tree/Customer Group"}, |
| 72 | "Territory Tree": {"title": "Territory Tree", "route": "Tree/Territory"}, |
| 73 | "Sales Person Tree": {"title": "Sales Person Tree", "route": "Tree/Sales Person"}, |
Rushabh Mehta | 430d132 | 2014-05-31 10:36:04 +0530 | [diff] [blame] | 74 | } |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 75 | ) |
Richard Case | 525f656 | 2023-12-06 15:18:13 +0000 | [diff] [blame] | 76 | |
| 77 | |
| 78 | def bootinfo(bootinfo): |
| 79 | if bootinfo.get("user") and bootinfo["user"].get("name"): |
| 80 | bootinfo["user"]["employee"] = "" |
Ankush Menat | 6a47a2c | 2023-12-06 20:53:55 +0530 | [diff] [blame] | 81 | employee = frappe.db.get_value("Employee", {"user_id": bootinfo["user"]["name"]}, "name") |
Richard Case | 525f656 | 2023-12-06 15:18:13 +0000 | [diff] [blame] | 82 | if employee: |
| 83 | bootinfo["user"]["employee"] = employee |