From 05ad2802c67febe9f33b771bf6879dfb525c6692 Mon Sep 17 00:00:00 2001 From: Shreya Shah Date: Mon, 30 Apr 2018 11:14:56 +0530 Subject: [PATCH] Travis test fixes for leave application (#13790) * test fix * expense claim test fix * fix payroll entry test case --- .../expense_claim/test_expense_claim.py | 27 +++++++++++++--- .../leave_application/leave_application.py | 32 +++++++++---------- .../test_leave_application.py | 6 ++-- .../payroll_entry/test_payroll_entry.py | 2 +- 4 files changed, 41 insertions(+), 26 deletions(-) diff --git a/erpnext/hr/doctype/expense_claim/test_expense_claim.py b/erpnext/hr/doctype/expense_claim/test_expense_claim.py index f89beba2f6..3e031c9cce 100644 --- a/erpnext/hr/doctype/expense_claim/test_expense_claim.py +++ b/erpnext/hr/doctype/expense_claim/test_expense_claim.py @@ -77,9 +77,27 @@ class TestExpenseClaim(unittest.TestCase): ]) for gle in gl_entries: - self.assertEqual(expected_values[gle.account][0], gle.account) - self.assertEqual(expected_values[gle.account][1], gle.debit) - self.assertEqual(expected_values[gle.account][2], gle.credit) + self.assertEquals(expected_values[gle.account][0], gle.account) + self.assertEquals(expected_values[gle.account][1], gle.debit) + self.assertEquals(expected_values[gle.account][2], gle.credit) + + def test_rejected_expense_claim(self): + payable_account = get_payable_account("Wind Power LLC") + expense_claim = frappe.get_doc({ + "doctype": "Expense Claim", + "employee": "_T-Employee-00001", + "payable_account": payable_account, + "approval_status": "Rejected", + "expenses": + [{ "expense_type": "Travel", "default_account": "Travel Expenses - WP", "claim_amount": 300, "sanctioned_amount": 200 }] + }) + expense_claim.submit() + + self.assertEquals(expense_claim.status, 'Rejected') + self.assertEquals(expense_claim.total_sanctioned_amount, 0.0) + + gl_entry = frappe.get_all('GL Entry', {'voucher_type': 'Expense Claim', 'voucher_no': expense_claim.name}) + self.assertEquals(len(gl_entry), 0) def get_payable_account(company): return frappe.db.get_value('Company', company, 'default_payable_account') @@ -89,6 +107,7 @@ def make_expense_claim(payable_account,claim_amount, sanctioned_amount, company, "doctype": "Expense Claim", "employee": "_T-Employee-00001", "payable_account": payable_account, + "approval_status": "Approved", "company": company, "expenses": [{ "expense_type": "Travel", "default_account": account, "claim_amount": claim_amount, "sanctioned_amount": sanctioned_amount }] @@ -100,5 +119,3 @@ def make_expense_claim(payable_account,claim_amount, sanctioned_amount, company, expense_claim.submit() return expense_claim - - diff --git a/erpnext/hr/doctype/leave_application/leave_application.py b/erpnext/hr/doctype/leave_application/leave_application.py index b33bd5444e..df554e85a5 100755 --- a/erpnext/hr/doctype/leave_application/leave_application.py +++ b/erpnext/hr/doctype/leave_application/leave_application.py @@ -232,24 +232,24 @@ class LeaveApplication(Document): }) def notify_leave_approver(self): + if self.leave_approver: + parent_doc = frappe.get_doc('Leave Application', self.name) + args = parent_doc.as_dict() - parent_doc = frappe.get_doc('Leave Application', self.name) - args = parent_doc.as_dict() + template = frappe.db.get_single_value('HR Settings', 'leave_approval_notification_template') + if not template: + frappe.msgprint(_("Please set default template for Leave Approval Notification in HR Settings.")) + return + email_template = frappe.get_doc("Email Template", template) + message = frappe.render_template(email_template.response, args) - template = frappe.db.get_single_value('HR Settings', 'leave_approval_notification_template') - if not template: - frappe.msgprint(_("Please set default template for Leave Approval Notification in HR Settings.")) - return - email_template = frappe.get_doc("Email Template", template) - message = frappe.render_template(email_template.response, args) - - self.notify({ - # for post in messages - "message": message, - "message_to": self.leave_approver, - # for email - "subject": email_template.subject - }) + self.notify({ + # for post in messages + "message": message, + "message_to": self.leave_approver, + # for email + "subject": email_template.subject + }) def notify(self, args): args = frappe._dict(args) diff --git a/erpnext/hr/doctype/leave_application/test_leave_application.py b/erpnext/hr/doctype/leave_application/test_leave_application.py index 0f77fb93b9..4643e89ef6 100644 --- a/erpnext/hr/doctype/leave_application/test_leave_application.py +++ b/erpnext/hr/doctype/leave_application/test_leave_application.py @@ -49,9 +49,6 @@ class TestLeaveApplication(unittest.TestCase): def tearDown(self): frappe.set_user("Administrator") - # so that this test doesn't affect other tests - frappe.db.sql("""delete from `tabEmployee Leave Approver`""") - def _clear_roles(self): frappe.db.sql("""delete from `tabHas Role` where parent in ("test@example.com", "test1@example.com", "test2@example.com")""") @@ -80,6 +77,7 @@ class TestLeaveApplication(unittest.TestCase): application = self.get_application(_test_records[0]) application.insert() + application.status = "Approved" self.assertRaises(LeaveDayBlockedError, application.submit) frappe.set_user("test1@example.com") @@ -219,7 +217,7 @@ class TestLeaveApplication(unittest.TestCase): frappe.set_user("test1@example.com") application.insert() - + application.status = "Approved" frappe.set_user("test@example.com") self.assertRaises(LeaveDayBlockedError, application.submit) diff --git a/erpnext/hr/doctype/payroll_entry/test_payroll_entry.py b/erpnext/hr/doctype/payroll_entry/test_payroll_entry.py index fe5a7551c6..2a9d87c754 100644 --- a/erpnext/hr/doctype/payroll_entry/test_payroll_entry.py +++ b/erpnext/hr/doctype/payroll_entry/test_payroll_entry.py @@ -57,7 +57,7 @@ class TestPayrollEntry(unittest.TestCase): salary_component = frappe.get_doc('Salary Component', 'Basic Salary') salary_component.append('accounts', { 'company': company, - 'default_account': 'Salary - WP' + 'default_account': "Salary - " + frappe.db.get_value('Company', company, 'abbr') }) company_doc = frappe.get_doc('Company', company)