From 269868130fe5c462660a613cc18d265c7be5cf7d Mon Sep 17 00:00:00 2001 From: Anurag Mishra <32095923+Anurag810@users.noreply.github.com> Date: Mon, 19 Aug 2019 10:27:53 +0530 Subject: [PATCH] fix: validated cost center in financial_statement (#18732) * fix: validated cost center in financial_statement * Update financial_statements.py --- erpnext/accounts/report/financial_statements.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/erpnext/accounts/report/financial_statements.py b/erpnext/accounts/report/financial_statements.py index 9765310fc9b..c615f7b23fb 100644 --- a/erpnext/accounts/report/financial_statements.py +++ b/erpnext/accounts/report/financial_statements.py @@ -407,9 +407,12 @@ def get_cost_centers_with_children(cost_centers): all_cost_centers = [] for d in cost_centers: - lft, rgt = frappe.db.get_value("Cost Center", d, ["lft", "rgt"]) - children = frappe.get_all("Cost Center", filters={"lft": [">=", lft], "rgt": ["<=", rgt]}) - all_cost_centers += [c.name for c in children] + if frappe.db.exists("Cost Center", d): + lft, rgt = frappe.db.get_value("Cost Center", d, ["lft", "rgt"]) + children = frappe.get_all("Cost Center", filters={"lft": [">=", lft], "rgt": ["<=", rgt]}) + all_cost_centers += [c.name for c in children] + else: + frappe.throw(_("Cost Center: {0} does not exist".format(d))) return list(set(all_cost_centers))