From 626b345caf3116f35686736b28aab6ee11dbbcab Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Mon, 10 Feb 2025 17:36:31 +0530 Subject: [PATCH] refactor: better local variables and contextual error messages --- erpnext/controllers/budget_controller.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/erpnext/controllers/budget_controller.py b/erpnext/controllers/budget_controller.py index b396d44aa5d..33a7f5e286d 100644 --- a/erpnext/controllers/budget_controller.py +++ b/erpnext/controllers/budget_controller.py @@ -4,6 +4,7 @@ import frappe from frappe import _, qb from frappe.query_builder import Criterion from frappe.query_builder.functions import IfNull, Sum +from frappe.utils import get_link_to_form from erpnext.accounts.utils import get_fiscal_year @@ -184,18 +185,20 @@ class BudgetValidation: if requested_amount: self.to_validate[key]["requested_amount"] = requested_amount[0].amount - def stop_or_warn(self, validation_map): + def stop_or_warn(self, v_map): msg = [] - if validation_map.get("budget_doc").applicable_on_purchase_order and validation_map.get( - "ordered_amount" - ) > validation_map.get("budget_amount"): + budget = v_map.get("budget_doc") + if budget.applicable_on_purchase_order and v_map.get("ordered_amount") > v_map.get("budget_amount"): # TODO: handle monthly accumulation # action_if_accumulated_monthly_budget_exceeded_on_po, - if validation_map.get("budget_doc").action_if_annual_budget_exceeded_on_po == "Warn": + if budget.action_if_annual_budget_exceeded_on_po == "Warn": msg.append("some warning message") - if validation_map.get("budget_doc").action_if_annual_budget_exceeded_on_po == "Stop": - frappe.throw("Booking gone above budget", BudgetExceededError, title=_("Budget Exceeded")) + if budget.action_if_annual_budget_exceeded_on_po == "Stop": + _msg = _( + "Expenses have gone above budget: {}".format(get_link_to_form("Budget", budget.name)) + ) + frappe.throw(_msg, BudgetExceededError, title=_("Budget Exceeded")) def validate_for_overbooking(self): # TODO: Need to fetch historical amount and add them to the current document; GL effect is pending