[FIX] google_calendar: get RRULE when recurrence contains more items
Before this commit: we assumed an event's recurrence only contains RRULE, and we were getting the RRULE from the first element in the list. But it could have EXRULE, RDATE, and EXDATE, so in this case, the first element could be other items. The solution is to iterate through all items and return the RRULE. opw-2797968 closes odoo/odoo#138697 X-original-commit: f2a20457b352026c2dfb50f6a4d48d47211708f9 Signed-off-by: Arnaud Joset (arj) <arj@odoo.com> Signed-off-by: Pedram Bi Ria (pebr) <pebr@odoo.com>
This commit is contained in:
committed by
Pedram (PEBR)
parent
838718cc76
commit
ec25a56c26
@@ -832,6 +832,38 @@ class TestSyncGoogle2Odoo(TestSyncGoogle):
|
||||
)
|
||||
self.assertEqual(len(no_duplicate_event), 1)
|
||||
|
||||
@patch_api
|
||||
def test_recurrence_list_contains_more_items(self):
|
||||
recurrence_id = 'oj44nep1ldf8a3ll02uip0c9aa'
|
||||
values = {
|
||||
'id': recurrence_id,
|
||||
'description': 'Small mini desc',
|
||||
'organizer': {'email': 'odoocalendarref@gmail.com', 'self': True},
|
||||
'summary': 'Pricing new update',
|
||||
'visibility': 'public',
|
||||
'recurrence': ['EXDATE;TZID=Europe/Rome:20200113',
|
||||
'RRULE:FREQ=WEEKLY;COUNT=3;BYDAY=MO'],
|
||||
'reminders': {'useDefault': True},
|
||||
'start': {'date': '2020-01-6'},
|
||||
'end': {'date': '2020-01-7'},
|
||||
}
|
||||
self.env['calendar.recurrence']._sync_google2odoo(GoogleEvent([values]))
|
||||
recurrence = self.env['calendar.recurrence'].search([('google_id', '=', values.get('id'))])
|
||||
self.assertTrue(recurrence, "it should have created a recurrence")
|
||||
events = recurrence.calendar_event_ids.sorted('start')
|
||||
self.assertEqual(len(events), 3, "it should have created a recurrence with 3 events")
|
||||
self.assertTrue(all(events.mapped('recurrency')))
|
||||
self.assertEqual(events[0].start_date, date(2020, 1, 6))
|
||||
self.assertEqual(events[1].start_date, date(2020, 1, 13))
|
||||
self.assertEqual(events[2].start_date, date(2020, 1, 20))
|
||||
self.assertEqual(events[0].stop_date, date(2020, 1, 6))
|
||||
self.assertEqual(events[1].stop_date, date(2020, 1, 13))
|
||||
self.assertEqual(events[2].stop_date, date(2020, 1, 20))
|
||||
self.assertEqual(events[0].google_id, '%s_20200106' % recurrence_id)
|
||||
self.assertEqual(events[1].google_id, '%s_20200113' % recurrence_id)
|
||||
self.assertEqual(events[2].google_id, '%s_20200120' % recurrence_id)
|
||||
self.assertGoogleAPINotCalled()
|
||||
|
||||
@patch_api
|
||||
def test_simple_event_into_recurrency(self):
|
||||
""" Synched single events should be converted in recurrency without problems"""
|
||||
|
||||
@@ -64,10 +64,9 @@ class GoogleEvent(abc.Set):
|
||||
|
||||
@property
|
||||
def rrule(self):
|
||||
if self.recurrence:
|
||||
# Find the rrule in the list
|
||||
rrule = next(rr for rr in self.recurrence if 'RRULE:' in rr)
|
||||
return rrule[6:] # skip "RRULE:" in the rrule string
|
||||
if self.recurrence and any('RRULE' in item for item in self.recurrence):
|
||||
rrule = next(item for item in self.recurrence if 'RRULE' in item)
|
||||
return rrule[6:] # skip "RRULE:" in the rrule string
|
||||
|
||||
def odoo_id(self, env):
|
||||
self.odoo_ids(env) # load ids
|
||||
|
||||
Reference in New Issue
Block a user