From 5035312168f26464813cc60c354949a3ac02edd1 Mon Sep 17 00:00:00 2001 From: "Thomas Lefebvre (thle)" Date: Thu, 29 Feb 2024 13:37:10 +0100 Subject: [PATCH] [FIX] calendar: do not create a document for ICS file Steps to reproduce: ------------------- - install calendar, project and documents; - create an activity for a task (project.task) with meeting type; - change attendee to the meeting; - save; Issue: ------ The activity is not linked to the right task. Cause: ------ When we create a `calendar.event`, when the event is at a future date, we send an email to the attendees. This email must include an attachment corresponding to the ICS file. Depending on the `no_document` context key, we may or may not create a document. When we create the document, we have a value for the `activity_ids` field (one2many) which is the ORM command for linking the newly created document. This will result in the document id being written to the `res_id` field of the `mail.activity` record. Unfortunately, the activity contains a `res_model` which is not `documents.document`. The result is that the activity is linked to a `res_id` which is not that of the model previously set for it (i.e. `project.task`). Solution: --------- Add context key `no_document` when creating an attachment for ICS files. opw-3746857 closes odoo/odoo#158570 X-original-commit: 17ac8d3f25bad2c4f37793e06edca40793a4f3d5 Signed-off-by: Arnaud Joset (arj) Signed-off-by: Thomas Lefebvre (thle) --- addons/calendar/models/calendar_attendee.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/addons/calendar/models/calendar_attendee.py b/addons/calendar/models/calendar_attendee.py index 8497d1d31b5..2115022deb7 100644 --- a/addons/calendar/models/calendar_attendee.py +++ b/addons/calendar/models/calendar_attendee.py @@ -8,6 +8,7 @@ from collections import defaultdict from odoo import api, fields, models, _ from odoo.addons.base.models.res_partner import _tz_get from odoo.exceptions import UserError +from odoo.tools.misc import clean_context _logger = logging.getLogger(__name__) @@ -122,7 +123,11 @@ class Attendee(models.Model): attachment_ids = mail_template.attachment_ids.ids if ics_file: - attachment_ids += self.env['ir.attachment'].create({ + context = { + **clean_context(self.env.context), + 'no_document': True, # An ICS file must not create a document + } + attachment_ids += self.env['ir.attachment'].with_context(context).create({ 'datas': base64.b64encode(ics_file), 'description': 'invitation.ics', 'mimetype': 'text/calendar',