From 7f9ea3bf6ad0706bfe50f86f570aaee637761ba3 Mon Sep 17 00:00:00 2001 From: Neil Trini Lasrado Date: Tue, 7 Apr 2015 18:11:49 +0530 Subject: [PATCH] expense claim test records --- .../hr/doctype/expense_claim/expense_claim.py | 12 ++++- .../expense_claim/test_expense_claim.py | 48 ++++++++++++++++++- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/erpnext/hr/doctype/expense_claim/expense_claim.py b/erpnext/hr/doctype/expense_claim/expense_claim.py index 9bc16e4ebc4..eb297f827ba 100644 --- a/erpnext/hr/doctype/expense_claim/expense_claim.py +++ b/erpnext/hr/doctype/expense_claim/expense_claim.py @@ -18,8 +18,9 @@ class ExpenseClaim(Document): def validate(self): validate_fiscal_year(self.posting_date, self.fiscal_year, _("Posting Date"), self) - self.validate_sanctioned_amount() self.validate_exp_details() + self.validate_cost() + self.validate_sanctioned_amount() self.validate_expense_approver() self.validate_task() set_employee_name(self) @@ -33,6 +34,15 @@ class ExpenseClaim(Document): def on_cancel(self): if self.project: self.update_task() + + def validate_cost(self): + total_claimed_amount = 0 + total_sanctioned_amount = 0 + for d in self.expenses: + total_claimed_amount += d.claim_amount + total_sanctioned_amount += d.sanctioned_amount + self.total_claimed_amount = total_claimed_amount + self.total_sanctioned_amount = total_sanctioned_amount def validate_exp_details(self): if not self.get('expenses'): diff --git a/erpnext/hr/doctype/expense_claim/test_expense_claim.py b/erpnext/hr/doctype/expense_claim/test_expense_claim.py index f1c657adb88..9c053839de7 100644 --- a/erpnext/hr/doctype/expense_claim/test_expense_claim.py +++ b/erpnext/hr/doctype/expense_claim/test_expense_claim.py @@ -8,4 +8,50 @@ import unittest test_records = frappe.get_test_records('Expense Claim') class TestExpenseClaim(unittest.TestCase): - pass + def test_project_costing(self): + frappe.db.sql("delete from `tabTask`") + frappe.db.sql("delete from `tabProject`") + + frappe.get_doc({ + "project_name": "_Test Project 1", + "doctype": "Project", + "tasks" : + [{ "title": "_Test Project Task 1", "status": "Open" }] + }).save() + + task_name = frappe.db.get_value("Task",{"project": "_Test Project 1"}) + expense_claim = frappe.get_doc({ + "doctype": "Expense Claim", + "employee": "_T-Employee-0001", + "posting_date": "2015-07-07", + "fiscal_year": "_Test Fiscal Year 2015", + "approval_status": "Approved", + "project": "_Test Project 1", + "task": task_name, + "expenses": + [{ "expense_type": "Food", "claim_amount": 300, "sanctioned_amount": 200 }] + }) + expense_claim.submit() + + self.assertEqual(frappe.db.get_value("Task", task_name, "total_expense_claim"), 200) + self.assertEqual(frappe.db.get_value("Project", "_Test Project 1", "total_expense_claim"), 200) + + expense_claim2 = frappe.get_doc({ + "doctype": "Expense Claim", + "employee": "_T-Employee-0001", + "posting_date": "2015-07-07", + "approval_status": "Approved", + "project": "_Test Project 1", + "task": task_name, + "expenses": + [{ "expense_type": "Food", "claim_amount": 600, "sanctioned_amount": 500 }] + }) + expense_claim2.submit() + + self.assertEqual(frappe.db.get_value("Task", task_name, "total_expense_claim"), 700) + self.assertEqual(frappe.db.get_value("Project", "_Test Project 1", "total_expense_claim"), 700) + + expense_claim2.cancel() + + self.assertEqual(frappe.db.get_value("Task", task_name, "total_expense_claim"), 200) + self.assertEqual(frappe.db.get_value("Project", "_Test Project 1", "total_expense_claim"), 200)