Example #1
0
    def _sync_google2odoo(self,
                          google_events: GoogleEvent,
                          default_reminders=()):
        """Synchronize Google recurrences in Odoo. Creates new recurrences, updates
        existing ones.

        :param google_recurrences: Google recurrences to synchronize in Odoo
        :return: synchronized odoo recurrences
        """
        existing = google_events.exists(self.env)
        new = google_events - existing - google_events.cancelled()

        odoo_values = [
            dict(self._odoo_values(e, default_reminders), need_sync=False)
            for e in new
        ]
        new_odoo = self.create(odoo_values)

        cancelled = existing.cancelled()
        cancelled_odoo = self.browse(cancelled.odoo_ids(self.env))
        cancelled_odoo._cancel()

        synced_records = new_odoo + cancelled_odoo
        for gevent in existing - cancelled:
            # Last updated wins.
            # This could be dangerous if google server time and odoo server time are different
            updated = parse(gevent.updated)
            odoo_record = self.browse(gevent.odoo_id(self.env))
            if updated >= pytz.utc.localize(odoo_record.write_date):
                vals = dict(self._odoo_values(gevent, default_reminders),
                            need_sync=False)
                odoo_record.write(vals)
                synced_records |= odoo_record

        return synced_records
Example #2
0
    def _sync_google2odoo(self, google_events: GoogleEvent, default_reminders=()):
        """Synchronize Google recurrences in Odoo. Creates new recurrences, updates
        existing ones.

        :param google_recurrences: Google recurrences to synchronize in Odoo
        :return: synchronized odoo recurrences
        """
        existing = google_events.exists(self.env)
        new = google_events - existing - google_events.cancelled()

        odoo_values = [
            dict(self._odoo_values(e, default_reminders), need_sync=False)
            for e in new
        ]
        new_odoo = self.with_context(dont_notify=True)._create_from_google(new, odoo_values)
        # Synced recurrences attendees will be notified once _apply_recurrence is called.
        if not self._context.get("dont_notify") and all(not e.is_recurrence() for e in google_events):
            new_odoo._notify_attendees()

        cancelled = existing.cancelled()
        cancelled_odoo = self.browse(cancelled.odoo_ids(self.env))
        cancelled_odoo._cancel()
        synced_records = (new_odoo + cancelled_odoo).with_context(dont_notify=self._context.get("dont_notify", False))
        for gevent in existing - cancelled:
            # Last updated wins.
            # This could be dangerous if google server time and odoo server time are different
            updated = parse(gevent.updated)
            odoo_record = self.browse(gevent.odoo_id(self.env))
            # Migration from 13.4 does not fill write_date. Therefore, we force the update from Google.
            if not odoo_record.write_date or updated >= pytz.utc.localize(odoo_record.write_date):
                vals = dict(self._odoo_values(gevent, default_reminders), need_sync=False)
                odoo_record._write_from_google(gevent, vals)
                synced_records |= odoo_record

        return synced_records