blob: 3de2be34ebcbd7f9ed4d51d923eb3d5af2f67a2f [file] [log] [blame]
Anand Doshi885e0742015-03-03 14:55:30 +05301# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
Rushabh Mehtae67d1fb2013-08-05 14:59:54 +05302# License: GNU General Public License v3. See license.txt"
Rushabh Mehta74506e92013-03-25 17:52:14 +05303
4
Rushabh Mehta793ba6b2014-02-14 15:47:51 +05305import frappe
rohitwaghchaure7677ff02017-11-02 18:12:14 +05306from frappe.utils import cint
Rushabh Mehta74506e92013-03-25 17:52:14 +05307
Chillar Anand915b3432021-09-02 16:44:59 +05308
Rushabh Mehta74506e92013-03-25 17:52:14 +05309def boot_session(bootinfo):
10 """boot session - send website info if guest"""
Rushabh Mehta430d1322014-05-31 10:36:04 +053011
Ankush Menat494bd9e2022-03-28 18:52:46 +053012 if frappe.session["user"] != "Guest":
Rushabh Mehta430d1322014-05-31 10:36:04 +053013 update_page_info(bootinfo)
14
Ankush Menat494bd9e2022-03-28 18:52:46 +053015 bootinfo.sysdefaults.territory = frappe.db.get_single_value("Selling Settings", "territory")
Akhil Narang3effaf22024-03-27 11:37:26 +053016 bootinfo.sysdefaults.customer_group = frappe.db.get_single_value("Selling Settings", "customer_group")
Ankush Menat494bd9e2022-03-28 18:52:46 +053017 bootinfo.sysdefaults.allow_stale = cint(
18 frappe.db.get_single_value("Accounts Settings", "allow_stale")
19 )
Raffael Meyer870b02b2023-05-14 05:29:58 +020020 bootinfo.sysdefaults.over_billing_allowance = frappe.db.get_single_value(
21 "Accounts Settings", "over_billing_allowance"
22 )
23
Ankush Menat494bd9e2022-03-28 18:52:46 +053024 bootinfo.sysdefaults.quotation_valid_till = cint(
25 frappe.db.get_single_value("CRM Settings", "default_valid_till")
26 )
Rushabh Mehta430d1322014-05-31 10:36:04 +053027
Deepesh Garg148703b2023-02-13 10:27:55 +053028 bootinfo.sysdefaults.allow_sales_order_creation_for_expired_quotation = cint(
Akhil Narang3effaf22024-03-27 11:37:26 +053029 frappe.db.get_single_value("Selling Settings", "allow_sales_order_creation_for_expired_quotation")
Deepesh Garg148703b2023-02-13 10:27:55 +053030 )
31
Rushabh Mehta430d1322014-05-31 10:36:04 +053032 # if no company, show a dialog box to create a new company
Suraj Shettybfc195d2018-09-21 10:20:52 +053033 bootinfo.customer_count = frappe.db.sql("""SELECT count(*) FROM `tabCustomer`""")[0][0]
Rushabh Mehta430d1322014-05-31 10:36:04 +053034
35 if not bootinfo.customer_count:
Ankush Menat494bd9e2022-03-28 18:52:46 +053036 bootinfo.setup_complete = (
37 frappe.db.sql(
38 """SELECT `name`
Suraj Shettybfc195d2018-09-21 10:20:52 +053039 FROM `tabCompany`
Ankush Menat494bd9e2022-03-28 18:52:46 +053040 LIMIT 1"""
41 )
42 and "Yes"
43 or "No"
44 )
Rushabh Mehta430d1322014-05-31 10:36:04 +053045
Ankush Menat494bd9e2022-03-28 18:52:46 +053046 bootinfo.docs += frappe.db.sql(
47 """select name, default_currency, cost_center, default_selling_terms, default_buying_terms,
Gauravb30a9b12019-03-01 12:33:19 +053048 default_letter_head, default_bank_account, enable_perpetual_inventory, country from `tabCompany`""",
Ankush Menat494bd9e2022-03-28 18:52:46 +053049 as_dict=1,
50 update={"doctype": ":Company"},
51 )
Rushabh Mehta9dd25b32013-09-03 17:36:41 +053052
Akhil Narang3effaf22024-03-27 11:37:26 +053053 party_account_types = frappe.db.sql(""" select name, ifnull(account_type, '') from `tabParty Type`""")
rohitwaghchauree8358f32018-05-16 11:02:26 +053054 bootinfo.party_account_types = frappe._dict(party_account_types)
55
Deepesh Garg371413a2023-07-29 22:39:07 +053056 bootinfo.sysdefaults.demo_company = frappe.db.get_single_value("Global Defaults", "demo_company")
57
Ankush Menat494bd9e2022-03-28 18:52:46 +053058
Rushabh Mehta430d1322014-05-31 10:36:04 +053059def update_page_info(bootinfo):
Ankush Menat494bd9e2022-03-28 18:52:46 +053060 bootinfo.page_info.update(
61 {
62 "Chart of Accounts": {"title": "Chart of Accounts", "route": "Tree/Account"},
63 "Chart of Cost Centers": {"title": "Chart of Cost Centers", "route": "Tree/Cost Center"},
64 "Item Group Tree": {"title": "Item Group Tree", "route": "Tree/Item Group"},
65 "Customer Group Tree": {"title": "Customer Group Tree", "route": "Tree/Customer Group"},
66 "Territory Tree": {"title": "Territory Tree", "route": "Tree/Territory"},
67 "Sales Person Tree": {"title": "Sales Person Tree", "route": "Tree/Sales Person"},
Rushabh Mehta430d1322014-05-31 10:36:04 +053068 }
Ankush Menat494bd9e2022-03-28 18:52:46 +053069 )
Richard Case525f6562023-12-06 15:18:13 +000070
71
72def bootinfo(bootinfo):
73 if bootinfo.get("user") and bootinfo["user"].get("name"):
74 bootinfo["user"]["employee"] = ""
Ankush Menat6a47a2c2023-12-06 20:53:55 +053075 employee = frappe.db.get_value("Employee", {"user_id": bootinfo["user"]["name"]}, "name")
Richard Case525f6562023-12-06 15:18:13 +000076 if employee:
77 bootinfo["user"]["employee"] = employee