From e7f3a78abea712d3b4355d87dad44399037951ac Mon Sep 17 00:00:00 2001 From: Florian Damhaut Date: Fri, 18 Aug 2023 16:23:38 +0200 Subject: [PATCH] [FIX] ressource: _leave_intervals_batch find public leaves Issue : - When you check-in/out on a day of time off, all the time is logged as extra hours. - When you do the same on a public holiday, it's not. _leave_intervals_batch is used to get all leave for an employee but the domain for the search only find leaves related to given ressources. Public Holiday Leaves are not related to any specific ressources and thus where never found. closes odoo/odoo#142728 Task-id: 3465686 X-original-commit: 8d7100d08ecabe72dc9aedb036d7908fcd7a35bb Signed-off-by: Sofie Gvaladze (sgv) --- addons/hr_holidays_attendance/models/hr_attendance.py | 3 ++- .../tests/test_holidays_overtime.py | 11 +++++++++++ addons/resource/models/resource_calendar.py | 4 ++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/addons/hr_holidays_attendance/models/hr_attendance.py b/addons/hr_holidays_attendance/models/hr_attendance.py index 83d40189bac..e98e21f8a62 100644 --- a/addons/hr_holidays_attendance/models/hr_attendance.py +++ b/addons/hr_holidays_attendance/models/hr_attendance.py @@ -10,4 +10,5 @@ class HrAttendance(models.Model): def _get_overtime_leave_domain(self): domain = super()._get_overtime_leave_domain() - return AND([domain, [('holiday_id.holiday_status_id.time_type', '=', 'leave')]]) + # resource_id = False => Public holidays + return AND([domain, ['|', ('holiday_id.holiday_status_id.time_type', '=', 'leave'), ('resource_id', '=', False)]]) diff --git a/addons/hr_holidays_attendance/tests/test_holidays_overtime.py b/addons/hr_holidays_attendance/tests/test_holidays_overtime.py index b29ad901306..0f4f8be92d0 100644 --- a/addons/hr_holidays_attendance/tests/test_holidays_overtime.py +++ b/addons/hr_holidays_attendance/tests/test_holidays_overtime.py @@ -244,3 +244,14 @@ class TestHolidaysOvertime(TransactionCase): .new({'reason': 'Test remove holiday'}) \ .action_cancel_leave() self.assertFalse(leave.overtime_id.exists()) + + def test_public_leave_overtime(self): + self.env['resource.calendar.leaves'].create([{ + 'name': 'Public Holiday', + 'date_from': datetime(2022, 5, 5, 6), + 'date_to': datetime(2022, 5, 5, 18), + 'time_type': 'leave', + }]) + + self.new_attendance(check_in=datetime(2022, 5, 5, 8), check_out=datetime(2022, 5, 5, 16)) + self.assertEqual(self.employee.total_overtime, 7, 'Should have 7 hours of overtime (there is one hour of lunch)') diff --git a/addons/resource/models/resource_calendar.py b/addons/resource/models/resource_calendar.py index 3b480098485..a5aaad0cae8 100644 --- a/addons/resource/models/resource_calendar.py +++ b/addons/resource/models/resource_calendar.py @@ -384,14 +384,14 @@ class ResourceCalendar(models.Model): resources_list = [resources] else: resources_list = list(resources) + [self.env['resource.resource']] - resource_ids = [r.id for r in resources_list] if domain is None: domain = [('time_type', '=', 'leave')] if not any_calendar: domain = domain + [('calendar_id', 'in', [False, self.id])] # for the computation, express all datetimes in UTC + # Public leave don't have a resource_id domain = domain + [ - ('resource_id', 'in', resource_ids), + ('resource_id', 'in', [False] + [r.id for r in resources_list]), ('date_from', '<=', datetime_to_string(end_dt)), ('date_to', '>=', datetime_to_string(start_dt)), ]