[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) <arj@odoo.com>
Signed-off-by: Thomas Lefebvre (thle) <thle@odoo.com>
This commit is contained in:
Thomas Lefebvre (thle)
2024-03-25 08:33:09 +00:00
parent c0dd759df7
commit 5035312168
+6 -1
View File
@@ -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',