fix: validated cost center in financial_statement (#18733)

* fix: validated cost center in financial_statement

* Update financial_statements.py
diff --git a/erpnext/accounts/report/financial_statements.py b/erpnext/accounts/report/financial_statements.py
index 7b9c939..3c8de60 100644
--- a/erpnext/accounts/report/financial_statements.py
+++ b/erpnext/accounts/report/financial_statements.py
@@ -425,9 +425,12 @@
 
 	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))