From 76d4c3f3a34de6cfbd117e8668f624cbe0257800 Mon Sep 17 00:00:00 2001 From: joyep-odoo Date: Tue, 2 Dec 2025 17:47:53 +0100 Subject: [PATCH] [FIX] hr_holidays: fix leave type operator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- addons/hr_holidays/models/hr_leave_type.py | 2 +- .../hr_holidays/tests/test_hr_leave_type.py | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/addons/hr_holidays/models/hr_leave_type.py b/addons/hr_holidays/models/hr_leave_type.py index 4093f0d66dff8..44c72709a2775 100644 --- a/addons/hr_holidays/models/hr_leave_type.py +++ b/addons/hr_holidays/models/hr_leave_type.py @@ -283,7 +283,7 @@ def _search_virtual_remaining_leaves(self, operator, value): leave_types = self.env['hr.leave.type'].search([]) def is_valid(leave_type): - return not leave_type.requires_allocation or op(leave_type.virtual_remaining_leaves) + return not leave_type.requires_allocation or op(leave_type.virtual_remaining_leaves, value) return [('id', 'in', leave_types.filtered(is_valid).ids)] @api.depends_context('employee_id', 'default_employee_id', 'leave_date_from', 'default_date_from') diff --git a/addons/hr_holidays/tests/test_hr_leave_type.py b/addons/hr_holidays/tests/test_hr_leave_type.py index b7732013987c5..64ee10d0cc224 100644 --- a/addons/hr_holidays/tests/test_hr_leave_type.py +++ b/addons/hr_holidays/tests/test_hr_leave_type.py @@ -114,3 +114,38 @@ def test_users_tz_shift_back(self): ).search([('has_valid_allocation', '=', True)], limit=1) self.assertFalse(leave_types, "Got valid leaves outside vaild period") + + @tagged('test_search_virtual_remaining_leaves', 'at_install', '-post_install') + def test_search_virtual_remaining_leaves(self): + employee = self.env['hr.employee'].create({'name': 'Virtual Remaining Leaves Employee'}) + + unlimited_type = self.env['hr.leave.type'].create({ + 'name': 'Unlimited Time Off', + 'requires_allocation': False, + }) + + allocated_type = self.env['hr.leave.type'].create({ + 'name': 'Allocated Time Off', + 'requires_allocation': True, + }) + + self.env['hr.leave.allocation'].sudo().create({ + 'name': 'Allocation', + 'holiday_status_id': allocated_type.id, + 'employee_id': employee.id, + 'number_of_days': 3, + 'state': 'confirm', + }).action_approve() + + no_allocation_type = self.env['hr.leave.type'].create({ + 'name': 'No Allocation Time Off', + 'requires_allocation': True, + }) + + matching_types = self.env['hr.leave.type'].with_context(employee_id=employee.id).search([ + ('virtual_remaining_leaves', '>=', 1), + ]) + + self.assertIn(unlimited_type, matching_types) + self.assertIn(allocated_type, matching_types) + self.assertNotIn(no_allocation_type, matching_types)