mail_message.py 1.2 KB

123456789101112131415161718192021222324252627
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo import models
  4. class MailMessage(models.Model):
  5. _inherit = 'mail.message'
  6. def portal_message_format(self):
  7. return self._portal_message_format([
  8. 'id', 'body', 'date', 'author_id', 'email_from', # base message fields
  9. 'message_type', 'subtype_id', 'is_internal', 'subject', # message specific
  10. 'model', 'res_id', 'record_name', # document related
  11. ])
  12. def _portal_message_format(self, fields_list):
  13. vals_list = self._message_format(fields_list, legacy=True)
  14. message_subtype_note_id = self.env['ir.model.data']._xmlid_to_res_id('mail.mt_note')
  15. IrAttachmentSudo = self.env['ir.attachment'].sudo()
  16. for vals in vals_list:
  17. vals['is_message_subtype_note'] = message_subtype_note_id and (vals.get('subtype_id') or [False])[0] == message_subtype_note_id
  18. for attachment in vals.get('attachment_ids', []):
  19. if not attachment.get('access_token'):
  20. attachment['access_token'] = IrAttachmentSudo.browse(attachment['id']).generate_access_token()[0]
  21. return vals_list