refactor: validation to force accounts to be on same currency
This commit is contained in:
@@ -138,6 +138,7 @@ class Supplier(TransactionBase):
|
|||||||
validate_party_accounts(self)
|
validate_party_accounts(self)
|
||||||
self.validate_internal_supplier()
|
self.validate_internal_supplier()
|
||||||
self.add_role_for_user()
|
self.add_role_for_user()
|
||||||
|
self.validate_currency_for_receivable_payable_and_advance_account()
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_supplier_group_details(self):
|
def get_supplier_group_details(self):
|
||||||
|
|||||||
@@ -144,6 +144,7 @@ class Customer(TransactionBase):
|
|||||||
self.validate_default_bank_account()
|
self.validate_default_bank_account()
|
||||||
self.validate_internal_customer()
|
self.validate_internal_customer()
|
||||||
self.add_role_for_user()
|
self.add_role_for_user()
|
||||||
|
self.validate_currency_for_receivable_payable_and_advance_account()
|
||||||
|
|
||||||
# set loyalty program tier
|
# set loyalty program tier
|
||||||
if frappe.db.exists("Customer", self.name):
|
if frappe.db.exists("Customer", self.name):
|
||||||
|
|||||||
@@ -168,6 +168,63 @@ class TransactionBase(StatusUpdater):
|
|||||||
if len(child_table_values) > 1:
|
if len(child_table_values) > 1:
|
||||||
self.set(default_field, None)
|
self.set(default_field, None)
|
||||||
|
|
||||||
|
def validate_currency_for_receivable_payable_and_advance_account(self):
|
||||||
|
if self.doctype in ["Customer", "Supplier"]:
|
||||||
|
account_type = "Receivable" if self.doctype == "Customer" else "Payable"
|
||||||
|
for x in self.accounts:
|
||||||
|
company_default_currency = frappe.get_cached_value("Company", x.company, "default_currency")
|
||||||
|
receivable_payable_account_currency = None
|
||||||
|
advance_account_currency = None
|
||||||
|
|
||||||
|
if x.account:
|
||||||
|
receivable_payable_account_currency = frappe.get_cached_value(
|
||||||
|
"Account", x.account, "account_currency"
|
||||||
|
)
|
||||||
|
|
||||||
|
if x.advance_account:
|
||||||
|
advance_account_currency = frappe.get_cached_value(
|
||||||
|
"Account", x.advance_account, "account_currency"
|
||||||
|
)
|
||||||
|
if receivable_payable_account_currency and (
|
||||||
|
receivable_payable_account_currency != self.default_currency
|
||||||
|
and receivable_payable_account_currency != company_default_currency
|
||||||
|
):
|
||||||
|
frappe.throw(
|
||||||
|
_(
|
||||||
|
"{0} Account must be in either customer billing currency: {1} or Company default currency: {2}"
|
||||||
|
).format(
|
||||||
|
account_type,
|
||||||
|
frappe.bold(self.default_currency),
|
||||||
|
frappe.bold(company_default_currency),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
if advance_account_currency and (
|
||||||
|
advance_account_currency != self.default_currency
|
||||||
|
and advance_account_currency != company_default_currency
|
||||||
|
):
|
||||||
|
frappe.throw(
|
||||||
|
_(
|
||||||
|
"Advance Account must be in either customer billing currency: {0} or Company default currency: {1}"
|
||||||
|
).format(frappe.bold(self.default_currency), frappe.bold(company_default_currency))
|
||||||
|
)
|
||||||
|
|
||||||
|
if (
|
||||||
|
receivable_payable_account_currency
|
||||||
|
and advance_account_currency
|
||||||
|
and receivable_payable_account_currency != advance_account_currency
|
||||||
|
):
|
||||||
|
frappe.throw(
|
||||||
|
_(
|
||||||
|
"Both {0} Account: {1} and Advance Account: {2} must be of same currency for company: {3}"
|
||||||
|
).format(
|
||||||
|
account_type,
|
||||||
|
frappe.bold(x.account),
|
||||||
|
frappe.bold(x.advance_account),
|
||||||
|
frappe.bold(x.company),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def delete_events(ref_type, ref_name):
|
def delete_events(ref_type, ref_name):
|
||||||
events = (
|
events = (
|
||||||
|
|||||||
Reference in New Issue
Block a user