[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:
@@ -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.
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user