from `message_format` and from `_message_read_dict_postprocess`. The reading and initial formatting is done by `_message_read_dict_postprocess`, which has been renamed more simply to `_message_format` due to its new goal. This makes the methods easier to follow and does not increase the query count. It actually reduces it when the data were already in the cache, by not always reading them again. Part of task-2180311 PR: #43841
25 lines
978 B
Python
25 lines
978 B
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import models
|
|
|
|
|
|
class MailMessage(models.Model):
|
|
_inherit = 'mail.message'
|
|
|
|
def portal_message_format(self):
|
|
return self._portal_message_format([
|
|
'id', 'body', 'date', 'author_id', 'email_from', # base message fields
|
|
'message_type', 'subtype_id', 'is_internal', 'subject', # message specific
|
|
'model', 'res_id', 'record_name', # document related
|
|
])
|
|
|
|
def _portal_message_format(self, fields_list):
|
|
vals_list = self._message_format(fields_list)
|
|
IrAttachmentSudo = self.env['ir.attachment'].sudo()
|
|
for vals in vals_list:
|
|
for attachment in vals.get('attachment_ids', []):
|
|
if not attachment.get('access_token'):
|
|
attachment['access_token'] = IrAttachmentSudo.browse(attachment['id']).generate_access_token()[0]
|
|
return vals_list
|