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
29 lines
1.2 KiB
Python
29 lines
1.2 KiB
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, field_list):
|
|
# inlude rating value in data if requested
|
|
if self._context.get('rating_include'):
|
|
field_list += ['rating_value']
|
|
return super(MailMessage, self)._portal_message_format(field_list)
|
|
|
|
def _message_format(self, fnames):
|
|
""" Override the method to add information about a publisher comment
|
|
on each rating messages if requested, and compute a plaintext value of it.
|
|
"""
|
|
vals_list = super(MailMessage, self)._message_format(fnames)
|
|
|
|
if self._context.get('rating_include'):
|
|
infos = ["id", "publisher_comment", "publisher_id", "publisher_datetime", "message_id"]
|
|
related_rating = self.env['rating.rating'].sudo().search([('message_id', 'in', self.ids)]).read(infos)
|
|
mid_rating_tree = dict((rating['message_id'][0], rating) for rating in related_rating)
|
|
for vals in vals_list:
|
|
vals["rating"] = mid_rating_tree.get(vals['id'], {})
|
|
return vals_list
|