def reset_account(self):
        microsoft = MicrosoftCalendarService(self.env['microsoft.service'])

        events = self.env['calendar.event'].search([
            ('user_id', '=', self.user_id.id), ('microsoft_id', '!=', False)
        ])
        if self.delete_policy in ('delete_microsoft', 'delete_both'):
            with microsoft_calendar_token(self.user_id) as token:
                for event in events:
                    microsoft.delete(event.microsoft_id, token=token)

        if self.delete_policy in ('delete_odoo', 'delete_both'):
            events.microsoft_id = False
            events.unlink()

        if self.sync_policy == 'all':
            events.write({
                'microsoft_id': False,
                'need_sync_m': True,
            })

        self.user_id._set_microsoft_auth_tokens(False, False, 0)
        self.user_id.write({
            'microsoft_calendar_sync_token': False,
        })
Ejemplo n.º 2
0
 def _microsoft_delete(self,
                       microsoft_service: MicrosoftCalendarService,
                       microsoft_id,
                       timeout=TIMEOUT):
     with microsoft_calendar_token(self.env.user.sudo()) as token:
         if token:
             microsoft_service.delete(microsoft_id,
                                      token=token,
                                      timeout=timeout)