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)), ]