From ed8a49737af765a459cb367f4cd4cb97ae726113 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Fri, 13 May 2022 20:23:32 +0530 Subject: [PATCH 1/3] feat: add Employee Status filter in leave balance reports --- .../employee_leave_balance.js | 17 ++++++++++++----- .../employee_leave_balance.py | 8 +++++--- .../employee_leave_balance_summary.js | 7 +++++++ .../employee_leave_balance_summary.py | 3 ++- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/erpnext/hr/report/employee_leave_balance/employee_leave_balance.js b/erpnext/hr/report/employee_leave_balance/employee_leave_balance.js index 8bb3457190..79da65c7e0 100644 --- a/erpnext/hr/report/employee_leave_balance/employee_leave_balance.js +++ b/erpnext/hr/report/employee_leave_balance/employee_leave_balance.js @@ -4,21 +4,21 @@ frappe.query_reports["Employee Leave Balance"] = { "filters": [ { - "fieldname":"from_date", + "fieldname": "from_date", "label": __("From Date"), "fieldtype": "Date", "reqd": 1, "default": frappe.defaults.get_default("year_start_date") }, { - "fieldname":"to_date", + "fieldname": "to_date", "label": __("To Date"), "fieldtype": "Date", "reqd": 1, "default": frappe.defaults.get_default("year_end_date") }, { - "fieldname":"company", + "fieldname": "company", "label": __("Company"), "fieldtype": "Link", "options": "Company", @@ -26,16 +26,23 @@ frappe.query_reports["Employee Leave Balance"] = { "default": frappe.defaults.get_user_default("Company") }, { - "fieldname":"department", + "fieldname": "department", "label": __("Department"), "fieldtype": "Link", "options": "Department", }, { - "fieldname":"employee", + "fieldname": "employee", "label": __("Employee"), "fieldtype": "Link", "options": "Employee", + }, + { + "fieldname": "employee_status", + "label": __("Employee Status"), + "fieldtype": "Select", + "options": ["", "Active", "Inactive", "Suspended", "Left"], + "default": "Active", } ], diff --git a/erpnext/hr/report/employee_leave_balance/employee_leave_balance.py b/erpnext/hr/report/employee_leave_balance/employee_leave_balance.py index ca352f197d..1f7ade23f4 100644 --- a/erpnext/hr/report/employee_leave_balance/employee_leave_balance.py +++ b/erpnext/hr/report/employee_leave_balance/employee_leave_balance.py @@ -168,9 +168,8 @@ def get_opening_balance( def get_conditions(filters: Filters) -> Dict: - conditions = { - "status": "Active", - } + conditions = {} + if filters.get("employee"): conditions["name"] = filters.get("employee") @@ -180,6 +179,9 @@ def get_conditions(filters: Filters) -> Dict: if filters.get("department"): conditions["department"] = filters.get("department") + if filters.get("employee_status"): + conditions["status"] = filters.get("employee_status") + return conditions diff --git a/erpnext/hr/report/employee_leave_balance_summary/employee_leave_balance_summary.js b/erpnext/hr/report/employee_leave_balance_summary/employee_leave_balance_summary.js index cb05d1138f..3046b14e7a 100644 --- a/erpnext/hr/report/employee_leave_balance_summary/employee_leave_balance_summary.js +++ b/erpnext/hr/report/employee_leave_balance_summary/employee_leave_balance_summary.js @@ -30,6 +30,13 @@ frappe.query_reports['Employee Leave Balance Summary'] = { label: __('Department'), fieldtype: 'Link', options: 'Department', + }, + { + fieldname: "employee_status", + label: __("Employee Status"), + fieldtype: "Select", + options: ["", "Active", "Inactive", "Suspended", "Left"], + default: "Active", } ] }; diff --git a/erpnext/hr/report/employee_leave_balance_summary/employee_leave_balance_summary.py b/erpnext/hr/report/employee_leave_balance_summary/employee_leave_balance_summary.py index 2a16dc41d6..82878dbebb 100644 --- a/erpnext/hr/report/employee_leave_balance_summary/employee_leave_balance_summary.py +++ b/erpnext/hr/report/employee_leave_balance_summary/employee_leave_balance_summary.py @@ -35,9 +35,10 @@ def get_columns(leave_types): def get_conditions(filters): conditions = { - "status": "Active", "company": filters.company, } + if filters.get("employee_status"): + conditions.update({"status": filters.get("employee_status")}) if filters.get("department"): conditions.update({"department": filters.get("department")}) if filters.get("employee"): From 08fb9a4318dabde4ace4bd76191af911f24b4aaa Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Fri, 13 May 2022 20:44:35 +0530 Subject: [PATCH 2/3] fix: translation for status filter --- .../employee_leave_balance/employee_leave_balance.js | 8 +++++++- .../employee_leave_balance_summary.js | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/erpnext/hr/report/employee_leave_balance/employee_leave_balance.js b/erpnext/hr/report/employee_leave_balance/employee_leave_balance.js index 79da65c7e0..2339350d06 100644 --- a/erpnext/hr/report/employee_leave_balance/employee_leave_balance.js +++ b/erpnext/hr/report/employee_leave_balance/employee_leave_balance.js @@ -41,7 +41,13 @@ frappe.query_reports["Employee Leave Balance"] = { "fieldname": "employee_status", "label": __("Employee Status"), "fieldtype": "Select", - "options": ["", "Active", "Inactive", "Suspended", "Left"], + "options": [ + "", + { "value": "Active", "label": __("Active") }, + { "value": "Inactive", "label": __("Inactive") }, + { "value": "Suspended", "label": __("Suspended") }, + { "value": "Left", "label": __("Left") }, + ], "default": "Active", } ], diff --git a/erpnext/hr/report/employee_leave_balance_summary/employee_leave_balance_summary.js b/erpnext/hr/report/employee_leave_balance_summary/employee_leave_balance_summary.js index 3046b14e7a..26dd782533 100644 --- a/erpnext/hr/report/employee_leave_balance_summary/employee_leave_balance_summary.js +++ b/erpnext/hr/report/employee_leave_balance_summary/employee_leave_balance_summary.js @@ -35,7 +35,13 @@ frappe.query_reports['Employee Leave Balance Summary'] = { fieldname: "employee_status", label: __("Employee Status"), fieldtype: "Select", - options: ["", "Active", "Inactive", "Suspended", "Left"], + options: [ + "", + { "value": "Active", "label": __("Active") }, + { "value": "Inactive", "label": __("Inactive") }, + { "value": "Suspended", "label": __("Suspended") }, + { "value": "Left", "label": __("Left") }, + ], default: "Active", } ] From 260cfa5d1ee97d131e2ae958372811b630ee46cb Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Fri, 13 May 2022 21:02:09 +0530 Subject: [PATCH 3/3] 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)