Skip to content

Commit 1df0172

Browse files
committed
[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 a165720 commit 1df0172

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-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: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,75 @@ 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+
test_cases = [
139+
# (operator, value, expected_leave_type_1, expected_leave_type_2, description_type_1, description_type_2)
140+
(
141+
">",
142+
0,
143+
True,
144+
True,
145+
"should be in the result as it has remaining leaves",
146+
"should be in the result since it does not require allocation",
147+
),
148+
(
149+
"=",
150+
0,
151+
False,
152+
True,
153+
"should not be in the result as it has remaining leaves != 0",
154+
"should be in the result since it does not require allocation",
155+
),
156+
(
157+
">",
158+
4,
159+
False,
160+
True,
161+
"should not be in the result",
162+
"should be in the result since it does not require allocation",
163+
),
164+
]
165+
166+
for (
167+
operator,
168+
value,
169+
expected_type_1,
170+
expected_type_2,
171+
description_type_1,
172+
description_type_2,
173+
) in test_cases:
174+
result = (
175+
self.env["hr.leave.type"]
176+
.with_context(employee_id=employee.id)
177+
.search([("virtual_remaining_leaves", operator, value)])
178+
)
179+
self.assertIn(
180+
leave_type_1, result, f"Leave Type 1 {description_type_1}",
181+
) if expected_type_1 else self.assertNotIn(
182+
leave_type_1, result, f"Leave Type 1 {description_type_1}",
183+
)
184+
self.assertIn(
185+
leave_type_2, result, f"Leave Type 2 {description_type_2}",
186+
) if expected_type_2 else self.assertNotIn(
187+
leave_type_2, result, f"Leave Type 2 {description_type_2}",
188+
)

0 commit comments

Comments
 (0)