From 2bc6d668b75aaad2e5d2962f0442e4af3f1d4e7d Mon Sep 17 00:00:00 2001 From: "Achraf (abz)" Date: Thu, 26 Nov 2020 12:50:52 +0000 Subject: [PATCH] [FIX] calendar, google_calendar, hr_holidays: lost attendees after sync What are the steps to reproduce your issue ? 1. Install "google_calendar" 2. Log in with "admin" 3. Create an eventX with "admin" and "demo" has attendees 4. Run "Google Calendar Synchronization" from "Scheduled Actions" What is currently happening ? eventX is successfully added to Google but without admin if you sync Odoo to Google one more time, Google will overwrite eventX and it will remove admin from attendees What are you expecting to happen ? Sync Odoo to Google and Google to Odoo without lost attendees Why is this happening ? Because there is a filter that prevent addition of current user to the attendees How to fix the bug ? Remove the filter This reverts commit 287ee0f83ae6fd457e5356860c8a8ab5a4e66754. opw-2382443 closes odoo/odoo#62416 X-original-commit: f6a610d0b1379aa97ad97fb7494a5d269da87775 Signed-off-by: Nicolas Martinelli (nim) --- addons/calendar/models/calendar_event.py | 14 ++++++-------- addons/calendar/tests/test_attendees.py | 4 ++-- addons/google_calendar/models/calendar.py | 3 +-- addons/hr_holidays/models/hr_leave.py | 1 - addons/hr_holidays/tests/test_company_leave.py | 2 +- 5 files changed, 10 insertions(+), 14 deletions(-) diff --git a/addons/calendar/models/calendar_event.py b/addons/calendar/models/calendar_event.py index 791f030e219..1192cc0bdbf 100644 --- a/addons/calendar/models/calendar_event.py +++ b/addons/calendar/models/calendar_event.py @@ -475,12 +475,11 @@ class Meeting(models.Model): added_partner_ids += [command[1]] if command[1] not in self.partner_ids.ids else [] # commands 0 and 1 not supported - if removed_partner_ids: - attendees_to_unlink = self.env['calendar.attendee'].search([ - ('event_id', 'in', self.ids), - ('partner_id', 'in', removed_partner_ids), - ]) - attendee_commands += [[2, attendee.id] for attendee in attendees_to_unlink] # Removes and delete + attendees_to_unlink = self.env['calendar.attendee'].search([ + ('event_id', 'in', self.ids), + ('partner_id', 'in', removed_partner_ids), + ]) + attendee_commands += [[2, attendee.id] for attendee in attendees_to_unlink] # Removes and delete attendee_commands += [ [0, 0, dict(partner_id=partner_id)] @@ -700,9 +699,8 @@ class Meeting(models.Model): activity_vals['user_id'] = user_id values['activity_ids'] = [(0, 0, activity_vals)] - self_partner_id = [(4, self.env.user.partner_id.id)] vals_list = [ - dict(vals, attendee_ids=self._attendees_values(vals.get('partner_ids', self_partner_id))) + dict(vals, attendee_ids=self._attendees_values(vals['partner_ids'])) if 'partner_ids' in vals else vals for vals in vals_list ] recurrence_fields = self._get_recurrent_fields() diff --git a/addons/calendar/tests/test_attendees.py b/addons/calendar/tests/test_attendees.py index d9e1c1db4fc..44f7177c149 100644 --- a/addons/calendar/tests/test_attendees.py +++ b/addons/calendar/tests/test_attendees.py @@ -11,12 +11,12 @@ class TestEventNotifications(TransactionCase): @classmethod def setUpClass(cls): super().setUpClass() - cls.user = new_test_user(cls.env, 'xav', email='em@il.com', notification_type='inbox') - cls.event = cls.env['calendar.event'].with_user(cls.user).create({ + cls.event = cls.env['calendar.event'].create({ 'name': "Doom's day", 'start': datetime(2019, 10, 25, 8, 0), 'stop': datetime(2019, 10, 27, 18, 0), }).with_context(mail_notrack=True) + cls.user = new_test_user(cls.env, 'xav', email='em@il.com', notification_type='inbox') cls.partner = cls.user.partner_id def test_attendee_added(self): diff --git a/addons/google_calendar/models/calendar.py b/addons/google_calendar/models/calendar.py index 80d2cb7ca9d..765473509ba 100644 --- a/addons/google_calendar/models/calendar.py +++ b/addons/google_calendar/models/calendar.py @@ -167,7 +167,6 @@ class Meeting(models.Model): 'method': "email" if alarm.alarm_type == "email" else "popup", 'minutes': alarm.duration_minutes } for alarm in self.alarm_ids] - attendee_ids = self.attendee_ids.filtered(lambda a: a.partner_id != self.env.user.partner_id) values = { 'id': self.google_id, 'start': start, @@ -177,7 +176,7 @@ class Meeting(models.Model): 'location': self.location or '', 'guestsCanModify': True, 'organizer': {'email': self.user_id.email, 'self': self.user_id == self.env.user}, - 'attendees': [{'email': attendee.email, 'responseStatus': attendee.state} for attendee in attendee_ids], + 'attendees': [{'email': attendee.email, 'responseStatus': attendee.state} for attendee in self.attendee_ids], 'extendedProperties': { 'shared': { '%s_odoo_id' % self.env.cr.dbname: self.id, diff --git a/addons/hr_holidays/models/hr_leave.py b/addons/hr_holidays/models/hr_leave.py index 9f4e5cebb3a..c393dfb4ddd 100644 --- a/addons/hr_holidays/models/hr_leave.py +++ b/addons/hr_holidays/models/hr_leave.py @@ -894,7 +894,6 @@ class HolidaysRequest(models.Model): 'privacy': 'confidential', 'event_tz': holiday.user_id.tz, 'activity_ids': [(5, 0, 0)], - 'partner_ids': [], } # Add the partner_id (if exist) as an attendee if holiday.user_id and holiday.user_id.partner_id: diff --git a/addons/hr_holidays/tests/test_company_leave.py b/addons/hr_holidays/tests/test_company_leave.py index f1b1061577e..11462de358b 100644 --- a/addons/hr_holidays/tests/test_company_leave.py +++ b/addons/hr_holidays/tests/test_company_leave.py @@ -313,7 +313,7 @@ class TestCompanyLeave(TransactionCase): }) company_leave._compute_date_from_to() - count = 863 + count = 865 with self.assertQueryCount(__system__=count, admin=count): # Original query count: 1987 # Without tracking/activity context keys: 5154