Skip to content
Snippets Groups Projects
Commit abc45b19 authored by Nans Lefebvre's avatar Nans Lefebvre
Browse files

[FIX] mail: remove attachment as main at unlink


If an user unlinks an attachment,
it doesn't remove it as message_main_attachment_id.

opw 1950403

closes odoo/odoo#32347

Signed-off-by: default avatarNans Lefebvre (len) <len@odoo.com>
parent 6a5dab9c
No related branches found
No related tags found
No related merge requests found
......@@ -15,6 +15,19 @@ class IrAttachment(models.Model):
for record in self:
record.register_as_main_attachment(force=False)
@api.multi
def unlink(self):
self.remove_as_main_attachment()
super(IrAttachment, self).unlink()
@api.multi
def remove_as_main_attachment(self):
for attachment in self:
related_record = self.env[attachment.res_model].browse(attachment.res_id)
if related_record and hasattr(related_record, 'message_main_attachment_id'):
if related_record.message_main_attachment_id == attachment:
related_record.message_main_attachment_id = False
def register_as_main_attachment(self, force=True):
""" Registers this attachment as the main one of the model it is
attached to.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment