From 5bd4d8a932a88870bd1311a5ae043a06ad45efaf Mon Sep 17 00:00:00 2001 From: Manas Solanki Date: Tue, 22 Nov 2016 18:11:30 +0530 Subject: [PATCH] [Fix] Budget against Projects - Test case fixed - Either cost center or project is mandatory --- erpnext/accounts/doctype/budget/budget.json | 4 ++-- erpnext/accounts/doctype/budget/budget.py | 2 ++ erpnext/accounts/doctype/budget/test_budget.py | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/erpnext/accounts/doctype/budget/budget.json b/erpnext/accounts/doctype/budget/budget.json index d177fa862d..1dad38f53a 100644 --- a/erpnext/accounts/doctype/budget/budget.json +++ b/erpnext/accounts/doctype/budget/budget.json @@ -34,7 +34,7 @@ "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, - "reqd": 1, + "reqd": 0, "search_index": 0, "set_only_once": 0, "unique": 0 @@ -370,7 +370,7 @@ "issingle": 0, "istable": 0, "max_attachments": 0, - "modified": "2016-11-22 11:58:42.211690", + "modified": "2016-11-23 11:20:46.600912", "modified_by": "Administrator", "module": "Accounts", "name": "Budget", diff --git a/erpnext/accounts/doctype/budget/budget.py b/erpnext/accounts/doctype/budget/budget.py index 7df71518aa..a3cc1102c4 100644 --- a/erpnext/accounts/doctype/budget/budget.py +++ b/erpnext/accounts/doctype/budget/budget.py @@ -20,6 +20,8 @@ class Budget(Document): self.name = make_autoname(self.project + "/" + self.fiscal_year + "/.###") def validate(self): + if not self.cost_center and not self.project: + frappe.throw(_("Budget should be allocated against either Cost Center or Project.")) if self.cost_center: self.validate_duplicate("cost_center") if self.project: diff --git a/erpnext/accounts/doctype/budget/test_budget.py b/erpnext/accounts/doctype/budget/test_budget.py index ef6a1c84f6..ee44ee05ec 100644 --- a/erpnext/accounts/doctype/budget/test_budget.py +++ b/erpnext/accounts/doctype/budget/test_budget.py @@ -5,7 +5,7 @@ from __future__ import unicode_literals import frappe import unittest -from erpnext.accounts.doctype.budget.budget import get_actual_expense, BudgetError +from erpnext.accounts.doctype.budget.budget import get_actual_expense_for_CC, BudgetError from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journal_entry class TestBudget(unittest.TestCase): @@ -89,7 +89,7 @@ class TestBudget(unittest.TestCase): budget.cancel() def set_total_expense_zero(posting_date, cost_center=None): - existing_expense = get_actual_expense({ + existing_expense = get_actual_expense_for_CC({ "account": "_Test Account Cost for Goods Sold - _TC", "cost_center": cost_center or "_Test Cost Center - _TC", "monthly_end_date": posting_date,