[FIX] calendar: event recurrence start date is not correctly computed
Steps to follow:
- Set your timezone to New York
In linux for example with: `timedatectl set-timezone America/New_York`
- Verify that the user timezone is also set to NY
- Create a reccurent event the 6 july 2022 (a wednesday)
- In options, check the recurrent box
- Set repeat to once every week
- Thursday is the only day checked
-> It should be Wednesday
Cause of the issue:
When `_compute_recurrence` is called, `event.recurrence_id` has not
yet been set
-> `event.recurrence_id.event_tz` is False
=> Copy the defaults before computing the start date and check the
timezone of the event itself
opw-2886253
closes odoo/odoo#96049
X-original-commit: 7186dbad38ef1f05919c398f3c0c5f5d8f8b2219
Signed-off-by: Arnaud Joset <arj@odoo.com>
Signed-off-by: Hubert Van De Walle <huvw@odoo.com>
This commit is contained in:
@@ -352,13 +352,14 @@ class Meeting(models.Model):
|
||||
defaults = self.env['calendar.recurrence'].default_get(recurrence_fields)
|
||||
for event in self:
|
||||
if event.recurrency:
|
||||
event.update(defaults) # default recurrence values are needed to correctly compute the recurrence params
|
||||
event_values = event._get_recurrence_params()
|
||||
rrule_values = {
|
||||
field: event.recurrence_id[field]
|
||||
for field in recurrence_fields
|
||||
if event.recurrence_id[field]
|
||||
}
|
||||
event.update({**false_values, **defaults, **event_values, **rrule_values})
|
||||
event.update({**false_values, **event_values, **rrule_values})
|
||||
else:
|
||||
event.update(false_values)
|
||||
|
||||
@@ -1082,8 +1083,8 @@ class Meeting(models.Model):
|
||||
"""
|
||||
if not self.start:
|
||||
return fields.Date.today()
|
||||
if self.recurrence_id.event_tz:
|
||||
tz = pytz.timezone(self.recurrence_id.event_tz)
|
||||
if self.recurrency and self.event_tz:
|
||||
tz = pytz.timezone(self.event_tz)
|
||||
# Ensure that all day events date are not calculated around midnight. TZ shift would potentially return bad date
|
||||
start = self.start if not self.allday else self.start.replace(hour=12)
|
||||
return pytz.utc.localize(start).astimezone(tz).date()
|
||||
|
||||
@@ -5,6 +5,7 @@ import datetime
|
||||
from datetime import datetime, timedelta, time
|
||||
|
||||
from odoo import fields, Command
|
||||
from odoo.tests import Form
|
||||
from odoo.addons.base.tests.common import SavepointCaseWithUserDemo
|
||||
import pytz
|
||||
import re
|
||||
@@ -186,6 +187,14 @@ class TestCalendar(SavepointCaseWithUserDemo):
|
||||
self.assertEqual(d.hour, 15)
|
||||
self.assertEqual(d.minute, 30)
|
||||
|
||||
def test_recurring_ny(self):
|
||||
self.env.user.tz = 'US/Eastern'
|
||||
f = Form(self.CalendarEvent.with_context(tz='US/Eastern'))
|
||||
f.name = 'test'
|
||||
f.start = '2022-07-07 01:00:00' # This is in UTC. In NY, it corresponds to the 6th of july at 9pm.
|
||||
f.recurrency = True
|
||||
self.assertEqual(f.weekday, 'WED')
|
||||
|
||||
def test_event_activity_timezone(self):
|
||||
activty_type = self.env['mail.activity.type'].create({
|
||||
'name': 'Meeting',
|
||||
|
||||
Reference in New Issue
Block a user