diff --git a/erpnext/setup/setup_wizard/data/dashboard_charts.py b/erpnext/setup/setup_wizard/data/dashboard_charts.py index 41cfcb529e1..bb8c1319bf3 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 6dbb89062ea..b65716536d9 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