[FIX] microsoft_calendar: enable syncing of events without an organizer

Before this commit, an Outlook event without an organizer would fail to
sync with Odoo. This commit fixes this issue by allowing events without
an organizer to be synced from Outlook to Odoo.

opw-3701839

closes odoo/odoo#153683

X-original-commit: 4f441aa083413e475728f4f510afdbb9f15a26ef
Signed-off-by: Arnaud Joset (arj) <arj@odoo.com>
This commit is contained in:
Pedram (pebr)
2024-02-13 16:07:29 +00:00
parent 6b724a2333
commit c8e6a82bc6
2 changed files with 26 additions and 0 deletions
@@ -474,3 +474,26 @@ class TestCreateEvents(TestCommon):
# Ensure that event was successfully created in Odoo (no ACL error was triggered blocking creation).
portal_user_events = self.env['calendar.event'].search([('user_id', '=', portal_user.id)])
self.assertEqual(len(portal_user_events), 1)
@patch.object(MicrosoftCalendarService, 'get_events')
def test_create_simple_event_from_outlook_without_organizer(self, mock_get_events):
"""
Allow creation of an event without organizer in Outlook and sync it in Odoo.
"""
# arrange
outlook_event = self.simple_event_from_outlook_attendee
outlook_event = dict(self.simple_event_from_outlook_attendee, organizer=None)
expected_event = dict(self.expected_odoo_event_from_outlook, user_id=False)
mock_get_events.return_value = (MicrosoftEvent([outlook_event]), None)
existing_records = self.env["calendar.event"].search([])
# act
self.organizer_user.with_user(self.organizer_user).sudo()._sync_microsoft_calendar()
# assert
records = self.env["calendar.event"].search([])
new_records = (records - existing_records)
self.assertEqual(len(new_records), 1)
self.assert_odoo_event(new_records, expected_event)
@@ -167,6 +167,9 @@ class MicrosoftEvent(abc.Set):
if self.isOrganizer:
return env.user.id
if not self.organizer:
return False
organizer_email = self.organizer.get('emailAddress') and email_normalize(self.organizer.get('emailAddress').get('address'))
if organizer_email:
# Warning: In Microsoft: 1 email = 1 user; but in Odoo several users might have the same email