diff --git a/addons/hr_holidays/models/hr_employee.py b/addons/hr_holidays/models/hr_employee.py index 16a318988a2..f8f3e85e15d 100644 --- a/addons/hr_holidays/models/hr_employee.py +++ b/addons/hr_holidays/models/hr_employee.py @@ -180,7 +180,10 @@ class HrEmployeeBase(models.AbstractModel): ('date_from', '<=', today_end), ('date_to', '>=', today_start), ]) - return [('id', 'in', holidays.mapped('employee_id').ids)] + op = 'not in' + if (operator == '=' and value) or (operator == '!=' and not value): + op = 'in' + return [('id', op, holidays.mapped('employee_id').ids)] @api.model_create_multi def create(self, vals_list): diff --git a/addons/hr_holidays/tests/test_out_of_office.py b/addons/hr_holidays/tests/test_out_of_office.py index 567ceabff66..6ad58bb045d 100644 --- a/addons/hr_holidays/tests/test_out_of_office.py +++ b/addons/hr_holidays/tests/test_out_of_office.py @@ -103,3 +103,18 @@ class TestOutOfOfficePerformance(TestHrHolidaysCommon, TransactionCaseWithUserDe self.leave.write({'state': 'validate'}) with self.assertQueryCount(__system__=2, demo=2): self.assertEqual(self.hr_partner.im_status, 'leave_offline') + + def test_search_absent_employee(self): + present_employees = self.env['hr.employee'].search([('is_absent', '!=', 'True')]) + absent_employees = self.env['hr.employee'].search([('is_absent', '=', 'True')]) + today_date = datetime.utcnow().date() + holidays = self.env['hr.leave'].sudo().search([ + ('employee_id', '!=', False), + ('state', 'not in', ['cancel', 'refuse']), + ('date_from', '<=', today_date), + ('date_to', '>=', today_date), + ]) + for employee in present_employees: + self.assertFalse(employee in holidays.employee_id) + for employee in absent_employees: + self.assertFalse(employee not in holidays.employee_id)