From ebe510f223a09b283ffb38007bed0b3f6d21127c Mon Sep 17 00:00:00 2001 From: Carmen Bianca BAKKER Date: Fri, 30 Aug 2024 16:31:40 +0200 Subject: [PATCH] fixup! [IMP] resource_multi_week_calendar: Implement _attendance_intervals_batch Signed-off-by: Carmen Bianca BAKKER --- .../models/resource_calendar.py | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/resource_multi_week_calendar/models/resource_calendar.py b/resource_multi_week_calendar/models/resource_calendar.py index b9432800f43..37c7b31ee06 100644 --- a/resource_multi_week_calendar/models/resource_calendar.py +++ b/resource_multi_week_calendar/models/resource_calendar.py @@ -192,24 +192,22 @@ def get_multi_week_epoch_date(self): @api.model def _split_into_weeks(self, start_dt, end_dt): + # TODO: This method splits weeks on the timezone of start_dt. Maybe it + # should split weeks on the timezone of the calendar. It is not + # immediately clear to me how to implement that. current_start = start_dt - - while current_start <= end_dt: - # Calculate the end of the week (Sunday, 23:59:59) - days_until_sunday = 6 - current_start.weekday() - week_end = current_start + timedelta(days=days_until_sunday) - week_end = week_end.replace( - hour=23, minute=59, second=59, microsecond=999999 - ) + while current_start < end_dt: + # Calculate the end of the week (Monday 00:00:00, the threshold + # of Sunday-to-Monday.) + days_until_monday = 7 - current_start.weekday() + week_end = current_start + timedelta(days=days_until_monday) + week_end = week_end.replace(hour=0, minute=0, second=0, microsecond=0) current_end = min(week_end, end_dt) yield (current_start, current_end) # Move to the next week (start of next Monday) - current_start = current_end + timedelta(days=1) - current_start = current_start.replace( - hour=0, minute=0, second=0, microsecond=0 - ) + current_start = current_end def _attendance_intervals_batch( self, start_dt, end_dt, resources=None, domain=None, tz=None