From 5ece274a29bf3ccccf2a772517059b0349319ba4 Mon Sep 17 00:00:00 2001 From: SebVde Date: Wed, 6 May 2026 13:36:45 +0200 Subject: [PATCH] [FIX] hr_holidays: fix error when selecting time off type There was a TypeError after allocating a time off for an employee, validating it, creating the time off for this employee, and clicking on the Time Type selection. The bug was due to the private _search method. Added a test to ensure the search on work entry types works. Task: 6191029 --- .../hr_holidays/models/hr_work_entry_type.py | 2 +- .../tests/test_hr_work_entry_type.py | 59 +++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/addons/hr_holidays/models/hr_work_entry_type.py b/addons/hr_holidays/models/hr_work_entry_type.py index 9677754741dbc..87d6496542c65 100644 --- a/addons/hr_holidays/models/hr_work_entry_type.py +++ b/addons/hr_holidays/models/hr_work_entry_type.py @@ -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 diff --git a/addons/hr_holidays/tests/test_hr_work_entry_type.py b/addons/hr_holidays/tests/test_hr_work_entry_type.py index aca98678c8619..6f13d7fc70bb4 100644 --- a/addons/hr_holidays/tests/test_hr_work_entry_type.py +++ b/addons/hr_holidays/tests/test_hr_work_entry_type.py @@ -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)