blob: bb76f5a6f976dcf7c1dfa848790ef0f2667c6d0e [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
5from __future__ import unicode_literals
Chillar Anand915b3432021-09-02 16:44:59 +05306
Rushabh Mehta793ba6b2014-02-14 15:47:51 +05307import frappe
rohitwaghchaure7677ff02017-11-02 18:12:14 +05308from frappe.utils import cint
Rushabh Mehta74506e92013-03-25 17:52:14 +05309
Chillar Anand915b3432021-09-02 16:44:59 +053010
Rushabh Mehta74506e92013-03-25 17:52:14 +053011def boot_session(bootinfo):
12 """boot session - send website info if guest"""
Rushabh Mehta430d1322014-05-31 10:36:04 +053013
14 bootinfo.custom_css = frappe.db.get_value('Style Settings', None, 'custom_css') or ''
Rushabh Mehta74506e92013-03-25 17:52:14 +053015
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053016 if frappe.session['user']!='Guest':
Rushabh Mehta430d1322014-05-31 10:36:04 +053017 update_page_info(bootinfo)
18
19 load_country_and_currency(bootinfo)
rohitwaghchaureec9430d2017-08-02 18:16:13 +053020 bootinfo.sysdefaults.territory = frappe.db.get_single_value('Selling Settings',
Rushabh Mehtabf8e33112017-09-14 15:03:45 +053021 'territory')
rohitwaghchaureec9430d2017-08-02 18:16:13 +053022 bootinfo.sysdefaults.customer_group = frappe.db.get_single_value('Selling Settings',
Rushabh Mehtabf8e33112017-09-14 15:03:45 +053023 'customer_group')
rohitwaghchaure7677ff02017-11-02 18:12:14 +053024 bootinfo.sysdefaults.allow_stale = cint(frappe.db.get_single_value('Accounts Settings',
25 'allow_stale'))
tundebabzy9360f812018-02-26 07:53:41 +010026 bootinfo.sysdefaults.quotation_valid_till = cint(frappe.db.get_single_value('Selling Settings',
27 'default_valid_till'))
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:
Suraj Shettybfc195d2018-09-21 10:20:52 +053033 bootinfo.setup_complete = frappe.db.sql("""SELECT `name`
34 FROM `tabCompany`
35 LIMIT 1""") and 'Yes' or 'No'
Rushabh Mehta430d1322014-05-31 10:36:04 +053036
karthikeyan57fc60212019-07-04 22:46:16 +053037 bootinfo.docs += frappe.db.sql("""select name, default_currency, cost_center, default_selling_terms, default_buying_terms,
Gauravb30a9b12019-03-01 12:33:19 +053038 default_letter_head, default_bank_account, enable_perpetual_inventory, country from `tabCompany`""",
Rushabh Mehta5495bc52015-05-19 12:00:34 +053039 as_dict=1, update={"doctype":":Company"})
Rushabh Mehta9dd25b32013-09-03 17:36:41 +053040
rohitwaghchauree8358f32018-05-16 11:02:26 +053041 party_account_types = frappe.db.sql(""" select name, ifnull(account_type, '') from `tabParty Type`""")
42 bootinfo.party_account_types = frappe._dict(party_account_types)
43
Rushabh Mehta9dd25b32013-09-03 17:36:41 +053044def load_country_and_currency(bootinfo):
Rushabh Mehtaa504f062014-04-04 12:16:26 +053045 country = frappe.db.get_default("country")
46 if country and frappe.db.exists("Country", country):
Rushabh Mehta430d1322014-05-31 10:36:04 +053047 bootinfo.docs += [frappe.get_doc("Country", country)]
48
Rushabh Mehtae29192c2016-03-22 14:52:25 +053049 bootinfo.docs += frappe.db.sql("""select name, fraction, fraction_units,
50 number_format, smallest_currency_fraction_value, symbol from tabCurrency
Anand Doshi602e8252015-11-16 19:05:46 +053051 where enabled=1""", as_dict=1, update={"doctype":":Currency"})
Rushabh Mehta9dd25b32013-09-03 17:36:41 +053052
Rushabh Mehta430d1322014-05-31 10:36:04 +053053def update_page_info(bootinfo):
54 bootinfo.page_info.update({
55 "Chart of Accounts": {
56 "title": "Chart of Accounts",
Saurabh17022732016-06-21 13:19:17 +053057 "route": "Tree/Account"
Rushabh Mehta430d1322014-05-31 10:36:04 +053058 },
59 "Chart of Cost Centers": {
60 "title": "Chart of Cost Centers",
Saurabh17022732016-06-21 13:19:17 +053061 "route": "Tree/Cost Center"
Rushabh Mehta430d1322014-05-31 10:36:04 +053062 },
63 "Item Group Tree": {
64 "title": "Item Group Tree",
Saurabh17022732016-06-21 13:19:17 +053065 "route": "Tree/Item Group"
Rushabh Mehta430d1322014-05-31 10:36:04 +053066 },
67 "Customer Group Tree": {
68 "title": "Customer Group Tree",
Saurabh17022732016-06-21 13:19:17 +053069 "route": "Tree/Customer Group"
Rushabh Mehta430d1322014-05-31 10:36:04 +053070 },
71 "Territory Tree": {
72 "title": "Territory Tree",
Saurabh17022732016-06-21 13:19:17 +053073 "route": "Tree/Territory"
Rushabh Mehta430d1322014-05-31 10:36:04 +053074 },
75 "Sales Person Tree": {
76 "title": "Sales Person Tree",
Saurabh17022732016-06-21 13:19:17 +053077 "route": "Tree/Sales Person"
Rushabh Mehta430d1322014-05-31 10:36:04 +053078 }
79 })