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_work_entry_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def _search_max_leaves(self, operator, value):

def _search_virtual_remaining_leaves(self, operator, value):
def is_valid(work_entry_type):
return not work_entry_type.requires_allocation or op(work_entry_type.virtual_remaining_leaves)
return not work_entry_type.requires_allocation or op(work_entry_type.virtual_remaining_leaves, value)
op = PY_OPERATORS.get(operator)
if not op:
return NotImplemented
Expand Down
59 changes: 59 additions & 0 deletions addons/hr_holidays/tests/test_hr_work_entry_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,62 @@ def test_change_count_days_as(self):

with self.assertRaises(ValidationError):
work_entry_type.count_days_as = 'working'

def test_search_with_virtual_remaining_leaves_rule(self):
work_entry_type_1 = self.env['hr.work.entry.type'].create({
'name': 'Test Time Off',
'code': 'Test Time Off 5',
'requires_allocation': True,
'unit_of_measure': 'day',
})
work_entry_type_2 = self.env['hr.work.entry.type'].create({
'name': 'Test Time Off',
'code': 'Test Time Off 6',
'requires_allocation': True,
'unit_of_measure': 'day',
})
work_entry_type_3 = self.env['hr.work.entry.type'].create({
'name': 'Test Time Off',
'code': 'Test Time Off 7',
'requires_allocation': True,
'unit_of_measure': 'day',
})

employee = self.env['hr.employee'].create({'name': 'Test Employee'})
allocation_1 = self.env['hr.leave.allocation'].create({
'name': 'Test Allocation',
'employee_id': employee.id,
'work_entry_type_id': work_entry_type_1.id,
'number_of_days': 6,
})
allocation_2 = self.env['hr.leave.allocation'].create({
'name': 'Test Allocation',
'employee_id': employee.id,
'work_entry_type_id': work_entry_type_2.id,
'number_of_days': 4,
})
allocation_1._action_validate()
allocation_2._action_validate()

type_env = self.env['hr.work.entry.type'].with_context(employee_id=employee.id)

results = type_env.search([('virtual_remaining_leaves', '=', 0)])
self.assertNotIn(work_entry_type_1, results)
self.assertNotIn(work_entry_type_2, results)
self.assertIn(work_entry_type_3, results)

results = type_env.search([('virtual_remaining_leaves', '<', 5)])
self.assertNotIn(work_entry_type_1, results)
self.assertIn(work_entry_type_2, results)
self.assertIn(work_entry_type_3, results)

results = type_env.search([('virtual_remaining_leaves', '>', 3)])
self.assertIn(work_entry_type_1, results)
self.assertIn(work_entry_type_2, results)
self.assertNotIn(work_entry_type_3, results)

results = type_env.search([('virtual_remaining_leaves', '=', 6)])
self.assertIn(work_entry_type_1, results)

results = type_env.search([('virtual_remaining_leaves', '=', 4)])
self.assertIn(work_entry_type_2, results)