Skip to content

Commit 47b6005

Browse files
HashemKhaledarpi-odoo
authored andcommitted
[FIX] hr_holidays: fix search on leave type
**Steps to reproduce:** Navigate to Time Off >> Configuration >> Time Off Types >> Open any type, navigate to the Smart button Time Off >> Click on New >> Time Off Type Leads to an error. Reference Video: https://drive.google.com/file/d/1vi_apL24Km5tSomQtwcTArqqWvrBR5ni/view?usp=drive_link **Reason:** The `op` function is a comparison operator function that expects two values to compare and we are only passing to it `leave_type.virtual_remaining_leaves` parameter. **Solution:** Added the missing `value` parameter. Task: 5238200
1 parent 3a7160b commit 47b6005

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

addons/hr_holidays/models/hr_leave_type.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ def _search_virtual_remaining_leaves(self, operator, value):
280280
leave_types = self.env['hr.leave.type'].search([])
281281

282282
def is_valid(leave_type):
283-
return not leave_type.requires_allocation or op(leave_type.virtual_remaining_leaves)
283+
return not leave_type.requires_allocation or op(leave_type.virtual_remaining_leaves, value)
284284
return [('id', 'in', leave_types.filtered(is_valid).ids)]
285285

286286
@api.depends_context('employee_id', 'default_employee_id', 'leave_date_from', 'default_date_from')

addons/hr_holidays/tests/test_hr_leave_type.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,59 @@ def test_users_tz_shift_back(self):
114114
).search([('has_valid_allocation', '=', True)], limit=1)
115115

116116
self.assertFalse(leave_types, "Got valid leaves outside vaild period")
117+
118+
def test_search_virtual_remaining_leaves(self):
119+
employee = self.env['hr.employee'].create({'name': 'Test Employee'})
120+
leave_type_1 = self.env['hr.leave.type'].create({
121+
'name': 'Test Leave 1',
122+
'requires_allocation': True,
123+
})
124+
leave_type_2 = self.env['hr.leave.type'].create({
125+
'name': 'Test Leave 2',
126+
'requires_allocation': False,
127+
})
128+
129+
self.env['hr.leave.allocation'].sudo().create({
130+
'state': 'confirm',
131+
'holiday_status_id': leave_type_1.id,
132+
'employee_id': employee.id,
133+
'number_of_days': 4,
134+
'date_from': '2025-01-01',
135+
'date_to': '2025-12-31',
136+
}).action_approve()
137+
138+
result = (
139+
self.env["hr.leave.type"]
140+
.with_context(employee_id=employee.id)
141+
.search([("virtual_remaining_leaves", ">", 0)])
142+
)
143+
self.assertIn(
144+
leave_type_1, result, "Leave Type 1 should be in the result as it has remaining leaves",
145+
)
146+
self.assertIn(
147+
leave_type_2, result, "Leave Type 2 should be in the result since it does not require allocation",
148+
)
149+
150+
result = (
151+
self.env["hr.leave.type"]
152+
.with_context(employee_id=employee.id)
153+
.search([("virtual_remaining_leaves", "=", 0)])
154+
)
155+
self.assertNotIn(
156+
leave_type_1, result, "Leave Type 1 should not be in the result as it has remaining leaves != 0",
157+
)
158+
self.assertIn(
159+
leave_type_2, result, "Leave Type 2 should be in the result since it does not require allocation",
160+
)
161+
162+
result = (
163+
self.env["hr.leave.type"]
164+
.with_context(employee_id=employee.id)
165+
.search([("virtual_remaining_leaves", ">", 4)])
166+
)
167+
self.assertNotIn(
168+
leave_type_1, result, "Leave Type 1 should not be in the result",
169+
)
170+
self.assertIn(
171+
leave_type_2, result, "Leave Type 2 should be in the result since it does not require allocation",
172+
)

0 commit comments

Comments
 (0)