From 5a9b272f8480956bd60bbec4f180e012a59a5158 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Thu, 22 May 2025 15:04:17 +0530 Subject: [PATCH] test: cumulative actions for budget --- .../accounts/doctype/budget/test_budget.py | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/erpnext/accounts/doctype/budget/test_budget.py b/erpnext/accounts/doctype/budget/test_budget.py index f9349a28793..707a52e84ad 100644 --- a/erpnext/accounts/doctype/budget/test_budget.py +++ b/erpnext/accounts/doctype/budget/test_budget.py @@ -380,6 +380,44 @@ class TestBudget(ERPNextTestSuite): self.assertRaises(BudgetError, jv.submit) + def test_action_for_cumulative_limit(self): + set_total_expense_zero(nowdate(), "cost_center") + + budget = make_budget(budget_against="Cost Center", applicable_on_cumulative_expense=True) + + 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", + accumulated_limit - 1, + "_Test Cost Center - _TC", + posting_date=nowdate(), + ) + jv.submit() + + frappe.db.set_value( + "Budget", budget.name, "action_if_accumulated_monthly_exceeded_on_cumulative_expense", "Stop" + ) + po = create_purchase_order( + transaction_date=nowdate(), qty=1, rate=accumulated_limit + 1, do_not_submit=True + ) + po.set_missing_values() + + self.assertRaises(BudgetError, po.submit) + + frappe.db.set_value( + "Budget", budget.name, "action_if_accumulated_monthly_exceeded_on_cumulative_expense", "Ignore" + ) + po.submit() + + budget.load_from_db() + budget.cancel() + po.cancel() + jv.cancel() + def set_total_expense_zero(posting_date, budget_against_field=None, budget_against_CC=None): if budget_against_field == "project":