[FIX] mail: set message_main_attachment_id when the attachment is added via widget

Create a record.
Add an attachment, using the widget (aptly named 'add an attachment').
It is not set as message_main_attachment_id.
If you add the message through 'log note', then it is.

We add a hook to make sure that it is set as message_main_attachment_id
when added through the widget.

opw 1950403

closes odoo/odoo#31847

Signed-off-by: Nans Lefebvre (len) <len@odoo.com>
This commit is contained in:
Nans Lefebvre
2019-03-14 12:50:51 +00:00
parent c68a97a255
commit a26496b6e7
3 changed files with 13 additions and 0 deletions
+8
View File
@@ -7,6 +7,14 @@ from odoo import api, fields, models
class IrAttachment(models.Model):
_inherit = 'ir.attachment'
@api.multi
def _post_add_create(self):
""" Overrides behaviour when the attachment is created through the controller
"""
super(IrAttachment, self)._post_add_create()
for record in self:
record.register_as_main_attachment()
def register_as_main_attachment(self):
""" Registers this attachment as the main one of the model it is
attached to.
+1
View File
@@ -1167,6 +1167,7 @@ class Binary(http.Controller):
'res_model': model,
'res_id': int(id)
})
attachment._post_add_create()
except Exception:
args.append({'error': _("Something horrible happened")})
_logger.exception("Fail to upload attachment %s" % ufile.filename)
+4
View File
@@ -506,6 +506,10 @@ class IrAttachment(models.Model):
self.browse().check('write', values=values)
return super(IrAttachment, self).create(vals_list)
@api.multi
def _post_add_create(self):
pass
@api.one
def generate_access_token(self):
if self.access_token: