From 6ba2d269400c692d5f5b7de4f8669a1ef95c7787 Mon Sep 17 00:00:00 2001 From: "Abdelouahab (abla)" Date: Wed, 8 Mar 2023 16:24:45 +0000 Subject: [PATCH] [FIX] hr_holidays: is absent search To Reproduce ============ - go to employees app and filter by `Absent is Yes` then by `Absent is No` some employees are present in both filters which is not logical Problem ======= the search method on `is_absent` field always performs the search `ids in absent_ids` no matter what are the operator and the value Solution ======== use the `operator` argument in the searching opw-3205967 closes odoo/odoo#115443 X-original-commit: 89a762ec463efd936c5d60a483f3cac876724b7e Signed-off-by: Yannick Tivisse (yti) Signed-off-by: abla001 --- addons/hr_holidays/models/hr_employee.py | 5 ++++- addons/hr_holidays/tests/test_out_of_office.py | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) 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)