Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
388 Vistas

Hello,

We are using Odoo v16 (Enterprise) and have connected a Google Workspace account to synchronize Google Calendar with the Odoo Calendar module.

After enabling synchronization, Odoo imports all past events, and creates hundreds of contacts from past calendar invites.

This happens automatically and clutters the Contacts module with unnecessary entries (see attached screenshot).


So far we tried:

  • Revoking the connection and re-adding it using a clean calendar – this works, but is not a scalable solution.
  • We couldn't find any configuration to limit sync by date or block contact creation.

Is there a way (setting or recommended customization) to:

  1. Only sync future events from Google Calendar?
  2. Avoid creating res.partner records from Google event attendees?

Any guidance or workaround would be appreciated. Thanks in advance!

Avatar
Descartar
Mejor respuesta

Hi,


When syncing Google Calendar events in Odoo, unknown attendee emails often result in automatic creation of new res.partner records. If you want to avoid creating new partner records, you can override the _get_sync_partner method and change just one line.


Solution Using Inherited Model (google.calendar.sync)

Here’s the full code using model inheritance and making only one change:


from odoo import models, api

from odoo.tools.mail import email_normalize


class GoogleCalendarSync(models.AbstractModel):

    _inherit = 'google.calendar.sync'


    @api.model

    def _get_sync_partner(self, emails):

        normalized_emails = [email_normalize(contact) for contact in emails if email_normalize(contact)]

        user_partners = self.env['mail.thread']._mail_search_on_user(

            normalized_emails,

            extra_domain=[('share', '=', False)]

        )

        partners = list(user_partners)

        remaining = [email for email in normalized_emails if

                     email not in [partner.email_normalized for partner in partners]]

        if remaining:

            #Changed this line: force_create=False to avoid creating new partners

            partners += self.env['mail.thread']._mail_find_partner_from_emails(

                remaining, records=self, force_create=False

            )

        unsorted_partners = self.env['res.partner'].browse([p.id for p in partners if p.id])

        # partners need to be sorted according to the emails order provided by Google

        k = {value: idx for idx, value in enumerate(emails)}

        result = unsorted_partners.sorted(key=lambda p: k.get(p.email_normalized, -1))

        return result



Hope it helps.

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
0
jul 25
339
1
ene 25
1443
2
nov 23
1930
3
nov 22
5084
2
may 20
4733