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 | bootinfo.custom_css = frappe.db.get_value("Style Settings", None, "custom_css") or "" |
Rushabh Mehta | 74506e9 | 2013-03-25 17:52:14 +0530 | [diff] [blame] | 13 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 14 | if frappe.session["user"] != "Guest": |
Rushabh Mehta | 430d132 | 2014-05-31 10:36:04 +0530 | [diff] [blame] | 15 | update_page_info(bootinfo) |
| 16 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 17 | bootinfo.sysdefaults.territory = frappe.db.get_single_value("Selling Settings", "territory") |
| 18 | bootinfo.sysdefaults.customer_group = frappe.db.get_single_value( |
| 19 | "Selling Settings", "customer_group" |
| 20 | ) |
| 21 | bootinfo.sysdefaults.allow_stale = cint( |
| 22 | frappe.db.get_single_value("Accounts Settings", "allow_stale") |
| 23 | ) |
| 24 | bootinfo.sysdefaults.quotation_valid_till = cint( |
| 25 | frappe.db.get_single_value("CRM Settings", "default_valid_till") |
| 26 | ) |
Rushabh Mehta | 430d132 | 2014-05-31 10:36:04 +0530 | [diff] [blame] | 27 | |
Rushabh Mehta | 430d132 | 2014-05-31 10:36:04 +0530 | [diff] [blame] | 28 | # if no company, show a dialog box to create a new company |
Suraj Shetty | bfc195d | 2018-09-21 10:20:52 +0530 | [diff] [blame] | 29 | bootinfo.customer_count = frappe.db.sql("""SELECT count(*) FROM `tabCustomer`""")[0][0] |
Rushabh Mehta | 430d132 | 2014-05-31 10:36:04 +0530 | [diff] [blame] | 30 | |
| 31 | if not bootinfo.customer_count: |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 32 | bootinfo.setup_complete = ( |
| 33 | frappe.db.sql( |
| 34 | """SELECT `name` |
Suraj Shetty | bfc195d | 2018-09-21 10:20:52 +0530 | [diff] [blame] | 35 | FROM `tabCompany` |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 36 | LIMIT 1""" |
| 37 | ) |
| 38 | and "Yes" |
| 39 | or "No" |
| 40 | ) |
Rushabh Mehta | 430d132 | 2014-05-31 10:36:04 +0530 | [diff] [blame] | 41 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 42 | bootinfo.docs += frappe.db.sql( |
| 43 | """select name, default_currency, cost_center, default_selling_terms, default_buying_terms, |
Gaurav | b30a9b1 | 2019-03-01 12:33:19 +0530 | [diff] [blame] | 44 | default_letter_head, default_bank_account, enable_perpetual_inventory, country from `tabCompany`""", |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 45 | as_dict=1, |
| 46 | update={"doctype": ":Company"}, |
| 47 | ) |
Rushabh Mehta | 9dd25b3 | 2013-09-03 17:36:41 +0530 | [diff] [blame] | 48 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 49 | party_account_types = frappe.db.sql( |
| 50 | """ select name, ifnull(account_type, '') from `tabParty Type`""" |
| 51 | ) |
rohitwaghchaure | e8358f3 | 2018-05-16 11:02:26 +0530 | [diff] [blame] | 52 | bootinfo.party_account_types = frappe._dict(party_account_types) |
| 53 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 54 | |
Rushabh Mehta | 430d132 | 2014-05-31 10:36:04 +0530 | [diff] [blame] | 55 | def update_page_info(bootinfo): |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 56 | bootinfo.page_info.update( |
| 57 | { |
| 58 | "Chart of Accounts": {"title": "Chart of Accounts", "route": "Tree/Account"}, |
| 59 | "Chart of Cost Centers": {"title": "Chart of Cost Centers", "route": "Tree/Cost Center"}, |
| 60 | "Item Group Tree": {"title": "Item Group Tree", "route": "Tree/Item Group"}, |
| 61 | "Customer Group Tree": {"title": "Customer Group Tree", "route": "Tree/Customer Group"}, |
| 62 | "Territory Tree": {"title": "Territory Tree", "route": "Tree/Territory"}, |
| 63 | "Sales Person Tree": {"title": "Sales Person Tree", "route": "Tree/Sales Person"}, |
Rushabh Mehta | 430d132 | 2014-05-31 10:36:04 +0530 | [diff] [blame] | 64 | } |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 65 | ) |