Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Employee Status filter in leave balance reports #31013

Merged
merged 3 commits into from
May 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions erpnext/hr/report/employee_leave_balance/employee_leave_balance.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,51 @@
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",
"reqd": 1,
"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": [
"",
{ "value": "Active", "label": __("Active") },
{ "value": "Inactive", "label": __("Inactive") },
{ "value": "Suspended", "label": __("Suspended") },
{ "value": "Left", "label": __("Left") },
],
"default": "Active",
}
],

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,40 @@ def test_opening_balance_considers_carry_forwarded_leaves(self):
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)
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ frappe.query_reports['Employee Leave Balance Summary'] = {
label: __('Department'),
fieldtype: 'Link',
options: 'Department',
},
{
fieldname: "employee_status",
label: __("Employee Status"),
fieldtype: "Select",
options: [
"",
{ "value": "Active", "label": __("Active") },
{ "value": "Inactive", "label": __("Inactive") },
{ "value": "Suspended", "label": __("Suspended") },
{ "value": "Left", "label": __("Left") },
],
default: "Active",
}
]
};
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def setUp(self):

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()
Expand Down Expand Up @@ -146,3 +145,37 @@ def test_get_leave_balance_near_alloc_expiry(self):
]

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)