From d0c2c225da14533d77f063517fc53c122bb0c3d1 Mon Sep 17 00:00:00 2001 From: Renaud Thiry Date: Thu, 14 Dec 2023 06:46:17 +0100 Subject: [PATCH] [FIX] calendar: support writing attendee_ids with ids MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit, attempting to do `self.env['calendar.event'].write({'partner_ids': [0, 1, 2]})` would give a traceback as the method that updates attendees only supports parsing commands, not ids. This is a problem as that method is called from 'write' and other methods with the assumption that partner_ids can only contain commands. This will not be the case when using a gantt view and grouping by partner_ids for example, and cannot be worked around. task-3452277 closes odoo/odoo#146446 X-original-commit: 88e191132bf40a4e3090077f1fd0077e649eb7fb Signed-off-by: Warnon Aurélien (awa) Signed-off-by: Renaud Thiry (reth) --- addons/calendar/models/calendar_event.py | 5 +++++ addons/calendar/tests/test_attendees.py | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/addons/calendar/models/calendar_event.py b/addons/calendar/models/calendar_event.py index fdc52eff4e4..e4123fa054f 100644 --- a/addons/calendar/models/calendar_event.py +++ b/addons/calendar/models/calendar_event.py @@ -789,6 +789,11 @@ class Meeting(models.Model): removed_partner_ids = [] added_partner_ids = [] + + # if commands are just integers, assume they are ids with the intent to `Command.set` + if partner_commands and isinstance(partner_commands[0], int): + partner_commands = [Command.set(partner_commands)] + for command in partner_commands: op = command[0] if op in (2, 3, Command.delete, Command.unlink): # Remove partner diff --git a/addons/calendar/tests/test_attendees.py b/addons/calendar/tests/test_attendees.py index 629a7d5556e..98e9206483b 100644 --- a/addons/calendar/tests/test_attendees.py +++ b/addons/calendar/tests/test_attendees.py @@ -68,6 +68,11 @@ class TestEventNotifications(TransactionCase): events.partner_ids = self.partner self.assertEqual(len(events.attendee_ids), 2, "It should have created one attendee per event") + def test_attendee_added_write(self): + """Test that writing ids directly on partner_ids instead of commands is handled.""" + self.event.write({'partner_ids': [self.partner.id]}) + self.assertEqual(self.event.attendee_ids.partner_id, self.partner, "It should be linked to the partner") + def test_existing_attendee_added(self): self.event.partner_ids = self.partner attendee = self.event.attendee_ids