Skip to content
Draft
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
2 changes: 1 addition & 1 deletion addons/hr_holidays/models/hr_leave_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def _search_virtual_remaining_leaves(self, operator, value):
leave_types = self.env['hr.leave.type'].search([])

def is_valid(leave_type):
return not leave_type.requires_allocation or op(leave_type.virtual_remaining_leaves)
return not leave_type.requires_allocation or op(leave_type.virtual_remaining_leaves, value)
return [('id', 'in', leave_types.filtered(is_valid).ids)]

@api.depends_context('employee_id', 'default_employee_id', 'leave_date_from', 'default_date_from')
Expand Down
56 changes: 56 additions & 0 deletions addons/hr_holidays/tests/test_hr_leave_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,59 @@ def test_users_tz_shift_back(self):
).search([('has_valid_allocation', '=', True)], limit=1)

self.assertFalse(leave_types, "Got valid leaves outside vaild period")

def test_search_virtual_remaining_leaves(self):
employee = self.env['hr.employee'].create({'name': 'Test Employee'})
leave_type_1 = self.env['hr.leave.type'].create({
'name': 'Test Leave 1',
'requires_allocation': True,
})
leave_type_2 = self.env['hr.leave.type'].create({
'name': 'Test Leave 2',
'requires_allocation': False,
})

self.env['hr.leave.allocation'].sudo().create({
'state': 'confirm',
'holiday_status_id': leave_type_1.id,
'employee_id': employee.id,
'number_of_days': 4,
'date_from': '2025-01-01',
'date_to': '2025-12-31',
}).action_approve()

result = (
self.env["hr.leave.type"]
.with_context(employee_id=employee.id)
.search([("virtual_remaining_leaves", ">", 0)])
)
self.assertIn(
leave_type_1, result, "Leave Type 1 should be in the result as it has remaining leaves",
)
self.assertIn(
leave_type_2, result, "Leave Type 2 should be in the result since it does not require allocation",
)

result = (
self.env["hr.leave.type"]
.with_context(employee_id=employee.id)
.search([("virtual_remaining_leaves", "=", 0)])
)
self.assertNotIn(
leave_type_1, result, "Leave Type 1 should not be in the result as it has remaining leaves != 0",
)
self.assertIn(
leave_type_2, result, "Leave Type 2 should be in the result since it does not require allocation",
)

result = (
self.env["hr.leave.type"]
.with_context(employee_id=employee.id)
.search([("virtual_remaining_leaves", ">", 4)])
)
self.assertNotIn(
leave_type_1, result, "Leave Type 1 should not be in the result",
)
self.assertIn(
leave_type_2, result, "Leave Type 2 should be in the result since it does not require allocation",
)