mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-24 07:29:22 +00:00
perf: use cached value for account validations in gl and ple
This commit is contained in:
@@ -224,26 +224,23 @@ class GLEntry(Document):
|
|||||||
def validate_account_details(self, adv_adj):
|
def validate_account_details(self, adv_adj):
|
||||||
"""Account must be ledger, active and not freezed"""
|
"""Account must be ledger, active and not freezed"""
|
||||||
|
|
||||||
ret = frappe.db.sql(
|
account = frappe.get_cached_value(
|
||||||
"""select is_group, docstatus, company
|
"Account", self.account, fieldname=["is_group", "docstatus", "company"], as_dict=True
|
||||||
from tabAccount where name=%s""",
|
)
|
||||||
self.account,
|
|
||||||
as_dict=1,
|
|
||||||
)[0]
|
|
||||||
|
|
||||||
if ret.is_group == 1:
|
if account.is_group == 1:
|
||||||
frappe.throw(
|
frappe.throw(
|
||||||
_(
|
_(
|
||||||
"""{0} {1}: Account {2} is a Group Account and group accounts cannot be used in transactions"""
|
"""{0} {1}: Account {2} is a Group Account and group accounts cannot be used in transactions"""
|
||||||
).format(self.voucher_type, self.voucher_no, self.account)
|
).format(self.voucher_type, self.voucher_no, self.account)
|
||||||
)
|
)
|
||||||
|
|
||||||
if ret.docstatus == 2:
|
if account.docstatus == 2:
|
||||||
frappe.throw(
|
frappe.throw(
|
||||||
_("{0} {1}: Account {2} is inactive").format(self.voucher_type, self.voucher_no, self.account)
|
_("{0} {1}: Account {2} is inactive").format(self.voucher_type, self.voucher_no, self.account)
|
||||||
)
|
)
|
||||||
|
|
||||||
if ret.company != self.company:
|
if account.company != self.company:
|
||||||
frappe.throw(
|
frappe.throw(
|
||||||
_("{0} {1}: Account {2} does not belong to Company {3}").format(
|
_("{0} {1}: Account {2} does not belong to Company {3}").format(
|
||||||
self.voucher_type, self.voucher_no, self.account, self.company
|
self.voucher_type, self.voucher_no, self.account, self.company
|
||||||
|
|||||||
@@ -51,38 +51,36 @@ class PaymentLedgerEntry(Document):
|
|||||||
# end: auto-generated types
|
# end: auto-generated types
|
||||||
|
|
||||||
def validate_account(self):
|
def validate_account(self):
|
||||||
valid_account = frappe.db.get_list(
|
account = frappe.get_cached_value(
|
||||||
"Account",
|
"Account", self.account, fieldname=["account_type", "company"], as_dict=True
|
||||||
"name",
|
|
||||||
filters={"name": self.account, "account_type": self.account_type, "company": self.company},
|
|
||||||
ignore_permissions=True,
|
|
||||||
)
|
)
|
||||||
if not valid_account:
|
|
||||||
|
if account.company != self.company:
|
||||||
|
frappe.throw(_("{0} account is not of company {1}").format(self.account, self.company))
|
||||||
|
|
||||||
|
if account.account_type != self.account_type:
|
||||||
frappe.throw(_("{0} account is not of type {1}").format(self.account, self.account_type))
|
frappe.throw(_("{0} account is not of type {1}").format(self.account, self.account_type))
|
||||||
|
|
||||||
def validate_account_details(self):
|
def validate_account_details(self):
|
||||||
"""Account must be ledger, active and not freezed"""
|
"""Account must be ledger, active and not freezed"""
|
||||||
|
|
||||||
ret = frappe.db.sql(
|
account = frappe.get_cached_value(
|
||||||
"""select is_group, docstatus, company
|
"Account", self.account, fieldname=["is_group", "docstatus", "company"], as_dict=True
|
||||||
from tabAccount where name=%s""",
|
)
|
||||||
self.account,
|
|
||||||
as_dict=1,
|
|
||||||
)[0]
|
|
||||||
|
|
||||||
if ret.is_group == 1:
|
if account.is_group == 1:
|
||||||
frappe.throw(
|
frappe.throw(
|
||||||
_(
|
_(
|
||||||
"""{0} {1}: Account {2} is a Group Account and group accounts cannot be used in transactions"""
|
"""{0} {1}: Account {2} is a Group Account and group accounts cannot be used in transactions"""
|
||||||
).format(self.voucher_type, self.voucher_no, self.account)
|
).format(self.voucher_type, self.voucher_no, self.account)
|
||||||
)
|
)
|
||||||
|
|
||||||
if ret.docstatus == 2:
|
if account.docstatus == 2:
|
||||||
frappe.throw(
|
frappe.throw(
|
||||||
_("{0} {1}: Account {2} is inactive").format(self.voucher_type, self.voucher_no, self.account)
|
_("{0} {1}: Account {2} is inactive").format(self.voucher_type, self.voucher_no, self.account)
|
||||||
)
|
)
|
||||||
|
|
||||||
if ret.company != self.company:
|
if account.company != self.company:
|
||||||
frappe.throw(
|
frappe.throw(
|
||||||
_("{0} {1}: Account {2} does not belong to Company {3}").format(
|
_("{0} {1}: Account {2} does not belong to Company {3}").format(
|
||||||
self.voucher_type, self.voucher_no, self.account, self.company
|
self.voucher_type, self.voucher_no, self.account, self.company
|
||||||
|
|||||||
Reference in New Issue
Block a user