diff --git a/addons/google_calendar/models/calendar.py b/addons/google_calendar/models/calendar.py index 811ce5b2df6..b45a6f6749f 100644 --- a/addons/google_calendar/models/calendar.py +++ b/addons/google_calendar/models/calendar.py @@ -45,7 +45,7 @@ class Meeting(models.Model): @api.model def _get_google_synced_fields(self): return {'name', 'description', 'allday', 'start', 'date_end', 'stop', - 'attendee_ids', 'alarm_ids', 'location', 'privacy', 'active'} + 'attendee_ids', 'alarm_ids', 'location', 'privacy', 'active', 'show_as'} @api.model def _restart_google_sync(self): @@ -324,6 +324,8 @@ class Meeting(models.Model): values['conferenceData'] = {'createRequest': {'requestId': uuid4().hex}} if self.privacy: values['visibility'] = self.privacy + if self.show_as: + values['transparency'] = 'opaque' if self.show_as == 'busy' else 'transparent' if not self.active: values['status'] = 'cancelled' if self.user_id and self.user_id != self.env.user and not bool(self.user_id.sudo().google_calendar_token): diff --git a/addons/google_calendar/tests/test_sync_google2odoo.py b/addons/google_calendar/tests/test_sync_google2odoo.py index 7c6b360fb58..4b9643d307c 100644 --- a/addons/google_calendar/tests/test_sync_google2odoo.py +++ b/addons/google_calendar/tests/test_sync_google2odoo.py @@ -387,6 +387,7 @@ class TestSyncGoogle2Odoo(TestSyncGoogle): 'reminders': {'useDefault': True}, 'start': {'date': '2020-01-6'}, 'end': {'date': '2020-01-7'}, + 'transparency': 'opaque', } self.env['calendar.recurrence']._sync_google2odoo(GoogleEvent([values])) recurrence = self.env['calendar.recurrence'].search([('google_id', '=', values.get('id'))]) @@ -1098,6 +1099,7 @@ class TestSyncGoogle2Odoo(TestSyncGoogle): 'timeZone': 'Europe/Brussels', 'date': None }, + 'transparency': 'opaque', } self.env['calendar.event']._sync_google2odoo(GoogleEvent([values])) self.assertEqual(event.attendee_ids.state, 'declined') @@ -1135,6 +1137,7 @@ class TestSyncGoogle2Odoo(TestSyncGoogle): '%s_owner_id' % self.env.cr.dbname: other_user.id}}, 'reminders': {'overrides': [], 'useDefault': False}, 'visibility': 'public', + 'transparency': 'opaque', }, timeout=3) @patch_api diff --git a/addons/google_calendar/tests/test_sync_odoo2google.py b/addons/google_calendar/tests/test_sync_odoo2google.py index 4625b1d5574..0b9e633a893 100644 --- a/addons/google_calendar/tests/test_sync_odoo2google.py +++ b/addons/google_calendar/tests/test_sync_odoo2google.py @@ -57,7 +57,8 @@ class TestSyncOdoo2Google(TestSyncGoogle): 'reminders': {'useDefault': False, 'overrides': [{'method': 'popup', 'minutes': alarm.duration_minutes}]}, 'organizer': {'email': 'odoobot@example.com', 'self': True}, 'attendees': [{'email': 'jean-luc@opoo.com', 'responseStatus': 'needsAction'}], - 'extendedProperties': {'shared': {'%s_odoo_id' % self.env.cr.dbname: event.id}} + 'extendedProperties': {'shared': {'%s_odoo_id' % self.env.cr.dbname: event.id}}, + 'transparency': 'opaque', }) @patch_api @@ -170,7 +171,8 @@ class TestSyncOdoo2Google(TestSyncGoogle): 'organizer': {'email': 'odoobot@example.com', 'self': True}, 'attendees': [{'email': 'jean-luc@opoo.com', 'responseStatus': 'needsAction'}, {'email': 'phineas@opoo.com', 'responseStatus': 'needsAction'}], - 'extendedProperties': {'shared': {'%s_odoo_id' % self.env.cr.dbname: event.id}} + 'extendedProperties': {'shared': {'%s_odoo_id' % self.env.cr.dbname: event.id}}, + 'transparency': 'opaque', }) @patch_api @@ -195,7 +197,8 @@ class TestSyncOdoo2Google(TestSyncGoogle): 'reminders': {'overrides': [], 'useDefault': False}, 'organizer': {'email': 'odoobot@example.com', 'self': True}, 'attendees': [{'email': 'odoobot@example.com', 'responseStatus': 'accepted'}], - 'extendedProperties': {'shared': {'%s_odoo_id' % self.env.cr.dbname: event.id}} + 'extendedProperties': {'shared': {'%s_odoo_id' % self.env.cr.dbname: event.id}}, + 'transparency': 'opaque', }) @patch_api @@ -257,7 +260,8 @@ class TestSyncOdoo2Google(TestSyncGoogle): 'organizer': {'email': 'odoobot@example.com', 'self': True}, 'attendees': [{'email': 'odoobot@example.com', 'responseStatus': 'accepted'}], 'recurrence': ['RRULE:FREQ=WEEKLY;COUNT=2;BYDAY=WE'], - 'extendedProperties': {'shared': {'%s_odoo_id' % self.env.cr.dbname: recurrence.id}} + 'extendedProperties': {'shared': {'%s_odoo_id' % self.env.cr.dbname: recurrence.id}}, + 'transparency': 'opaque', }) @patch_api @@ -292,7 +296,8 @@ class TestSyncOdoo2Google(TestSyncGoogle): 'organizer': {'email': 'odoobot@example.com', 'self': True}, 'attendees': [{'email': 'odoobot@example.com', 'responseStatus': 'accepted'}], 'recurrence': ['RRULE:FREQ=WEEKLY;COUNT=2;BYDAY=WE'], - 'extendedProperties': {'shared': {'%s_odoo_id' % self.env.cr.dbname: event.recurrence_id.id}} + 'extendedProperties': {'shared': {'%s_odoo_id' % self.env.cr.dbname: event.recurrence_id.id}}, + 'transparency': 'opaque', }, timeout=3) self.assertGoogleEventDeleted(google_id) @@ -340,7 +345,8 @@ class TestSyncOdoo2Google(TestSyncGoogle): 'extendedProperties': {'shared': {'%s_odoo_id' % self.env.cr.dbname: event.recurrence_id.id}}, 'reminders': {'overrides': [], 'useDefault': False}, 'visibility': 'public', - 'recurrence': ['RRULE:FREQ=WEEKLY;WKST=SU;COUNT=1;BYDAY=WE'] + 'recurrence': ['RRULE:FREQ=WEEKLY;WKST=SU;COUNT=1;BYDAY=WE'], + 'transparency': 'opaque', }, timeout=3) @patch_api @@ -390,7 +396,8 @@ class TestSyncOdoo2Google(TestSyncGoogle): 'reminders': {'overrides': [], 'useDefault': False}, 'organizer': {'email': 'jean-luc@opoo.com', 'self': True}, 'attendees': [{'email': 'jean-luc@opoo.com', 'responseStatus': 'accepted'}], - 'extendedProperties': {'shared': {'%s_odoo_id' % self.env.cr.dbname: event.id}} + 'extendedProperties': {'shared': {'%s_odoo_id' % self.env.cr.dbname: event.id}}, + 'transparency': 'opaque', }, timeout=3) @patch_api @@ -429,6 +436,7 @@ class TestSyncOdoo2Google(TestSyncGoogle): 'extendedProperties': {'shared': {'%s_odoo_id' % self.env.cr.dbname: new_recurrence.id}}, 'reminders': {'overrides': [], 'useDefault': False}, 'visibility': 'public', + 'transparency': 'opaque', }, timeout=3) @patch_api @@ -558,6 +566,7 @@ class TestSyncOdoo2Google(TestSyncGoogle): 'extendedProperties': {'shared': {'%s_odoo_id' % self.env.cr.dbname: event.id}}, 'reminders': {'overrides': [], 'useDefault': False}, 'visibility': 'public', + 'transparency': 'opaque', }) @@ -596,6 +605,7 @@ class TestSyncOdoo2Google(TestSyncGoogle): 'extendedProperties': {'shared': {'%s_odoo_id' % self.env.cr.dbname: new_recurrence.id}}, 'reminders': {'overrides': [], 'useDefault': False}, 'visibility': 'public', + 'transparency': 'opaque', }, timeout=3) @patch.object(GoogleService, '_do_request') @@ -668,7 +678,8 @@ class TestSyncOdoo2Google(TestSyncGoogle): 'extendedProperties': {'shared': {'%s_odoo_id' % self.env.cr.dbname: event_1.id}}, 'reminders': {'overrides': [], 'useDefault': False}, 'visibility': 'public', - 'status': 'cancelled' + 'status': 'cancelled', + 'transparency': 'opaque', }, timeout=3) # Assert that deleted event is not active anymore and the recurrence updated its calendar_event_ids. self.assertFalse(event_1.active) @@ -778,3 +789,57 @@ class TestSyncOdoo2Google(TestSyncGoogle): }) event._sync_odoo2google(self.google_service) self.assertGoogleEventHasNoConferenceData() + + @patch_api + def test_event_available_privacy(self): + """ Create an event with "Available" value for 'show_as' and assert value is properly sync in google calendar. """ + event = self.env['calendar.event'].create({ + 'name': "Event", + 'start': datetime(2024, 3, 29, 10, 0), + 'stop': datetime(2024, 3, 29, 10, 0), + 'need_sync': False, + 'show_as': 'free' + }) + event._sync_odoo2google(self.google_service) + self.assertGoogleEventInserted({ + 'id': False, + 'start': {'dateTime': '2024-03-29T10:00:00+00:00', 'date': None}, + 'end': {'dateTime': '2024-03-29T10:00:00+00:00', 'date': None}, + 'summary': 'Event', + 'description': '', + 'location': '', + 'visibility': 'public', + 'guestsCanModify': True, + 'reminders': {'overrides': [], 'useDefault': False}, + 'organizer': {'email': 'odoobot@example.com', 'self': True}, + 'attendees': [{'email': 'odoobot@example.com', 'responseStatus': 'accepted'}], + 'extendedProperties': {'shared': {'%s_odoo_id' % self.env.cr.dbname: event.id}}, + 'transparency': 'transparent', + }) + + @patch_api + def test_event_busy_privacy(self): + """ Create an event with "busy" value for 'show_as' and assert value is properly sync in google calendar. """ + event = self.env['calendar.event'].create({ + 'name': "Event", + 'start': datetime(2024, 3, 29, 10, 0), + 'stop': datetime(2024, 3, 29, 10, 0), + 'need_sync': False, + 'show_as': 'busy' + }) + event._sync_odoo2google(self.google_service) + self.assertGoogleEventInserted({ + 'id': False, + 'start': {'dateTime': '2024-03-29T10:00:00+00:00', 'date': None}, + 'end': {'dateTime': '2024-03-29T10:00:00+00:00', 'date': None}, + 'summary': 'Event', + 'description': '', + 'location': '', + 'visibility': 'public', + 'guestsCanModify': True, + 'reminders': {'overrides': [], 'useDefault': False}, + 'organizer': {'email': 'odoobot@example.com', 'self': True}, + 'attendees': [{'email': 'odoobot@example.com', 'responseStatus': 'accepted'}], + 'extendedProperties': {'shared': {'%s_odoo_id' % self.env.cr.dbname: event.id}}, + 'transparency': 'opaque', + })