fix: do not setup charts if not setup_complete or no company found (#21670)
* fix: do not setup charts if not setup_complete or no company found Signed-off-by: Chinmay D. Pai <chinmaydpai@gmail.com> * chore: remove check for setup_complete moved the check for setup_complete to frappe Signed-off-by: Chinmay D. Pai <chinmaydpai@gmail.com> * chore: return an empty dict from get_data if company not set Signed-off-by: Chinmay D. Pai <chinmaydpai@gmail.com>
This commit is contained in:
parent
28c9468dad
commit
30f26b4457
@ -1,15 +1,22 @@
|
||||
# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors
|
||||
# License: GNU General Public License v3. See license.txt
|
||||
from erpnext import get_default_company
|
||||
|
||||
import frappe
|
||||
import json
|
||||
|
||||
|
||||
def get_data():
|
||||
return frappe._dict({
|
||||
"dashboards": get_dashboards(),
|
||||
"charts": get_charts(),
|
||||
data = frappe._dict({
|
||||
"dashboards": [],
|
||||
"charts": []
|
||||
})
|
||||
company = get_company_for_dashboards()
|
||||
if company:
|
||||
company_doc = frappe.get_doc("Company", company)
|
||||
data.dashboards = get_dashboards()
|
||||
data.charts = get_charts(company_doc)
|
||||
return data
|
||||
|
||||
def get_dashboards():
|
||||
return [{
|
||||
@ -24,8 +31,7 @@ def get_dashboards():
|
||||
]
|
||||
}]
|
||||
|
||||
def get_charts():
|
||||
company = frappe.get_doc("Company", get_company_for_dashboards())
|
||||
def get_charts(company):
|
||||
income_account = company.default_income_account or get_account("Income Account", company.name)
|
||||
expense_account = company.default_expense_account or get_account("Expense Account", company.name)
|
||||
bank_account = company.default_bank_account or get_account("Bank", company.name)
|
||||
@ -113,11 +119,9 @@ def get_account(account_type, company):
|
||||
return accounts[0].name
|
||||
|
||||
def get_company_for_dashboards():
|
||||
company = frappe.defaults.get_defaults().company
|
||||
if company:
|
||||
return company
|
||||
else:
|
||||
company = get_default_company()
|
||||
if not company:
|
||||
company_list = frappe.get_list("Company")
|
||||
if company_list:
|
||||
return company_list[0].name
|
||||
return None
|
||||
company = company_list[0].name
|
||||
return company
|
||||
|
Loading…
Reference in New Issue
Block a user