fix: Currency validation for default company accounts (#21094)
* fix: Currency validation for default company accounts * fix: Improve message
This commit is contained in:
parent
b37f0bb052
commit
c01ec7606d
@ -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():
|
||||
|
Loading…
Reference in New Issue
Block a user