From ec25a56c2636f4d858adca5024893e931cb64d06 Mon Sep 17 00:00:00 2001 From: pedrambiria Date: Wed, 30 Mar 2022 10:58:58 +0000 Subject: [PATCH] [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) Signed-off-by: Pedram Bi Ria (pebr) --- .../tests/test_sync_google2odoo.py | 32 +++++++++++++++++++ addons/google_calendar/utils/google_event.py | 7 ++-- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/addons/google_calendar/tests/test_sync_google2odoo.py b/addons/google_calendar/tests/test_sync_google2odoo.py index caff6f75b48..b7d8319a9bf 100644 --- a/addons/google_calendar/tests/test_sync_google2odoo.py +++ b/addons/google_calendar/tests/test_sync_google2odoo.py @@ -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""" diff --git a/addons/google_calendar/utils/google_event.py b/addons/google_calendar/utils/google_event.py index 44e68c53ddc..61e03dd4903 100644 --- a/addons/google_calendar/utils/google_event.py +++ b/addons/google_calendar/utils/google_event.py @@ -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