fix: use get_cached_value to avoid db call with db.exists

This commit is contained in:
Daizy Modi
2022-11-17 19:14:10 +05:30
parent 678a4c33da
commit fdfe5cbf93
3 changed files with 15 additions and 9 deletions

View File

@@ -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))