From c791981abc1906e25112b5b647445e1a944f948c Mon Sep 17 00:00:00 2001 From: Nans Lefebvre Date: Tue, 2 Apr 2019 13:48:18 +0000 Subject: [PATCH] [FIX] mail: only register as main attachment if main not already set Commit a26496b6e79 registered an attachment added through the widget as record's message_main_attachment. This to make the OCR feature available for such attachments. However we copy more closely the behaviour in message_post, which only puts the attachment as main if there isn't already a main. opw 1950403 --- addons/mail/models/ir_attachment.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/addons/mail/models/ir_attachment.py b/addons/mail/models/ir_attachment.py index 4330059c495..ee51ed8382e 100644 --- a/addons/mail/models/ir_attachment.py +++ b/addons/mail/models/ir_attachment.py @@ -13,9 +13,9 @@ class IrAttachment(models.Model): """ super(IrAttachment, self)._post_add_create() for record in self: - record.register_as_main_attachment() + record.register_as_main_attachment(force=False) - def register_as_main_attachment(self): + def register_as_main_attachment(self, force=True): """ Registers this attachment as the main one of the model it is attached to. """ @@ -24,4 +24,5 @@ class IrAttachment(models.Model): # message_main_attachment_id field can be empty, that's why we compare to False; # we are just checking that it exists on the model before writing it if related_record and hasattr(related_record, 'message_main_attachment_id'): - related_record.message_main_attachment_id = self + if force or not related_record.message_main_attachment_id: + related_record.message_main_attachment_id = self