mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-03 04:09:11 +00:00
refactor: validation in Supplier Group
(cherry picked from commit 107b614518)
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
|
from frappe import _
|
||||||
from frappe.utils.nestedset import NestedSet, get_root_of
|
from frappe.utils.nestedset import NestedSet, get_root_of
|
||||||
|
|
||||||
|
|
||||||
@@ -32,6 +33,51 @@ class SupplierGroup(NestedSet):
|
|||||||
def validate(self):
|
def validate(self):
|
||||||
if not self.parent_supplier_group:
|
if not self.parent_supplier_group:
|
||||||
self.parent_supplier_group = get_root_of("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):
|
def on_update(self):
|
||||||
NestedSet.on_update(self)
|
NestedSet.on_update(self)
|
||||||
|
|||||||
Reference in New Issue
Block a user