blob: 4b47398fb543c006900cf88649e207be7cd5d22a [file] [log] [blame]
Rushabh Mehtaad45e312013-11-20 12:59:58 +05301# Copyright (c) 2013, Web Notes 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 Mehta793ba6b2014-02-14 15:47:51 +053010 import frappe
11 import frappe.model.doc
Rushabh Mehta74506e92013-03-25 17:52:14 +053012
Anand Doshie9baaa62014-02-26 12:35:33 +053013 bootinfo['custom_css'] = frappe.db.get_value('Style Settings', None, 'custom_css') or ''
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053014 bootinfo['website_settings'] = frappe.model.doc.getsingle('Website Settings')
Rushabh Mehta74506e92013-03-25 17:52:14 +053015
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053016 if frappe.session['user']!='Guest':
Rushabh Mehta74506e92013-03-25 17:52:14 +053017 bootinfo['letter_heads'] = get_letter_heads()
Rushabh Mehta9dd25b32013-09-03 17:36:41 +053018
19 load_country_and_currency(bootinfo)
20
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053021 import frappe.model.doctype
22 bootinfo['notification_settings'] = frappe.doc("Notification Control",
Rushabh Mehta74506e92013-03-25 17:52:14 +053023 "Notification Control").get_values()
Rushabh Mehta27c40792013-04-03 15:21:44 +053024
Rushabh Mehta74506e92013-03-25 17:52:14 +053025 # if no company, show a dialog box to create a new company
Anand Doshie9baaa62014-02-26 12:35:33 +053026 bootinfo["customer_count"] = frappe.db.sql("""select count(*) from tabCustomer""")[0][0]
Rushabh Mehta2f7e1ab2013-06-26 17:20:12 +053027
28 if not bootinfo["customer_count"]:
Anand Doshie9baaa62014-02-26 12:35:33 +053029 bootinfo['setup_complete'] = frappe.db.sql("""select name from
Rushabh Mehta2f7e1ab2013-06-26 17:20:12 +053030 tabCompany limit 1""") and 'Yes' or 'No'
31
Anand Doshie9baaa62014-02-26 12:35:33 +053032 bootinfo['docs'] += frappe.db.sql("""select name, default_currency, cost_center
Anand Doshiaeef7bd2013-04-19 16:21:55 +053033 from `tabCompany`""", as_dict=1, update={"doctype":":Company"})
Rushabh Mehta9dd25b32013-09-03 17:36:41 +053034
35def load_country_and_currency(bootinfo):
36 if bootinfo.control_panel.country and \
Anand Doshie9baaa62014-02-26 12:35:33 +053037 frappe.db.exists("Country", bootinfo.control_panel.country):
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053038 bootinfo["docs"] += [frappe.doc("Country", bootinfo.control_panel.country)]
Rushabh Mehta9dd25b32013-09-03 17:36:41 +053039
Anand Doshie9baaa62014-02-26 12:35:33 +053040 bootinfo["docs"] += frappe.db.sql("""select * from tabCurrency
Rushabh Mehta9dd25b32013-09-03 17:36:41 +053041 where ifnull(enabled,0)=1""", as_dict=1, update={"doctype":":Currency"})
42
Rushabh Mehta74506e92013-03-25 17:52:14 +053043def get_letter_heads():
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053044 import frappe
Anand Doshie9baaa62014-02-26 12:35:33 +053045 ret = frappe.db.sql("""select name, content from `tabLetter Head`
Rushabh Mehta74506e92013-03-25 17:52:14 +053046 where ifnull(disabled,0)=0""")
47 return dict(ret)
Pratik Vyascfed8c42013-09-21 15:16:47 +053048