Merge pull request #9753 from rohitwaghchaure/budget_cost_center_issue
[Fix] Budget against the field in the validation message
diff --git a/erpnext/accounts/doctype/budget/budget.py b/erpnext/accounts/doctype/budget/budget.py
index a6348f1..f99d0bb 100644
--- a/erpnext/accounts/doctype/budget/budget.py
+++ b/erpnext/accounts/doctype/budget/budget.py
@@ -83,7 +83,7 @@
budget_records = frappe.db.sql("""
select
- b.{budget_against_field}, ba.budget_amount, b.monthly_distribution,
+ b.{budget_against_field} as budget_against, ba.budget_amount, b.monthly_distribution,
b.action_if_annual_budget_exceeded,
b.action_if_accumulated_monthly_budget_exceeded
from
@@ -111,15 +111,15 @@
args["month_end_date"] = get_last_day(args.posting_date)
compare_expense_with_budget(args, budget_amount,
- _("Accumulated Monthly"), monthly_action)
+ _("Accumulated Monthly"), monthly_action, budget.budget_against)
if yearly_action in ("Stop", "Warn") and monthly_action != "Stop" \
and yearly_action != monthly_action:
compare_expense_with_budget(args, flt(budget.budget_amount),
- _("Annual"), yearly_action)
+ _("Annual"), yearly_action, budget.budget_against)
-def compare_expense_with_budget(args, budget_amount, action_for, action):
+def compare_expense_with_budget(args, budget_amount, action_for, action, budget_against):
actual_expense = get_actual_expense(args)
if actual_expense > budget_amount:
diff = actual_expense - budget_amount
@@ -127,7 +127,7 @@
msg = _("{0} Budget for Account {1} against {2} {3} is {4}. It will exceed by {5}").format(
_(action_for), frappe.bold(args.account), args.budget_against_field,
- frappe.bold(args.budget_against),
+ frappe.bold(budget_against),
frappe.bold(fmt_money(budget_amount, currency=currency)),
frappe.bold(fmt_money(diff, currency=currency)))
diff --git a/erpnext/accounts/doctype/budget/test_budget.py b/erpnext/accounts/doctype/budget/test_budget.py
index 15895dc..f6849ba 100644
--- a/erpnext/accounts/doctype/budget/test_budget.py
+++ b/erpnext/accounts/doctype/budget/test_budget.py
@@ -140,6 +140,33 @@
budget.load_from_db()
budget.cancel()
+ def test_monthly_budget_against_parent_group_cost_center(self):
+ cost_center = "_Test Cost Center 3 - _TC"
+
+ if not frappe.db.exists("Cost Center", cost_center):
+ frappe.get_doc({
+ 'doctype': 'Cost Center',
+ 'cost_center_name': '_Test Cost Center 3',
+ 'parent_cost_center': "_Test Company - _TC",
+ 'company': '_Test Company',
+ 'is_group': 0
+ }).insert(ignore_permissions=True)
+
+ budget = make_budget("Cost Center", cost_center)
+ frappe.db.set_value("Budget", budget.name, "action_if_accumulated_monthly_budget_exceeded", "Stop")
+
+ jv = make_journal_entry("_Test Account Cost for Goods Sold - _TC",
+ "_Test Bank - _TC", 40000, cost_center)
+
+ self.assertRaises(BudgetError, jv.submit)
+
+ budget.load_from_db()
+ budget.cancel()
+ jv.cancel()
+
+ frappe.delete_doc('Journal Entry', jv.name)
+ frappe.delete_doc('Cost Center', cost_center)
+
def set_total_expense_zero(posting_date, budget_against_field=None, budget_against_CC=None):
if budget_against_field == "Project":
budget_against = "_Test Project"
@@ -167,7 +194,8 @@
if budget_against == "Project":
budget_list = frappe.get_all("Budget", fields=["name"], filters = {"name": ("like", "_Test Project/_Test Fiscal Year 2013%")})
else:
- budget_list = frappe.get_all("Budget", fields=["name"], filters = {"name": ("like", "_Test Cost Center - _TC/_Test Fiscal Year 2013%")})
+ cost_center_name = "{0}%".format(cost_center or "_Test Cost Center - _TC/_Test Fiscal Year 2013")
+ budget_list = frappe.get_all("Budget", fields=["name"], filters = {"name": ("like", cost_center_name)})
for d in budget_list:
frappe.db.sql("delete from `tabBudget` where name = %(name)s", d)
frappe.db.sql("delete from `tabBudget Account` where parent = %(name)s", d)