[FIX] google_calenar: remove attendees with alias emails

Before this commit: if one recurrence event in the google calendar
contains an attendee with one of the alias emails, it wouldn't get synced
and raise an error.

The solution is to remove those attendees.

opw-2963825

closes odoo/odoo#101037

X-original-commit: c9fa96604950f61c079627b88495130365d3b534
Signed-off-by: Arnaud Joset <arj@odoo.com>
This commit is contained in:
pedrambiria
2022-09-27 10:38:36 +02:00
parent c7b47f6e6a
commit 2adf005a8b
2 changed files with 46 additions and 1 deletions
@@ -103,8 +103,10 @@ class RecurrenceRule(models.Model):
# Create new attendees
if attendee[2].get('self'):
partner = self.env.user.partner_id
else:
elif attendee[1]:
partner = attendee[1]
else:
continue
self.calendar_event_ids.write({'attendee_ids': [(0, 0, {'state': attendee[2].get('responseStatus'), 'partner_id': partner.id})]})
if attendee[2].get('displayName') and not partner.name:
partner.name = attendee[2].get('displayName')
@@ -1215,3 +1215,46 @@ class TestSyncGoogle2Odoo(TestSyncGoogle):
self.assertTrue(all([a.partner_id.id != self.private_partner.id for a in private_attendees]))
self.assertTrue(all([a.partner_id.type != 'private' for a in private_attendees]))
self.assertGoogleAPINotCalled()
@patch_api
def test_alias_email_sync_recurrence(self):
catchall_domain = self.env['ir.config_parameter'].sudo().get_param("mail.catchall.domain")
alias_model = self.env['ir.model'].search([('model', '=', 'calendar.event')])
self.env['mail.alias'].create({'alias_name': 'sale', 'alias_model_id': alias_model.id})
alias_email = 'sale@%s' % catchall_domain if catchall_domain else 'sale@'
google_id = 'oj44nep1ldf8a3ll02uip0c9aa'
base_event = self.env['calendar.event'].create({
'name': 'coucou',
'allday': True,
'start': datetime(2020, 1, 6),
'stop': datetime(2020, 1, 6),
'need_sync': False,
})
recurrence = self.env['calendar.recurrence'].create({
'google_id': google_id,
'rrule': 'FREQ=WEEKLY;COUNT=2;BYDAY=MO',
'need_sync': False,
'base_event_id': base_event.id,
'calendar_event_ids': [(4, base_event.id)],
})
recurrence._apply_recurrence()
values = {
'id': google_id,
'summary': 'coucou',
'recurrence': ['RRULE:FREQ=WEEKLY;COUNT=2;BYDAY=MO'],
'start': {'date': '2020-01-06'},
'end': {'date': '2020-01-07'},
'reminders': {'useDefault': True},
"attendees": [
{
"email": alias_email, "state": "accepted",
},
],
'updated': self.now,
}
self.env['calendar.recurrence']._sync_google2odoo(GoogleEvent([values]))
events = recurrence.calendar_event_ids.sorted('start')
self.assertEqual(len(events), 2)
self.assertFalse(events.mapped('attendee_ids'))
self.assertGoogleAPINotCalled()