From 16abc4563c815c0c0d3b5bf18cb214d924903b4d Mon Sep 17 00:00:00 2001 From: Henrik Norlin Date: Thu, 1 Feb 2024 11:40:08 +0100 Subject: [PATCH] [FIX] resource_booking: _get_calendar_context() with correct start / timezone --- resource_booking/models/resource_booking.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/resource_booking/models/resource_booking.py b/resource_booking/models/resource_booking.py index effe7d9b..d885c57f 100644 --- a/resource_booking/models/resource_booking.py +++ b/resource_booking/models/resource_booking.py @@ -3,7 +3,7 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). import calendar -from datetime import datetime, timedelta +from datetime import timedelta from dateutil.relativedelta import relativedelta @@ -490,14 +490,18 @@ def _get_calendar_context(self, year=None, month=None, now=None): :param datetime now: Represents the current datetime. """ month1 = relativedelta(months=1) - now = now or fields.Datetime.now() + now = fields.Datetime.context_timestamp(self, now or fields.Datetime.now()) year = year or now.year month = month or now.month - start = datetime(year, month, 1) - start, now = ( - fields.Datetime.context_timestamp(self, dt) for dt in (start, now) + start = now.replace( + year=year, + month=month, + day=1, + hour=0, + minute=0, + second=0, + microsecond=0, ) - start = start.replace(hour=0, minute=0, second=0, microsecond=0) lang = self.env["res.lang"]._lang_get(self.env.lang or self.env.user.lang) weekday_names = dict(lang.fields_get(["week_start"])["week_start"]["selection"]) booking_duration = timedelta(hours=self.duration)