mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-03 04:09:11 +00:00
fix: use get_cached_value to avoid db call with db.exists
This commit is contained in:
@@ -286,9 +286,11 @@ def get_accounts_with_children(accounts):
|
||||
|
||||
all_accounts = []
|
||||
for d in accounts:
|
||||
if frappe.db.exists("Account", d):
|
||||
lft, rgt = frappe.get_cached_value("Account", d, ["lft", "rgt"])
|
||||
children = frappe.get_all("Account", filters={"lft": [">=", lft], "rgt": ["<=", rgt]})
|
||||
account_data = frappe.get_cached_value("Account", d, ["lft", "rgt"], as_dict=1)
|
||||
if account_data:
|
||||
children = frappe.get_all(
|
||||
"Account", filters={"lft": [">=", account_data.lft], "rgt": ["<=", account_data.rgt]}
|
||||
)
|
||||
all_accounts += [c.name for c in children]
|
||||
else:
|
||||
frappe.throw(_("Account: {0} does not exist").format(d))
|
||||
|
||||
Reference in New Issue
Block a user