[FIX] mail: only register as main attachment if main not already set
Commit a26496b6e7 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
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user