From d522a796d3bd63563a1060083a0a191e7db2b6a2 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Tue, 5 Sep 2017 16:12:44 +0200 Subject: [PATCH] [FIX] calendar: all day event - Set the TZ as 'America/Martinique' - In the calendar (month view), click on a date D. - Fill in the topic, then click on "Edit" The date is set to D-1. Commit 09066fbbd5db makes the date consistent when the user sets an event as an all day event by taking into account the appropriate timezone. However, in the case of an event created from the month view, this TZ modification should not be applied. opw-766638 --- addons/calendar/calendar.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/addons/calendar/calendar.py b/addons/calendar/calendar.py index beee7ed8ee4..ae0cbe60349 100644 --- a/addons/calendar/calendar.py +++ b/addons/calendar/calendar.py @@ -975,6 +975,7 @@ class calendar_event(osv.Model): def onchange_allday(self, cr, uid, ids, start=False, end=False, starttime=False, endtime=False, startdatetime=False, enddatetime=False, checkallday=False, context=None): value = {} + context = context or {} if not ((starttime and endtime) or (start and end)): # At first intialize, we have not datetime return value @@ -983,12 +984,18 @@ class calendar_event(osv.Model): startdatetime = startdatetime or start if startdatetime: start = datetime.strptime(startdatetime, DEFAULT_SERVER_DATETIME_FORMAT) - value['start_date'] = fields.date.context_today(self, cr, uid, context=context, timestamp=start) + if context.get('default_allday'): + value['start_date'] = datetime.strftime(start, DEFAULT_SERVER_DATE_FORMAT) + else: + value['start_date'] = fields.date.context_today(self, cr, uid, context=context, timestamp=start) enddatetime = enddatetime or end if enddatetime: end = datetime.strptime(enddatetime, DEFAULT_SERVER_DATETIME_FORMAT) - value['stop_date'] = fields.date.context_today(self, cr, uid, context=context, timestamp=end) + if context.get('default_allday'): + value['stop_date'] = datetime.strftime(end, DEFAULT_SERVER_DATE_FORMAT) + else: + value['stop_date'] = fields.date.context_today(self, cr, uid, context=context, timestamp=end) else: # from date to datetime user = self.pool['res.users'].browse(cr, uid, uid, context) tz = pytz.timezone(user.tz) if user.tz else pytz.utc