From c01ec7606d259f937b56a79e9b4bbe1547ebfdd6 Mon Sep 17 00:00:00 2001 From: Deepesh Garg <42651287+deepeshgarg007@users.noreply.github.com> Date: Mon, 6 Apr 2020 12:43:07 +0530 Subject: [PATCH] fix: Currency validation for default company accounts (#21094) * fix: Currency validation for default company accounts * fix: Improve message --- erpnext/setup/doctype/company/company.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/erpnext/setup/doctype/company/company.py b/erpnext/setup/doctype/company/company.py index 956deef928..8bcaa28707 100644 --- a/erpnext/setup/doctype/company/company.py +++ b/erpnext/setup/doctype/company/company.py @@ -16,6 +16,7 @@ from frappe.utils.nestedset import NestedSet from past.builtins import cmp import functools +from erpnext.accounts.doctype.account.account import get_account_currency class Company(NestedSet): nsm_parent_field = 'parent_company' @@ -73,18 +74,22 @@ class Company(NestedSet): def validate_default_accounts(self): accounts = [ - "default_bank_account", "default_cash_account", - "default_receivable_account", "default_payable_account", - "default_expense_account", "default_income_account", - "stock_received_but_not_billed", "stock_adjustment_account", - "expenses_included_in_valuation", "default_payroll_payable_account" + ["Default Bank Account", "default_bank_account"], ["Default Cash Account", "default_cash_account"], + ["Default Receivable Account", "default_receivable_account"], ["Default Payable Account", "default_payable_account"], + ["Default Expense Account", "default_expense_account"], ["Default Income Account", "default_income_account"], + ["Stock Received But Not Billed Account", "stock_received_but_not_billed"], ["Stock Adjustment Account", "stock_adjustment_account"], + ["Expense Included In Valuation Account", "expenses_included_in_valuation"], ["Default Payroll Payable Account", "default_payroll_payable_account"] ] - for field in accounts: - if self.get(field): - for_company = frappe.db.get_value("Account", self.get(field), "company") + for account in accounts: + if self.get(account[1]): + for_company = frappe.db.get_value("Account", self.get(account[1]), "company") if for_company != self.name: - frappe.throw(_("Account {0} does not belong to company: {1}").format(self.get(field), self.name)) + frappe.throw(_("Account {0} does not belong to company: {1}").format(self.get(account[1]), self.name)) + + if get_account_currency(self.get(account[1])) != self.default_currency: + frappe.throw(_("""{0} currency must be same as company's default currency. + Please select another account""").format(frappe.bold(account[0]))) def validate_currency(self): if self.is_new():