Skip to content

Commit 8eee53f

Browse files
yewentaiMahmoudk3m
authored andcommitted
[FIX] hr_holidays: fix leave type operator
Problem --------- The domain helper for allocation-based leave types failed to pass the comparison value to the operator. As a result, creating a new Time Off Type caused a crash. This could be reproduced via: - Time Off → Configuration → Time Off Types → open any type → Smart button “Time Off” → New → Time Off Type - Time Off → Management → Time Off → New Time Off Type Cause ---------- The comparison helper was missing a return value, causing the operator to receive an incomplete set of arguments. Solution ---------- The fix adds the correct return value so the operator is properly executed. task-5381490
1 parent e8d366f commit 8eee53f

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-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
@@ -283,7 +283,7 @@ def _search_virtual_remaining_leaves(self, operator, value):
283283
leave_types = self.env['hr.leave.type'].search([])
284284

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

289289
@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: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,37 @@ 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': 'Virtual Remaining Leaves Employee'})
120+
121+
unlimited_type = self.env['hr.leave.type'].create({
122+
'name': 'Unlimited Time Off',
123+
'requires_allocation': False,
124+
})
125+
126+
allocated_type = self.env['hr.leave.type'].create({
127+
'name': 'Allocated Time Off',
128+
'requires_allocation': True,
129+
})
130+
131+
self.env['hr.leave.allocation'].sudo().create({
132+
'name': 'Allocation',
133+
'holiday_status_id': allocated_type.id,
134+
'employee_id': employee.id,
135+
'number_of_days': 3,
136+
'state': 'confirm',
137+
}).action_approve()
138+
139+
no_allocation_type = self.env['hr.leave.type'].create({
140+
'name': 'No Allocation Time Off',
141+
'requires_allocation': True,
142+
})
143+
144+
matching_types = self.env['hr.leave.type'].with_context(employee_id=employee.id).search([
145+
('virtual_remaining_leaves', '>=', 1),
146+
])
147+
148+
self.assertIn(unlimited_type, matching_types)
149+
self.assertIn(allocated_type, matching_types)
150+
self.assertNotIn(no_allocation_type, matching_types)

0 commit comments

Comments
 (0)