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 | |
| 5 | from __future__ import unicode_literals |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 6 | import frappe |
rohitwaghchaure | 7677ff0 | 2017-11-02 18:12:14 +0530 | [diff] [blame] | 7 | from frappe.utils import cint |
Rushabh Mehta | 74506e9 | 2013-03-25 17:52:14 +0530 | [diff] [blame] | 8 | |
| 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 | |
| 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 | |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +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 | |
| 17 | load_country_and_currency(bootinfo) |
rohitwaghchaure | ec9430d | 2017-08-02 18:16:13 +0530 | [diff] [blame] | 18 | bootinfo.sysdefaults.territory = frappe.db.get_single_value('Selling Settings', |
Rushabh Mehta | bf8e3311 | 2017-09-14 15:03:45 +0530 | [diff] [blame] | 19 | 'territory') |
rohitwaghchaure | ec9430d | 2017-08-02 18:16:13 +0530 | [diff] [blame] | 20 | bootinfo.sysdefaults.customer_group = frappe.db.get_single_value('Selling Settings', |
Rushabh Mehta | bf8e3311 | 2017-09-14 15:03:45 +0530 | [diff] [blame] | 21 | 'customer_group') |
rohitwaghchaure | 7677ff0 | 2017-11-02 18:12:14 +0530 | [diff] [blame] | 22 | bootinfo.sysdefaults.allow_stale = cint(frappe.db.get_single_value('Accounts Settings', |
| 23 | 'allow_stale')) |
tundebabzy | 9360f81 | 2018-02-26 07:53:41 +0100 | [diff] [blame] | 24 | bootinfo.sysdefaults.quotation_valid_till = cint(frappe.db.get_single_value('Selling Settings', |
| 25 | 'default_valid_till')) |
Rushabh Mehta | 430d132 | 2014-05-31 10:36:04 +0530 | [diff] [blame] | 26 | |
Rushabh Mehta | 430d132 | 2014-05-31 10:36:04 +0530 | [diff] [blame] | 27 | # if no company, show a dialog box to create a new company |
Suraj Shetty | bfc195d | 2018-09-21 10:20:52 +0530 | [diff] [blame] | 28 | bootinfo.customer_count = frappe.db.sql("""SELECT count(*) FROM `tabCustomer`""")[0][0] |
Rushabh Mehta | 430d132 | 2014-05-31 10:36:04 +0530 | [diff] [blame] | 29 | |
| 30 | if not bootinfo.customer_count: |
Suraj Shetty | bfc195d | 2018-09-21 10:20:52 +0530 | [diff] [blame] | 31 | bootinfo.setup_complete = frappe.db.sql("""SELECT `name` |
| 32 | FROM `tabCompany` |
| 33 | LIMIT 1""") and 'Yes' or 'No' |
Rushabh Mehta | 430d132 | 2014-05-31 10:36:04 +0530 | [diff] [blame] | 34 | |
karthikeyan5 | 7fc6021 | 2019-07-04 22:46:16 +0530 | [diff] [blame] | 35 | bootinfo.docs += frappe.db.sql("""select name, default_currency, cost_center, default_selling_terms, default_buying_terms, |
Gaurav | b30a9b1 | 2019-03-01 12:33:19 +0530 | [diff] [blame] | 36 | default_letter_head, default_bank_account, enable_perpetual_inventory, country from `tabCompany`""", |
Rushabh Mehta | 5495bc5 | 2015-05-19 12:00:34 +0530 | [diff] [blame] | 37 | as_dict=1, update={"doctype":":Company"}) |
Rushabh Mehta | 9dd25b3 | 2013-09-03 17:36:41 +0530 | [diff] [blame] | 38 | |
rohitwaghchaure | e8358f3 | 2018-05-16 11:02:26 +0530 | [diff] [blame] | 39 | party_account_types = frappe.db.sql(""" select name, ifnull(account_type, '') from `tabParty Type`""") |
| 40 | bootinfo.party_account_types = frappe._dict(party_account_types) |
| 41 | |
Rushabh Mehta | 9dd25b3 | 2013-09-03 17:36:41 +0530 | [diff] [blame] | 42 | def load_country_and_currency(bootinfo): |
Rushabh Mehta | a504f06 | 2014-04-04 12:16:26 +0530 | [diff] [blame] | 43 | country = frappe.db.get_default("country") |
| 44 | if country and frappe.db.exists("Country", country): |
Rushabh Mehta | 430d132 | 2014-05-31 10:36:04 +0530 | [diff] [blame] | 45 | bootinfo.docs += [frappe.get_doc("Country", country)] |
| 46 | |
Rushabh Mehta | e29192c | 2016-03-22 14:52:25 +0530 | [diff] [blame] | 47 | bootinfo.docs += frappe.db.sql("""select name, fraction, fraction_units, |
| 48 | number_format, smallest_currency_fraction_value, symbol from tabCurrency |
Anand Doshi | 602e825 | 2015-11-16 19:05:46 +0530 | [diff] [blame] | 49 | where enabled=1""", as_dict=1, update={"doctype":":Currency"}) |
Rushabh Mehta | 9dd25b3 | 2013-09-03 17:36:41 +0530 | [diff] [blame] | 50 | |
Rushabh Mehta | 430d132 | 2014-05-31 10:36:04 +0530 | [diff] [blame] | 51 | def update_page_info(bootinfo): |
| 52 | bootinfo.page_info.update({ |
| 53 | "Chart of Accounts": { |
| 54 | "title": "Chart of Accounts", |
Saurabh | 1702273 | 2016-06-21 13:19:17 +0530 | [diff] [blame] | 55 | "route": "Tree/Account" |
Rushabh Mehta | 430d132 | 2014-05-31 10:36:04 +0530 | [diff] [blame] | 56 | }, |
| 57 | "Chart of Cost Centers": { |
| 58 | "title": "Chart of Cost Centers", |
Saurabh | 1702273 | 2016-06-21 13:19:17 +0530 | [diff] [blame] | 59 | "route": "Tree/Cost Center" |
Rushabh Mehta | 430d132 | 2014-05-31 10:36:04 +0530 | [diff] [blame] | 60 | }, |
| 61 | "Item Group Tree": { |
| 62 | "title": "Item Group Tree", |
Saurabh | 1702273 | 2016-06-21 13:19:17 +0530 | [diff] [blame] | 63 | "route": "Tree/Item Group" |
Rushabh Mehta | 430d132 | 2014-05-31 10:36:04 +0530 | [diff] [blame] | 64 | }, |
| 65 | "Customer Group Tree": { |
| 66 | "title": "Customer Group Tree", |
Saurabh | 1702273 | 2016-06-21 13:19:17 +0530 | [diff] [blame] | 67 | "route": "Tree/Customer Group" |
Rushabh Mehta | 430d132 | 2014-05-31 10:36:04 +0530 | [diff] [blame] | 68 | }, |
| 69 | "Territory Tree": { |
| 70 | "title": "Territory Tree", |
Saurabh | 1702273 | 2016-06-21 13:19:17 +0530 | [diff] [blame] | 71 | "route": "Tree/Territory" |
Rushabh Mehta | 430d132 | 2014-05-31 10:36:04 +0530 | [diff] [blame] | 72 | }, |
| 73 | "Sales Person Tree": { |
| 74 | "title": "Sales Person Tree", |
Saurabh | 1702273 | 2016-06-21 13:19:17 +0530 | [diff] [blame] | 75 | "route": "Tree/Sales Person" |
Rushabh Mehta | 430d132 | 2014-05-31 10:36:04 +0530 | [diff] [blame] | 76 | } |
| 77 | }) |