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
|
# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors
|
||||||
# License: GNU General Public License v3. See license.txt
|
# License: GNU General Public License v3. See license.txt
|
||||||
|
from erpnext import get_default_company
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
|
||||||
def get_data():
|
def get_data():
|
||||||
return frappe._dict({
|
data = frappe._dict({
|
||||||
"dashboards": get_dashboards(),
|
"dashboards": [],
|
||||||
"charts": get_charts(),
|
"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():
|
def get_dashboards():
|
||||||
return [{
|
return [{
|
||||||
@ -24,88 +31,87 @@ def get_dashboards():
|
|||||||
]
|
]
|
||||||
}]
|
}]
|
||||||
|
|
||||||
def get_charts():
|
def get_charts(company):
|
||||||
company = frappe.get_doc("Company", get_company_for_dashboards())
|
|
||||||
income_account = company.default_income_account or get_account("Income Account", company.name)
|
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)
|
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)
|
bank_account = company.default_bank_account or get_account("Bank", company.name)
|
||||||
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
"doctype": "Dashboard Chart",
|
"doctype": "Dashboard Chart",
|
||||||
"time_interval": "Quarterly",
|
"time_interval": "Quarterly",
|
||||||
"name": "Income",
|
"name": "Income",
|
||||||
"chart_name": "Income",
|
"chart_name": "Income",
|
||||||
"timespan": "Last Year",
|
"timespan": "Last Year",
|
||||||
"color": None,
|
"color": None,
|
||||||
"filters_json": json.dumps({"company": company.name, "account": income_account}),
|
"filters_json": json.dumps({"company": company.name, "account": income_account}),
|
||||||
"source": "Account Balance Timeline",
|
"source": "Account Balance Timeline",
|
||||||
"chart_type": "Custom",
|
"chart_type": "Custom",
|
||||||
"timeseries": 1,
|
"timeseries": 1,
|
||||||
"owner": "Administrator",
|
"owner": "Administrator",
|
||||||
"type": "Line"
|
"type": "Line"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"doctype": "Dashboard Chart",
|
"doctype": "Dashboard Chart",
|
||||||
"time_interval": "Quarterly",
|
"time_interval": "Quarterly",
|
||||||
"name": "Expenses",
|
"name": "Expenses",
|
||||||
"chart_name": "Expenses",
|
"chart_name": "Expenses",
|
||||||
"timespan": "Last Year",
|
"timespan": "Last Year",
|
||||||
"color": None,
|
"color": None,
|
||||||
"filters_json": json.dumps({"company": company.name, "account": expense_account}),
|
"filters_json": json.dumps({"company": company.name, "account": expense_account}),
|
||||||
"source": "Account Balance Timeline",
|
"source": "Account Balance Timeline",
|
||||||
"chart_type": "Custom",
|
"chart_type": "Custom",
|
||||||
"timeseries": 1,
|
"timeseries": 1,
|
||||||
"owner": "Administrator",
|
"owner": "Administrator",
|
||||||
"type": "Line"
|
"type": "Line"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"doctype": "Dashboard Chart",
|
"doctype": "Dashboard Chart",
|
||||||
"time_interval": "Quarterly",
|
"time_interval": "Quarterly",
|
||||||
"name": "Bank Balance",
|
"name": "Bank Balance",
|
||||||
"chart_name": "Bank Balance",
|
"chart_name": "Bank Balance",
|
||||||
"timespan": "Last Year",
|
"timespan": "Last Year",
|
||||||
"color": "#ffb868",
|
"color": "#ffb868",
|
||||||
"filters_json": json.dumps({"company": company.name, "account": bank_account}),
|
"filters_json": json.dumps({"company": company.name, "account": bank_account}),
|
||||||
"source": "Account Balance Timeline",
|
"source": "Account Balance Timeline",
|
||||||
"chart_type": "Custom",
|
"chart_type": "Custom",
|
||||||
"timeseries": 1,
|
"timeseries": 1,
|
||||||
"owner": "Administrator",
|
"owner": "Administrator",
|
||||||
"type": "Line"
|
"type": "Line"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"doctype": "Dashboard Chart",
|
"doctype": "Dashboard Chart",
|
||||||
"time_interval": "Monthly",
|
"time_interval": "Monthly",
|
||||||
"name": "Incoming Bills (Purchase Invoice)",
|
"name": "Incoming Bills (Purchase Invoice)",
|
||||||
"chart_name": "Incoming Bills (Purchase Invoice)",
|
"chart_name": "Incoming Bills (Purchase Invoice)",
|
||||||
"timespan": "Last Year",
|
"timespan": "Last Year",
|
||||||
"color": "#a83333",
|
"color": "#a83333",
|
||||||
"value_based_on": "base_grand_total",
|
"value_based_on": "base_grand_total",
|
||||||
"filters_json": json.dumps({}),
|
"filters_json": json.dumps({}),
|
||||||
"chart_type": "Sum",
|
"chart_type": "Sum",
|
||||||
"timeseries": 1,
|
"timeseries": 1,
|
||||||
"based_on": "posting_date",
|
"based_on": "posting_date",
|
||||||
"owner": "Administrator",
|
"owner": "Administrator",
|
||||||
"document_type": "Purchase Invoice",
|
"document_type": "Purchase Invoice",
|
||||||
"type": "Bar"
|
"type": "Bar"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"doctype": "Dashboard Chart",
|
"doctype": "Dashboard Chart",
|
||||||
"time_interval": "Monthly",
|
"time_interval": "Monthly",
|
||||||
"name": "Outgoing Bills (Sales Invoice)",
|
"name": "Outgoing Bills (Sales Invoice)",
|
||||||
"chart_name": "Outgoing Bills (Sales Invoice)",
|
"chart_name": "Outgoing Bills (Sales Invoice)",
|
||||||
"timespan": "Last Year",
|
"timespan": "Last Year",
|
||||||
"color": "#7b933d",
|
"color": "#7b933d",
|
||||||
"value_based_on": "base_grand_total",
|
"value_based_on": "base_grand_total",
|
||||||
"filters_json": json.dumps({}),
|
"filters_json": json.dumps({}),
|
||||||
"chart_type": "Sum",
|
"chart_type": "Sum",
|
||||||
"timeseries": 1,
|
"timeseries": 1,
|
||||||
"based_on": "posting_date",
|
"based_on": "posting_date",
|
||||||
"owner": "Administrator",
|
"owner": "Administrator",
|
||||||
"document_type": "Sales Invoice",
|
"document_type": "Sales Invoice",
|
||||||
"type": "Bar"
|
"type": "Bar"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
def get_account(account_type, company):
|
def get_account(account_type, company):
|
||||||
accounts = frappe.get_list("Account", filters={"account_type": account_type, "company": company})
|
accounts = frappe.get_list("Account", filters={"account_type": account_type, "company": company})
|
||||||
@ -113,11 +119,9 @@ def get_account(account_type, company):
|
|||||||
return accounts[0].name
|
return accounts[0].name
|
||||||
|
|
||||||
def get_company_for_dashboards():
|
def get_company_for_dashboards():
|
||||||
company = frappe.defaults.get_defaults().company
|
company = get_default_company()
|
||||||
if company:
|
if not company:
|
||||||
return company
|
|
||||||
else:
|
|
||||||
company_list = frappe.get_list("Company")
|
company_list = frappe.get_list("Company")
|
||||||
if company_list:
|
if company_list:
|
||||||
return company_list[0].name
|
company = company_list[0].name
|
||||||
return None
|
return company
|
||||||
|
Loading…
Reference in New Issue
Block a user