Skip to content

Commit 208c4a6

Browse files
[FIX] hr_holidays: fix time off type error in time off form view
1. Go to **Time Off > Configuration > Time Off Types**. 2. Open a type and click the "Time Off" smart button. 3. Click **New**. 4. An error appears. [[Reference Video](https://drive.google.com/file/d/1vi_apL24Km5tSomQtwcTArqqWvrBR5ni/view)] In the `_search_virtual_remaining_leaves` method, the code tries to use an operator (like `>`) to compare the `virtual_remaining_leaves`. This operator requires **two** arguments to work. However, the code was only passing **one** argument, missing the `value` to compare against. This caused the "expects 2 arguments" error. Passed the missing `value` to the operator call so the comparison can be completed correctly. Task: 5241685
1 parent af46c2a commit 208c4a6

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-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: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,26 @@ 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_id = self.env['hr.employee'].create({'name': 'Test Employee'})
120+
leave_type1 = self.env['hr.leave.type'].create({
121+
'name': 'Leave type 1',
122+
'time_type': 'leave',
123+
'requires_allocation': True,
124+
})
125+
leave_type2 = self.env['hr.leave.type'].create({
126+
'name': 'Leave type 2',
127+
'time_type': 'leave',
128+
'requires_allocation': True,
129+
})
130+
self.env['hr.leave.allocation'].create([{
131+
'name': 'Leave type 1 allocation',
132+
'holiday_status_id': leave_type1.id,
133+
'number_of_days': 1,
134+
'employee_id': employee_id.id,
135+
'state': 'confirm',
136+
}]).action_approve()
137+
leave_type_ids = self.env['hr.leave.type'].with_context(employee_id=employee_id.id).search([('virtual_remaining_leaves', '>', 0)])
138+
self.assertIn(leave_type1, leave_type_ids)
139+
self.assertNotIn(leave_type2, leave_type_ids)

0 commit comments

Comments
 (0)