mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-03 13:38:27 +00:00
refactor: validation in Supplier Group
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
|
||||
import frappe
|
||||
from frappe import _
|
||||
from frappe.utils.nestedset import NestedSet, get_root_of
|
||||
|
||||
|
||||
@@ -32,6 +33,51 @@ class SupplierGroup(NestedSet):
|
||||
def validate(self):
|
||||
if not self.parent_supplier_group:
|
||||
self.parent_supplier_group = get_root_of("Supplier Group")
|
||||
self.validate_currency_for_payable_and_advance_account()
|
||||
|
||||
def validate_currency_for_payable_and_advance_account(self):
|
||||
for x in self.accounts:
|
||||
company_default_currency = frappe.get_cached_value("Company", x.company, "default_currency")
|
||||
payable_account_currency = None
|
||||
advance_account_currency = None
|
||||
|
||||
if x.account:
|
||||
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 payable_account_currency and payable_account_currency != company_default_currency:
|
||||
frappe.throw(
|
||||
_("Payable Account: {0} must be in Company default currency: {1}").format(
|
||||
frappe.bold(x.account),
|
||||
frappe.bold(company_default_currency),
|
||||
)
|
||||
)
|
||||
|
||||
if advance_account_currency and advance_account_currency != company_default_currency:
|
||||
frappe.throw(
|
||||
_("Advance Account: {0} must be in Company default currency: {1}").format(
|
||||
frappe.bold(x.advance_account), frappe.bold(company_default_currency)
|
||||
)
|
||||
)
|
||||
|
||||
if (
|
||||
payable_account_currency
|
||||
and advance_account_currency
|
||||
and payable_account_currency != advance_account_currency
|
||||
):
|
||||
frappe.throw(
|
||||
_(
|
||||
"Both Payable Account: {0} and Advance Account: {1} must be of same currency for company: {2}"
|
||||
).format(
|
||||
frappe.bold(x.account),
|
||||
frappe.bold(x.advance_account),
|
||||
frappe.bold(x.company),
|
||||
)
|
||||
)
|
||||
|
||||
def on_update(self):
|
||||
NestedSet.on_update(self)
|
||||
|
||||
Reference in New Issue
Block a user