콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
671 화면

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!

아바타
취소
베스트 답변

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.

아바타
취소
관련 게시물 답글 화면 활동
0
7월 25
624
1
1월 25
1672
2
11월 23
2146
3
9월 25
5302
2
5월 20
4917