blob: 316430610915c45f6c77679edabbf1196700b88f [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
Rushabh Mehta793ba6b2014-02-14 15:47:51 +05306import frappe
Rushabh Mehta74506e92013-03-25 17:52:14 +05307
8def boot_session(bootinfo):
9 """boot session - send website info if guest"""
Rushabh Mehta430d1322014-05-31 10:36:04 +053010
11 bootinfo.custom_css = frappe.db.get_value('Style Settings', None, 'custom_css') or ''
12 bootinfo.website_settings = frappe.get_doc('Website Settings')
Rushabh Mehta74506e92013-03-25 17:52:14 +053013
Rushabh Mehta793ba6b2014-02-14 15:47:51 +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)
rohitwaghchaureec9430d2017-08-02 18:16:13 +053018 bootinfo.sysdefaults.territory = frappe.db.get_single_value('Selling Settings',
Rushabh Mehtabf8e33112017-09-14 15:03:45 +053019 'territory')
rohitwaghchaureec9430d2017-08-02 18:16:13 +053020 bootinfo.sysdefaults.customer_group = frappe.db.get_single_value('Selling Settings',
Rushabh Mehtabf8e33112017-09-14 15:03:45 +053021 'customer_group')
Rushabh Mehta430d1322014-05-31 10:36:04 +053022
23 bootinfo.notification_settings = frappe.get_doc("Notification Control",
24 "Notification Control")
25
26 # if no company, show a dialog box to create a new company
Rushabh Mehta9872d8c2016-11-21 21:04:47 +053027 bootinfo.customer_count = frappe.db.sql("""select count(*) from tabCustomer""")[0][0]
Rushabh Mehta430d1322014-05-31 10:36:04 +053028
29 if not bootinfo.customer_count:
30 bootinfo.setup_complete = frappe.db.sql("""select name from
Rushabh Mehta2f7e1ab2013-06-26 17:20:12 +053031 tabCompany limit 1""") and 'Yes' or 'No'
Rushabh Mehta430d1322014-05-31 10:36:04 +053032
Rohit Waghchaurea5f40942017-06-16 15:21:36 +053033 bootinfo.docs += frappe.db.sql("""select name, default_currency, cost_center, default_terms,
34 default_letter_head, default_bank_account, enable_perpetual_inventory from `tabCompany`""",
Rushabh Mehta5495bc52015-05-19 12:00:34 +053035 as_dict=1, update={"doctype":":Company"})
Rushabh Mehta9dd25b32013-09-03 17:36:41 +053036
37def load_country_and_currency(bootinfo):
Rushabh Mehtaa504f062014-04-04 12:16:26 +053038 country = frappe.db.get_default("country")
39 if country and frappe.db.exists("Country", country):
Rushabh Mehta430d1322014-05-31 10:36:04 +053040 bootinfo.docs += [frappe.get_doc("Country", country)]
41
Rushabh Mehtae29192c2016-03-22 14:52:25 +053042 bootinfo.docs += frappe.db.sql("""select name, fraction, fraction_units,
43 number_format, smallest_currency_fraction_value, symbol from tabCurrency
Anand Doshi602e8252015-11-16 19:05:46 +053044 where enabled=1""", as_dict=1, update={"doctype":":Currency"})
Rushabh Mehta9dd25b32013-09-03 17:36:41 +053045
Rushabh Mehta430d1322014-05-31 10:36:04 +053046def update_page_info(bootinfo):
47 bootinfo.page_info.update({
48 "Chart of Accounts": {
49 "title": "Chart of Accounts",
Saurabh17022732016-06-21 13:19:17 +053050 "route": "Tree/Account"
Rushabh Mehta430d1322014-05-31 10:36:04 +053051 },
52 "Chart of Cost Centers": {
53 "title": "Chart of Cost Centers",
Saurabh17022732016-06-21 13:19:17 +053054 "route": "Tree/Cost Center"
Rushabh Mehta430d1322014-05-31 10:36:04 +053055 },
56 "Item Group Tree": {
57 "title": "Item Group Tree",
Saurabh17022732016-06-21 13:19:17 +053058 "route": "Tree/Item Group"
Rushabh Mehta430d1322014-05-31 10:36:04 +053059 },
60 "Customer Group Tree": {
61 "title": "Customer Group Tree",
Saurabh17022732016-06-21 13:19:17 +053062 "route": "Tree/Customer Group"
Rushabh Mehta430d1322014-05-31 10:36:04 +053063 },
64 "Territory Tree": {
65 "title": "Territory Tree",
Saurabh17022732016-06-21 13:19:17 +053066 "route": "Tree/Territory"
Rushabh Mehta430d1322014-05-31 10:36:04 +053067 },
68 "Sales Person Tree": {
69 "title": "Sales Person Tree",
Saurabh17022732016-06-21 13:19:17 +053070 "route": "Tree/Sales Person"
Rushabh Mehta430d1322014-05-31 10:36:04 +053071 }
72 })