Exemple #1
0
    def test_recurrence_write_with_outliers(self):
        google_id = 'oj44nep1ldf8a3ll02uip0c9aa'
        base_event = self.env['calendar.event'].create({
            'name':
            'coucou',
            'start':
            datetime(2021, 2, 15, 8, 0, 0),
            'stop':
            datetime(2021, 2, 15, 10, 0, 0),
            'need_sync':
            False,
        })
        recurrence = self.env['calendar.recurrence'].create({
            'google_id':
            google_id,
            'rrule':
            'FREQ=WEEKLY;COUNT=3;BYDAY=MO',
            'need_sync':
            False,
            'base_event_id':
            base_event.id,
            'calendar_event_ids': [(4, base_event.id)],
        })
        recurrence._apply_recurrence()
        events = recurrence.calendar_event_ids.sorted('start')
        self.assertEqual(events[0].google_id,
                         '%s_20210215T080000Z' % google_id)
        self.assertEqual(events[1].google_id,
                         '%s_20210222T080000Z' % google_id)
        self.assertEqual(events[2].google_id,
                         '%s_20210301T080000Z' % google_id)
        # Modify start of one of the events.
        middle_event = recurrence.calendar_event_ids.filtered(
            lambda e: e.start == datetime(2021, 2, 22, 8, 0, 0))
        middle_event.write({
            'start': datetime(2021, 2, 22, 16, 0, 0),
            'need_sync': False,
        })

        values = {
            'id': google_id,
            'summary': 'coucou again',
            'recurrence': ['RRULE:FREQ=WEEKLY;COUNT=3;BYDAY=MO'],
            'start': {
                'dateTime': '2021-02-15T09:00:00+01:00'
            },  # 8:00 UTC
            'end': {
                'dateTime': '2021-02-15-T11:00:00+01:00'
            },
            'reminders': {
                'useDefault': True
            },
            "attendees": [
                {
                    "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), 3)
        self.assertEqual(recurrence.rrule, 'FREQ=WEEKLY;COUNT=3;BYDAY=MO')
        self.assertEqual(events.mapped('name'),
                         ['coucou again', 'coucou again', 'coucou again'])
        self.assertEqual(events[0].start, datetime(2021, 2, 15, 8, 0, 0))
        self.assertEqual(events[1].start, datetime(2021, 2, 22, 16, 0, 0))
        self.assertEqual(events[2].start, datetime(2021, 3, 1, 8, 0, 0))
        # the google_id of recurrent events should not be modified when events start is modified.
        # the original start date or datetime should always be present.
        self.assertEqual(events[0].google_id,
                         '%s_20210215T080000Z' % google_id)
        self.assertEqual(events[1].google_id,
                         '%s_20210222T080000Z' % google_id)
        self.assertEqual(events[2].google_id,
                         '%s_20210301T080000Z' % google_id)
        self.assertGoogleAPINotCalled()
Exemple #2
0
    def test_new_google_notifications(self):
        """ Event from Google should not create notifications and trigger. It ruins the perfs on large databases """
        cron_id = self.env.ref('calendar.ir_cron_scheduler_alarm').id
        triggers_before = self.env['ir.cron.trigger'].search([('cron_id', '=',
                                                               cron_id)])
        google_id = 'oj44nep1ldf8a3ll02uip0c9aa'
        start = datetime.today() + relativedelta(months=1, day=1, hours=1)
        end = datetime.today() + relativedelta(months=1, day=1, hours=2)
        updated = datetime.today() + relativedelta(minutes=1)
        values = {
            'id':
            google_id,
            'description':
            'Small mini desc',
            'organizer': {
                'email': '*****@*****.**',
                'self': True
            },
            'summary':
            'Pricing new update',
            'visibility':
            'public',
            'attendees': [
                {
                    'displayName': 'Mitchell Admin',
                    'email': '*****@*****.**',
                    'responseStatus': 'needsAction'
                },
            ],
            'reminders': {
                'overrides': [{
                    "method": "email",
                    "minutes": 10
                }],
                'useDefault': False
            },
            'start': {
                'dateTime': pytz.utc.localize(start).isoformat(),
                'timeZone': 'Europe/Brussels'
            },
            'end': {
                'dateTime': pytz.utc.localize(end).isoformat(),
                'timeZone': 'Europe/Brussels'
            },
        }
        self.env['calendar.event']._sync_google2odoo(GoogleEvent([values]))
        triggers_after = self.env['ir.cron.trigger'].search([('cron_id', '=',
                                                              cron_id)])
        new_triggers = triggers_after - triggers_before
        self.assertFalse(new_triggers,
                         "The event should not be created with triggers.")

        # Event was created from Google and now it will be Updated from Google.
        # No further notifications should be created.
        values = {
            'id':
            google_id,
            'updated':
            pytz.utc.localize(updated).isoformat(),
            'description':
            'New Super description',
            'organizer': {
                'email': '*****@*****.**',
                'self': True
            },
            'summary':
            'Pricing was not good, now it is correct',
            'visibility':
            'public',
            'attendees': [
                {
                    'displayName': 'Mitchell Admin',
                    'email': '*****@*****.**',
                    'responseStatus': 'needsAction'
                },
            ],
            'reminders': {
                'overrides': [{
                    "method": "email",
                    "minutes": 10
                }],
                'useDefault': False
            },
            'start': {
                'dateTime': pytz.utc.localize(start).isoformat(),
                'timeZone': 'Europe/Brussels'
            },
            'end': {
                'dateTime': pytz.utc.localize(end).isoformat(),
                'timeZone': 'Europe/Brussels'
            },
        }
        self.env['calendar.event']._sync_google2odoo(GoogleEvent([values]))
        triggers_after = self.env['ir.cron.trigger'].search([('cron_id', '=',
                                                              cron_id)])
        new_triggers = triggers_after - triggers_before
        self.assertFalse(new_triggers,
                         "The event should not be created with triggers.")
        self.assertGoogleAPINotCalled()
Exemple #3
0
 def test_attendee_recurrence_answer(self):
     """ Write on a recurrence to update all attendee answers """
     other_user = new_test_user(self.env, login='******')
     google_id = "aaaaaaaaaaa"
     base_event = self.env['calendar.event'].create({
         'name':
         'coucou',
         'start':
         datetime(2021, 2, 15, 7, 0, 0),
         'stop':
         datetime(2021, 2, 15, 9, 0, 0),
         'event_tz':
         'Europe/Brussels',
         'need_sync':
         False,
         'partner_ids': [(6, 0, [other_user.partner_id.id])]
     })
     recurrence = self.env['calendar.recurrence'].create({
         'google_id':
         google_id,
         'rrule':
         'FREQ=WEEKLY;COUNT=3;BYDAY=MO',
         'need_sync':
         False,
         'base_event_id':
         base_event.id,
         'calendar_event_ids': [(4, base_event.id)],
     })
     recurrence._apply_recurrence()
     recurrence.calendar_event_ids.attendee_ids.state = 'accepted'
     values = {
         'id':
         google_id,
         "updated":
         self.now,
         'description':
         '',
         'attendees': [{
             'email': '*****@*****.**',
             'responseStatus': 'declined'
         }],
         'summary':
         'coucou',
         # 'visibility': 'public',
         'recurrence': ['RRULE:FREQ=WEEKLY;COUNT=3;BYDAY=MO'],
         'reminders': {
             'useDefault': True
         },
         'start': {
             'dateTime': '2021-02-15T8:00:00+01:00',
             'timeZone': 'Europe/Brussels'
         },
         'end': {
             'dateTime': '2021-02-15T10:00:00+01:00',
             'timeZone': 'Europe/Brussels'
         },
     }
     self.env['calendar.recurrence']._sync_google2odoo(GoogleEvent([values
                                                                    ]))
     attendee = recurrence.calendar_event_ids.attendee_ids.mapped('state')
     self.assertEqual(attendee, ['declined', 'declined', 'declined'],
                      "All events should be declined")
     self.assertGoogleAPINotCalled()
Exemple #4
0
 def test_simple_event_into_recurrency(self):
     """ Synched single events should be converted in recurrency without problems"""
     google_id = 'aaaaaaaaaaaa'
     values = {
         'id':
         google_id,
         'description':
         'Small mini desc',
         'organizer': {
             'email': '*****@*****.**',
             'self': True
         },
         'summary':
         'Pricing new update',
         'visibility':
         'public',
         'attendees': [
             {
                 'displayName': 'Mitchell Admin',
                 'email': '*****@*****.**',
                 'responseStatus': 'needsAction'
             },
         ],
         'reminders': {
             'useDefault': True
         },
         'start': {
             'dateTime': '2020-01-06T18:00:00+01:00',
             'timeZone': 'Europe/Brussels'
         },
         'end': {
             'dateTime': '2020-01-13T19:55:00+01:00',
             'timeZone': 'Europe/Brussels'
         },
     }
     self.env['calendar.event']._sync_google2odoo(GoogleEvent([values]))
     # The event is transformed into a recurrency on google
     values = {
         'id': google_id,
         'description': '',
         'organizer': {
             'email': '*****@*****.**',
             'self': True
         },
         'summary': 'Event with ',
         'visibility': 'public',
         'recurrence': ['RRULE:FREQ=WEEKLY;WKST=SU;COUNT=3;BYDAY=MO'],
         'reminders': {
             'useDefault': True
         },
         'start': {
             'dateTime': '2020-01-06T18:00:00+01:00',
             'timeZone': 'Europe/Brussels'
         },
         'end': {
             'dateTime': '2020-01-06T19:00:00+01:00',
             'timeZone': 'Europe/Brussels'
         },
     }
     recurrence = self.env['calendar.recurrence']._sync_google2odoo(
         GoogleEvent([values]))
     events = recurrence.calendar_event_ids.sorted('start')
     self.assertEqual(len(events), 3,
                      "it should have created a recurrence with 3 events")
     event = self.env['calendar.event'].search([('google_id', '=',
                                                 values.get('id'))])
     self.assertFalse(event.exists(),
                      "The old event should not exits anymore")
     self.assertGoogleAPINotCalled()