Skip to content

Commit 8724928

Browse files
hazemayman1arpi-odoo
authored andcommitted
[FIX] hr_holidays: fix traceback bug when selecting leave type
Steps to reproduce: - On the Time Off app go to Configuration -> Time Off Types - Select any time off type the click the Time Off smart button - Click new and on the creation form try changing the Time Off type for an employee Cause of the bug: - The function that compares the leave type days and the employee's remaining leave days only gets the leave type days as an input, the other argument is missing Fix done: - Passing the input value as the second argument for the op(v1, v2) function task-5380284
1 parent ac0362b commit 8724928

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,21 @@ 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+
self.env['hr.leave.type'].create({
120+
'name': 'leave_with_allocation',
121+
'time_type': 'leave',
122+
'requires_allocation': True,
123+
'virtual_remaining_leaves': 100,
124+
})
125+
126+
self.env['hr.leave.type'].create({
127+
'name': 'leave_without_allocation',
128+
'time_type': 'leave',
129+
'requires_allocation': False,
130+
'virtual_remaining_leaves': 100,
131+
})
132+
133+
self.assertNotIn('leave_with_allocation', self.env['hr.leave.type'].search(domain=[('virtual_remaining_leaves', '>', 0)]).mapped('name'))
134+
self.assertIn('leave_without_allocation', self.env['hr.leave.type'].search(domain=[('virtual_remaining_leaves', '>', 0)]).mapped('name'))

0 commit comments

Comments
 (0)