diff --git a/erpnext/accounts/doctype/budget/budget.py b/erpnext/accounts/doctype/budget/budget.py index 2eff6cbac02..69c1e1eb8f3 100644 --- a/erpnext/accounts/doctype/budget/budget.py +++ b/erpnext/accounts/doctype/budget/budget.py @@ -409,6 +409,10 @@ def validate_budget_records(args, budget_records, expense_amount): args["for_material_request"] = budget.for_material_request args["for_purchase_order"] = budget.for_purchase_order args["from_fiscal_year"], args["to_fiscal_year"] = budget.from_fiscal_year, budget.to_fiscal_year + args["budget_start_date"], args["budget_end_date"] = ( + budget.budget_start_date, + budget.budget_end_date, + ) if yearly_action in ("Stop", "Warn"): compare_expense_with_budget( diff --git a/erpnext/controllers/budget_controller.py b/erpnext/controllers/budget_controller.py index 0325f18b972..33afac4df22 100644 --- a/erpnext/controllers/budget_controller.py +++ b/erpnext/controllers/budget_controller.py @@ -162,16 +162,19 @@ class BudgetValidation: def get_budget_records(self) -> list: bud = qb.DocType("Budget") - bud_acc = qb.DocType("Budget Account") + query = ( qb.from_(bud) - .inner_join(bud_acc) - .on(bud.name == bud_acc.parent) .select( bud.name, bud.budget_against, bud.company, - bud.monthly_distribution, + bud.account, + bud.budget_amount, + bud.from_fiscal_year, + bud.to_fiscal_year, + bud.budget_start_date, + bud.budget_end_date, bud.applicable_on_material_request, bud.action_if_annual_budget_exceeded_on_mr, bud.action_if_accumulated_monthly_budget_exceeded_on_mr, @@ -184,13 +187,15 @@ class BudgetValidation: bud.applicable_on_cumulative_expense, bud.action_if_annual_exceeded_on_cumulative_expense, bud.action_if_accumulated_monthly_exceeded_on_cumulative_expense, - bud_acc.account, - bud_acc.budget_amount, ) - .where(bud.docstatus.eq(1) & bud.fiscal_year.eq(self.fiscal_year) & bud.company.eq(self.company)) + .where( + (bud.docstatus == 1) + & (bud.company == self.company) + & (bud.budget_start_date <= self.doc_date) + & (bud.budget_end_date >= self.doc_date) + ) ) - # add dimension fields for x in self.dimensions: query = query.select(bud[x.get("fieldname")]) @@ -312,8 +317,8 @@ class BudgetValidation: frappe.bold(key[2]), frappe.bold(frappe.unscrub(key[0])), frappe.bold(key[1]), - frappe.bold(fmt_money(annual_diff, currency=currency)), frappe.bold(fmt_money(budget_amt, currency=currency)), + frappe.bold(fmt_money(annual_diff, currency=currency)), ) self.execute_action(config.action_for_annual, _msg)