diff --git a/erpnext/accounts/doctype/gl_entry/gl_entry.py b/erpnext/accounts/doctype/gl_entry/gl_entry.py index 89b184e89d0..98816a4a2d4 100644 --- a/erpnext/accounts/doctype/gl_entry/gl_entry.py +++ b/erpnext/accounts/doctype/gl_entry/gl_entry.py @@ -224,26 +224,23 @@ class GLEntry(Document): def validate_account_details(self, adv_adj): """Account must be ledger, active and not freezed""" - ret = frappe.db.sql( - """select is_group, docstatus, company - from tabAccount where name=%s""", - self.account, - as_dict=1, - )[0] + account = frappe.get_cached_value( + "Account", self.account, fieldname=["is_group", "docstatus", "company"], as_dict=True + ) - if ret.is_group == 1: + if account.is_group == 1: frappe.throw( _( """{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) ) - if ret.docstatus == 2: + if account.docstatus == 2: frappe.throw( _("{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( _("{0} {1}: Account {2} does not belong to Company {3}").format( self.voucher_type, self.voucher_no, self.account, self.company diff --git a/erpnext/accounts/doctype/payment_ledger_entry/payment_ledger_entry.py b/erpnext/accounts/doctype/payment_ledger_entry/payment_ledger_entry.py index 2bc44893c20..f48ee9ee6d1 100644 --- a/erpnext/accounts/doctype/payment_ledger_entry/payment_ledger_entry.py +++ b/erpnext/accounts/doctype/payment_ledger_entry/payment_ledger_entry.py @@ -51,38 +51,36 @@ class PaymentLedgerEntry(Document): # end: auto-generated types def validate_account(self): - valid_account = frappe.db.get_list( - "Account", - "name", - filters={"name": self.account, "account_type": self.account_type, "company": self.company}, - ignore_permissions=True, + account = frappe.get_cached_value( + "Account", self.account, fieldname=["account_type", "company"], as_dict=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)) def validate_account_details(self): """Account must be ledger, active and not freezed""" - ret = frappe.db.sql( - """select is_group, docstatus, company - from tabAccount where name=%s""", - self.account, - as_dict=1, - )[0] + account = frappe.get_cached_value( + "Account", self.account, fieldname=["is_group", "docstatus", "company"], as_dict=True + ) - if ret.is_group == 1: + if account.is_group == 1: frappe.throw( _( """{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) ) - if ret.docstatus == 2: + if account.docstatus == 2: frappe.throw( _("{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( _("{0} {1}: Account {2} does not belong to Company {3}").format( self.voucher_type, self.voucher_no, self.account, self.company