From ad4cd6df803d68738ee5b020f3da4aec4f351cff Mon Sep 17 00:00:00 2001 From: "Merlin (megu)" Date: Tue, 18 Jan 2022 13:55:00 +0000 Subject: [PATCH] [FIX] mail: update chatter attachments when a log is deleted MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Attachments of the chatter didn't update when a log with an attachment was deleted Steps to reproduce: 1. Install Sales app 2. Open any sale 3. Create a log note with an image attached 4. Delete the log note 5. The image is still in the sale's chatter attachments Solution: When deleting an attachment, send the info on the current partner's bus OPW-2732793 closes odoo/odoo#83199 X-original-commit: f5f09b7c73bc7a5243a3b6edcfa5d047de33d95e Signed-off-by: Guillaume Merlin (megu) Signed-off-by: Sébastien Theys (seb) --- addons/mail/models/ir_attachment.py | 9 ++++++--- addons/mail/models/mail_message.py | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/addons/mail/models/ir_attachment.py b/addons/mail/models/ir_attachment.py index b14cb985538..92e9e29804d 100644 --- a/addons/mail/models/ir_attachment.py +++ b/addons/mail/models/ir_attachment.py @@ -39,9 +39,12 @@ class IrAttachment(models.Model): def _delete_and_notify(self): for attachment in self: if attachment.res_model == 'mail.channel' and attachment.res_id: - self.env['bus.bus']._sendone(self.env['mail.channel'].browse(attachment.res_id), 'ir.attachment/delete', { - 'id': attachment.id, - }) + target = self.env['mail.channel'].browse(attachment.res_id) + else: + target = self.env.user.partner_id + self.env['bus.bus']._sendone(target, 'ir.attachment/delete', { + 'id': attachment.id, + }) self.unlink() def _attachment_format(self, commands=False): diff --git a/addons/mail/models/mail_message.py b/addons/mail/models/mail_message.py index 33627bbaed5..275c2b84048 100644 --- a/addons/mail/models/mail_message.py +++ b/addons/mail/models/mail_message.py @@ -809,7 +809,7 @@ class Message(models.Model): thread._check_can_update_message_content(self) self.body = body if not attachment_ids: - self.attachment_ids.unlink() + self.attachment_ids._delete_and_notify() else: message_values = { 'model': self.model,