From 2e0fbdeebe38d995104e5cb0f08a0de9417a42f7 Mon Sep 17 00:00:00 2001 From: Manas Solanki Date: Mon, 28 Nov 2016 23:53:33 +0530 Subject: [PATCH] [Fix] Test Case - Previous test case fixed - Additional test case for project against budget --- erpnext/accounts/doctype/budget/budget.json | 5 ++- erpnext/accounts/doctype/budget/budget.py | 10 ++--- .../accounts/doctype/budget/test_budget.py | 39 +++++++++++-------- .../journal_entry/test_journal_entry.py | 2 - 4 files changed, 30 insertions(+), 26 deletions(-) diff --git a/erpnext/accounts/doctype/budget/budget.json b/erpnext/accounts/doctype/budget/budget.json index 1dad38f53a..d081364f96 100644 --- a/erpnext/accounts/doctype/budget/budget.json +++ b/erpnext/accounts/doctype/budget/budget.json @@ -15,6 +15,7 @@ "bold": 0, "collapsible": 0, "columns": 0, + "default": "Cost Center", "fieldname": "budget_against", "fieldtype": "Select", "hidden": 0, @@ -34,7 +35,7 @@ "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, - "reqd": 0, + "reqd": 1, "search_index": 0, "set_only_once": 0, "unique": 0 @@ -370,7 +371,7 @@ "issingle": 0, "istable": 0, "max_attachments": 0, - "modified": "2016-11-23 11:20:46.600912", + "modified": "2016-11-30 08:51:10.453935", "modified_by": "Administrator", "module": "Accounts", "name": "Budget", diff --git a/erpnext/accounts/doctype/budget/budget.py b/erpnext/accounts/doctype/budget/budget.py index ab6d25b627..496f9119f1 100644 --- a/erpnext/accounts/doctype/budget/budget.py +++ b/erpnext/accounts/doctype/budget/budget.py @@ -14,12 +14,11 @@ class DuplicateBudgetError(frappe.ValidationError): pass class Budget(Document): def autoname(self): - budget_against = self.get(frappe.scrub(self.budget_against)) - self.name = make_autoname(budget_against + "/" + self.fiscal_year + "/.###") - + self.name = make_autoname(self.get(frappe.scrub(self.budget_against)) + "/" + 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 not self.get(frappe.scrub(self.budget_against)): + frappe.throw(_("{0} is mandatory").format(self.budget_against)) self.validate_duplicate() self.validate_accounts() @@ -58,7 +57,6 @@ def validate_expense_against_budget(args): args = frappe._dict(args) if not args.cost_center and not args.project: return - for budget_against in [args.project, args.cost_center]: if budget_against: if frappe.db.get_value("Account", {"name": args.account, "root_type": "Expense"}): diff --git a/erpnext/accounts/doctype/budget/test_budget.py b/erpnext/accounts/doctype/budget/test_budget.py index b1506364fd..15895dc5ca 100644 --- a/erpnext/accounts/doctype/budget/test_budget.py +++ b/erpnext/accounts/doctype/budget/test_budget.py @@ -127,7 +127,7 @@ class TestBudget(unittest.TestCase): def test_monthly_budget_against_group_cost_center(self): set_total_expense_zero("2013-02-28", "Cost Center") - set_total_expense_zero("2013-02-28", "Cost Center") + set_total_expense_zero("2013-02-28", "Cost Center", "_Test Cost Center 2 - _TC") budget = make_budget("Cost Center", "_Test Company - _TC") frappe.db.set_value("Budget", budget.name, "action_if_accumulated_monthly_budget_exceeded", "Stop") @@ -140,20 +140,20 @@ class TestBudget(unittest.TestCase): budget.load_from_db() budget.cancel() -def set_total_expense_zero(posting_date, budget_against_field=None): +def set_total_expense_zero(posting_date, budget_against_field=None, budget_against_CC=None): if budget_against_field == "Project": budget_against = "_Test Project" - elif budget_against_field == "Cost Center": - budget_against = "_Test Cost Center - _TC" - existing_expense = get_actual_expense({ + else: + budget_against = budget_against_CC or "_Test Cost Center - _TC" + existing_expense = get_actual_expense(frappe._dict({ "account": "_Test Account Cost for Goods Sold - _TC", - "cost_center": cost_center or "_Test Cost Center - _TC", + "cost_center": "_Test Cost Center - _TC", "monthly_end_date": posting_date, "company": "_Test Company", "fiscal_year": "_Test Fiscal Year 2013", "budget_against_field": budget_against_field, "budget_against": budget_against - }) + })) if existing_expense: if budget_against_field == "Cost Center": @@ -163,25 +163,32 @@ def set_total_expense_zero(posting_date, budget_against_field=None): make_journal_entry("_Test Account Cost for Goods Sold - _TC", "_Test Bank - _TC", -existing_expense, "_Test Cost Center - _TC", submit=True, project="_Test Project") -def make_budget(budget_against_field, budget_against=None): +def make_budget(budget_against=None, cost_center=None): + 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%")}) + 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) + budget = frappe.new_doc("Budget") - if budget_against_field == "Cost Center": - budget.cost_center = budget_against or "_Test Cost Center - _TC" - budget_amount = 100000 - elif budget_against == "Project": - budget.project = budget_against or "_Test Project" - budget_amount = 100000 + if budget_against == "Project": + budget.project = "_Test Project" + else: + budget.cost_center =cost_center or "_Test Cost Center - _TC" + budget.fiscal_year = "_Test Fiscal Year 2013" budget.monthly_distribution = "_Test Distribution" budget.company = "_Test Company" budget.action_if_annual_budget_exceeded = "Stop" budget.action_if_accumulated_monthly_budget_exceeded = "Ignore" - + budget.budget_against = budget_against budget.append("accounts", { "account": "_Test Account Cost for Goods Sold - _TC", - "budget_amount": budget_amount + "budget_amount": 100000 }) budget.insert() diff --git a/erpnext/accounts/doctype/journal_entry/test_journal_entry.py b/erpnext/accounts/doctype/journal_entry/test_journal_entry.py index 689b66387b..b4bb542aa7 100644 --- a/erpnext/accounts/doctype/journal_entry/test_journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/test_journal_entry.py @@ -189,8 +189,6 @@ class TestJournalEntry(unittest.TestCase): def make_journal_entry(account1, account2, amount, cost_center=None, posting_date=None, exchange_rate=1, save=True, submit=False, project=None): if not cost_center: cost_center = "_Test Cost Center - _TC" - if not project: - project = "_Test Project" jv = frappe.new_doc("Journal Entry") jv.posting_date = posting_date or "2013-02-14"