From 260cfa5d1ee97d131e2ae958372811b630ee46cb Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Fri, 13 May 2022 21:02:09 +0530 Subject: [PATCH] test: employee status filter in leave balance reports --- .../test_employee_leave_balance.py | 37 +++++++++++++++++++ .../test_employee_leave_balance_summary.py | 35 +++++++++++++++++- 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/erpnext/hr/report/employee_leave_balance/test_employee_leave_balance.py b/erpnext/hr/report/employee_leave_balance/test_employee_leave_balance.py index dc0f4d2c94..5354abf4f6 100644 --- a/erpnext/hr/report/employee_leave_balance/test_employee_leave_balance.py +++ b/erpnext/hr/report/employee_leave_balance/test_employee_leave_balance.py @@ -207,3 +207,40 @@ class TestEmployeeLeaveBalance(unittest.TestCase): allocation1.new_leaves_allocated - leave_application.total_leave_days ) self.assertEqual(report[1][0].opening_balance, opening_balance) + + @set_holiday_list("_Test Emp Balance Holiday List", "_Test Company") + def test_employee_status_filter(self): + frappe.get_doc(test_records[0]).insert() + inactive_emp = make_employee("test_emp_status@example.com", company="_Test Company") + + allocation = make_allocation_record( + employee=inactive_emp, + from_date=self.year_start, + to_date=self.year_end, + leaves=5, + ) + + # set employee as inactive + frappe.db.set_value("Employee", inactive_emp, "status", "Inactive") + + filters = frappe._dict( + { + "from_date": allocation.from_date, + "to_date": allocation.to_date, + "employee": inactive_emp, + "employee_status": "Active", + } + ) + report = execute(filters) + self.assertEqual(len(report[1]), 0) + + filters = frappe._dict( + { + "from_date": allocation.from_date, + "to_date": allocation.to_date, + "employee": inactive_emp, + "employee_status": "Inactive", + } + ) + report = execute(filters) + self.assertEqual(len(report[1]), 1) diff --git a/erpnext/hr/report/employee_leave_balance_summary/test_employee_leave_balance_summary.py b/erpnext/hr/report/employee_leave_balance_summary/test_employee_leave_balance_summary.py index 34b665fa9f..2fd74b7983 100644 --- a/erpnext/hr/report/employee_leave_balance_summary/test_employee_leave_balance_summary.py +++ b/erpnext/hr/report/employee_leave_balance_summary/test_employee_leave_balance_summary.py @@ -36,7 +36,6 @@ class TestEmployeeLeaveBalance(unittest.TestCase): frappe.set_user("Administrator") - self.employee_id = make_employee("test_emp_leave_balance@example.com", company="_Test Company") self.employee_id = make_employee("test_emp_leave_balance@example.com", company="_Test Company") self.date = getdate() @@ -146,3 +145,37 @@ class TestEmployeeLeaveBalance(unittest.TestCase): ] self.assertEqual(report[1], expected_data) + + @set_holiday_list("_Test Emp Balance Holiday List", "_Test Company") + def test_employee_status_filter(self): + frappe.get_doc(test_records[0]).insert() + + inactive_emp = make_employee("test_emp_status@example.com", company="_Test Company") + allocation = make_allocation_record( + employee=inactive_emp, from_date=self.year_start, to_date=self.year_end + ) + + # set employee as inactive + frappe.db.set_value("Employee", inactive_emp, "status", "Inactive") + + filters = frappe._dict( + { + "date": allocation.from_date, + "company": "_Test Company", + "employee": inactive_emp, + "employee_status": "Active", + } + ) + report = execute(filters) + self.assertEqual(len(report[1]), 0) + + filters = frappe._dict( + { + "date": allocation.from_date, + "company": "_Test Company", + "employee": inactive_emp, + "employee_status": "Inactive", + } + ) + report = execute(filters) + self.assertEqual(len(report[1]), 1)