From ca07ec79eed4d817b9c221470b8382a730cd7c58 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Thu, 15 May 2025 16:12:55 +0530 Subject: [PATCH 1/2] fix(test): dormant broken test in Budget --- erpnext/accounts/doctype/budget/budget.py | 2 +- erpnext/accounts/doctype/budget/test_budget.py | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/erpnext/accounts/doctype/budget/budget.py b/erpnext/accounts/doctype/budget/budget.py index 2f2b549cf46..8e58f294505 100644 --- a/erpnext/accounts/doctype/budget/budget.py +++ b/erpnext/accounts/doctype/budget/budget.py @@ -510,7 +510,7 @@ def get_accumulated_monthly_budget(monthly_distribution, posting_date, fiscal_ye accumulated_percentage = 0.0 while dt <= getdate(posting_date): - if monthly_distribution: + if monthly_distribution and distribution: accumulated_percentage += distribution.get(getdate(dt).strftime("%B"), 0) else: accumulated_percentage += 100.0 / 12 diff --git a/erpnext/accounts/doctype/budget/test_budget.py b/erpnext/accounts/doctype/budget/test_budget.py index 6fa655c0a36..9e3df0e35f2 100644 --- a/erpnext/accounts/doctype/budget/test_budget.py +++ b/erpnext/accounts/doctype/budget/test_budget.py @@ -5,7 +5,11 @@ import unittest import frappe from frappe.utils import now_datetime, nowdate -from erpnext.accounts.doctype.budget.budget import BudgetError, get_actual_expense +from erpnext.accounts.doctype.budget.budget import ( + BudgetError, + get_accumulated_monthly_budget, + get_actual_expense, +) from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journal_entry from erpnext.accounts.utils import get_fiscal_year from erpnext.buying.doctype.purchase_order.test_purchase_order import create_purchase_order @@ -67,10 +71,13 @@ class TestBudget(ERPNextTestSuite): frappe.db.set_value("Budget", budget.name, "action_if_accumulated_monthly_budget_exceeded", "Stop") + accumulated_limit = get_accumulated_monthly_budget( + budget.monthly_distribution, nowdate(), budget.fiscal_year, budget.accounts[0].budget_amount + ) jv = make_journal_entry( "_Test Account Cost for Goods Sold - _TC", "_Test Bank - _TC", - 40000, + accumulated_limit + 1, "_Test Cost Center - _TC", posting_date=nowdate(), ) @@ -427,6 +434,7 @@ def make_budget(**args): monthly_distribution = frappe.get_doc("Monthly Distribution", "_Test Distribution") monthly_distribution.fiscal_year = fiscal_year + monthly_distribution.save() budget.fiscal_year = fiscal_year budget.monthly_distribution = "_Test Distribution" From 9ed69f96e848d2f2ca147ab0d1e34008d06552ae Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Thu, 15 May 2025 16:47:30 +0530 Subject: [PATCH 2/2] fix(test): pass sufficient amount to breach accumulated limit --- .../accounts/doctype/budget/test_budget.py | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/erpnext/accounts/doctype/budget/test_budget.py b/erpnext/accounts/doctype/budget/test_budget.py index 9e3df0e35f2..7c071da1acc 100644 --- a/erpnext/accounts/doctype/budget/test_budget.py +++ b/erpnext/accounts/doctype/budget/test_budget.py @@ -51,10 +51,13 @@ class TestBudget(ERPNextTestSuite): frappe.db.set_value("Budget", budget.name, "action_if_accumulated_monthly_budget_exceeded", "Stop") + accumulated_limit = get_accumulated_monthly_budget( + budget.monthly_distribution, nowdate(), budget.fiscal_year, budget.accounts[0].budget_amount + ) jv = make_journal_entry( "_Test Account Cost for Goods Sold - _TC", "_Test Bank - _TC", - 40000, + accumulated_limit + 1, "_Test Cost Center - _TC", posting_date=nowdate(), ) @@ -146,7 +149,12 @@ class TestBudget(ERPNextTestSuite): frappe.db.set_value("Budget", budget.name, "action_if_accumulated_monthly_budget_exceeded", "Stop") frappe.db.set_value("Budget", budget.name, "fiscal_year", fiscal_year) - po = create_purchase_order(transaction_date=nowdate(), do_not_submit=True) + accumulated_limit = get_accumulated_monthly_budget( + budget.monthly_distribution, nowdate(), budget.fiscal_year, budget.accounts[0].budget_amount + ) + po = create_purchase_order( + transaction_date=nowdate(), qty=1, rate=accumulated_limit + 1, do_not_submit=True + ) po.set_missing_values() @@ -164,11 +172,13 @@ class TestBudget(ERPNextTestSuite): frappe.db.set_value("Budget", budget.name, "action_if_accumulated_monthly_budget_exceeded", "Stop") project = frappe.get_value("Project", {"project_name": "_Test Project"}) - + accumulated_limit = get_accumulated_monthly_budget( + budget.monthly_distribution, nowdate(), budget.fiscal_year, budget.accounts[0].budget_amount + ) jv = make_journal_entry( "_Test Account Cost for Goods Sold - _TC", "_Test Bank - _TC", - 40000, + accumulated_limit + 1, "_Test Cost Center - _TC", project=project, posting_date=nowdate(), @@ -283,10 +293,13 @@ class TestBudget(ERPNextTestSuite): budget = make_budget(budget_against="Cost Center", cost_center="_Test Company - _TC") frappe.db.set_value("Budget", budget.name, "action_if_accumulated_monthly_budget_exceeded", "Stop") + accumulated_limit = get_accumulated_monthly_budget( + budget.monthly_distribution, nowdate(), budget.fiscal_year, budget.accounts[0].budget_amount + ) jv = make_journal_entry( "_Test Account Cost for Goods Sold - _TC", "_Test Bank - _TC", - 40000, + accumulated_limit + 1, "_Test Cost Center 2 - _TC", posting_date=nowdate(), ) @@ -313,10 +326,13 @@ class TestBudget(ERPNextTestSuite): budget = make_budget(budget_against="Cost Center", cost_center=cost_center) frappe.db.set_value("Budget", budget.name, "action_if_accumulated_monthly_budget_exceeded", "Stop") + accumulated_limit = get_accumulated_monthly_budget( + budget.monthly_distribution, nowdate(), budget.fiscal_year, budget.accounts[0].budget_amount + ) jv = make_journal_entry( "_Test Account Cost for Goods Sold - _TC", "_Test Bank - _TC", - 40000, + accumulated_limit + 1, cost_center, posting_date=nowdate(), )