From e851346b4c0ed398fb4ff83f3512a743b8c9f056 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Tue, 10 Sep 2019 14:08:31 +0530 Subject: [PATCH] fix: dont make dashboards if company is not set (#18975) * fix: dont make dashboardss if company is not set * fix: function call * Update dashboard_charts.py --- .../setup/setup_wizard/data/dashboard_charts.py | 14 ++++++++++++-- .../setup_wizard/operations/install_fixtures.py | 5 +++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/erpnext/setup/setup_wizard/data/dashboard_charts.py b/erpnext/setup/setup_wizard/data/dashboard_charts.py index 41cfcb529e..bb8c1319bf 100644 --- a/erpnext/setup/setup_wizard/data/dashboard_charts.py +++ b/erpnext/setup/setup_wizard/data/dashboard_charts.py @@ -3,8 +3,18 @@ from frappe import _ import frappe import json +def get_company_for_dashboards(): + company = frappe.defaults.get_defaults().company + if company: + return company + else: + company_list = frappe.get_list("Company") + if company_list: + return company_list[0].name + return None + def get_default_dashboards(): - company = frappe.get_doc("Company", frappe.defaults.get_defaults().company) + company = frappe.get_doc("Company", get_company_for_dashboards()) 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) @@ -104,4 +114,4 @@ def get_default_dashboards(): def get_account(account_type, company): accounts = frappe.get_list("Account", filters={"account_type": account_type, "company": company}) if accounts: - return accounts[0].name \ No newline at end of file + return accounts[0].name diff --git a/erpnext/setup/setup_wizard/operations/install_fixtures.py b/erpnext/setup/setup_wizard/operations/install_fixtures.py index 6dbb89062e..b65716536d 100644 --- a/erpnext/setup/setup_wizard/operations/install_fixtures.py +++ b/erpnext/setup/setup_wizard/operations/install_fixtures.py @@ -501,6 +501,11 @@ def install_defaults(args=None): make_records(records) def add_dashboards(): + from erpnext.setup.setup_wizard.data.dashboard_charts import get_company_for_dashboards + + if not get_company_for_dashboards(): + return + from erpnext.setup.setup_wizard.data.dashboard_charts import get_default_dashboards from frappe.modules.import_file import import_file_by_path