From 5fd00e7113ab7323ed2ab10338f6e2f99e8c8561 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Wed, 31 May 2023 11:02:14 +0530 Subject: [PATCH] fix: Error while validating budget (#35487) fix: Error while validating budget (#35487) * fix: Error while validating budget * chore: remove print statement (cherry picked from commit 27d5e6a99bd72f2f44b31510da331d04fe3bc7bd) Co-authored-by: Deepesh Garg --- erpnext/accounts/doctype/budget/budget.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/doctype/budget/budget.py b/erpnext/accounts/doctype/budget/budget.py index ef2a7621f84..6cfd15d3ec8 100644 --- a/erpnext/accounts/doctype/budget/budget.py +++ b/erpnext/accounts/doctype/budget/budget.py @@ -125,14 +125,27 @@ def validate_expense_against_budget(args, expense_amount=0): if not args.account: return - for budget_against in ["project", "cost_center"] + get_accounting_dimensions(): + default_dimensions = [ + { + "fieldname": "project", + "document_type": "Project", + }, + { + "fieldname": "cost_center", + "document_type": "Cost Center", + }, + ] + + for dimension in default_dimensions + get_accounting_dimensions(as_list=False): + budget_against = dimension.get("fieldname") + if ( args.get(budget_against) and args.account and frappe.db.get_value("Account", {"name": args.account, "root_type": "Expense"}) ): - doctype = frappe.unscrub(budget_against) + doctype = dimension.get("document_type") if frappe.get_cached_value("DocType", doctype, "is_tree"): lft, rgt = frappe.db.get_value(doctype, args.get(budget_against), ["lft", "rgt"])