blob: c3445ab6446d2b2aa80e12dadc1650cd4ced228f [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 bootinfo.custom_css = frappe.db.get_value("Style Settings", None, "custom_css") or ""
Rushabh Mehta74506e92013-03-25 17:52:14 +053013
Ankush Menat494bd9e2022-03-28 18:52:46 +053014 if frappe.session["user"] != "Guest":
Rushabh Mehta430d1322014-05-31 10:36:04 +053015 update_page_info(bootinfo)
16
17 load_country_and_currency(bootinfo)
Ankush Menat494bd9e2022-03-28 18:52:46 +053018 bootinfo.sysdefaults.territory = frappe.db.get_single_value("Selling Settings", "territory")
19 bootinfo.sysdefaults.customer_group = frappe.db.get_single_value(
20 "Selling Settings", "customer_group"
21 )
22 bootinfo.sysdefaults.allow_stale = cint(
23 frappe.db.get_single_value("Accounts Settings", "allow_stale")
24 )
25 bootinfo.sysdefaults.quotation_valid_till = cint(
26 frappe.db.get_single_value("CRM Settings", "default_valid_till")
27 )
Rushabh Mehta430d1322014-05-31 10:36:04 +053028
Rushabh Mehta430d1322014-05-31 10:36:04 +053029 # if no company, show a dialog box to create a new company
Suraj Shettybfc195d2018-09-21 10:20:52 +053030 bootinfo.customer_count = frappe.db.sql("""SELECT count(*) FROM `tabCustomer`""")[0][0]
Rushabh Mehta430d1322014-05-31 10:36:04 +053031
32 if not bootinfo.customer_count:
Ankush Menat494bd9e2022-03-28 18:52:46 +053033 bootinfo.setup_complete = (
34 frappe.db.sql(
35 """SELECT `name`
Suraj Shettybfc195d2018-09-21 10:20:52 +053036 FROM `tabCompany`
Ankush Menat494bd9e2022-03-28 18:52:46 +053037 LIMIT 1"""
38 )
39 and "Yes"
40 or "No"
41 )
Rushabh Mehta430d1322014-05-31 10:36:04 +053042
Ankush Menat494bd9e2022-03-28 18:52:46 +053043 bootinfo.docs += frappe.db.sql(
44 """select name, default_currency, cost_center, default_selling_terms, default_buying_terms,
Gauravb30a9b12019-03-01 12:33:19 +053045 default_letter_head, default_bank_account, enable_perpetual_inventory, country from `tabCompany`""",
Ankush Menat494bd9e2022-03-28 18:52:46 +053046 as_dict=1,
47 update={"doctype": ":Company"},
48 )
Rushabh Mehta9dd25b32013-09-03 17:36:41 +053049
Ankush Menat494bd9e2022-03-28 18:52:46 +053050 party_account_types = frappe.db.sql(
51 """ select name, ifnull(account_type, '') from `tabParty Type`"""
52 )
rohitwaghchauree8358f32018-05-16 11:02:26 +053053 bootinfo.party_account_types = frappe._dict(party_account_types)
54
Ankush Menat494bd9e2022-03-28 18:52:46 +053055
Rushabh Mehta9dd25b32013-09-03 17:36:41 +053056def load_country_and_currency(bootinfo):
Rushabh Mehtaa504f062014-04-04 12:16:26 +053057 country = frappe.db.get_default("country")
58 if country and frappe.db.exists("Country", country):
Rushabh Mehta430d1322014-05-31 10:36:04 +053059 bootinfo.docs += [frappe.get_doc("Country", country)]
60
Ankush Menat494bd9e2022-03-28 18:52:46 +053061 bootinfo.docs += frappe.db.sql(
62 """select name, fraction, fraction_units,
Rushabh Mehtae29192c2016-03-22 14:52:25 +053063 number_format, smallest_currency_fraction_value, symbol from tabCurrency
Ankush Menat494bd9e2022-03-28 18:52:46 +053064 where enabled=1""",
65 as_dict=1,
66 update={"doctype": ":Currency"},
67 )
68
Rushabh Mehta9dd25b32013-09-03 17:36:41 +053069
Rushabh Mehta430d1322014-05-31 10:36:04 +053070def update_page_info(bootinfo):
Ankush Menat494bd9e2022-03-28 18:52:46 +053071 bootinfo.page_info.update(
72 {
73 "Chart of Accounts": {"title": "Chart of Accounts", "route": "Tree/Account"},
74 "Chart of Cost Centers": {"title": "Chart of Cost Centers", "route": "Tree/Cost Center"},
75 "Item Group Tree": {"title": "Item Group Tree", "route": "Tree/Item Group"},
76 "Customer Group Tree": {"title": "Customer Group Tree", "route": "Tree/Customer Group"},
77 "Territory Tree": {"title": "Territory Tree", "route": "Tree/Territory"},
78 "Sales Person Tree": {"title": "Sales Person Tree", "route": "Tree/Sales Person"},
Rushabh Mehta430d1322014-05-31 10:36:04 +053079 }
Ankush Menat494bd9e2022-03-28 18:52:46 +053080 )