[FIX] calendar: support writing attendee_ids with ids

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) <awa@odoo.com>
Signed-off-by: Renaud Thiry (reth) <reth@odoo.com>
This commit is contained in:
Renaud Thiry
2023-12-15 13:05:37 +00:00
parent d94c46a1b0
commit d0c2c225da
2 changed files with 10 additions and 0 deletions
+5
View File
@@ -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
+5
View File
@@ -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