Files
odoo_source/addons/website_rating/models/mail_message.py
T
ryv-odoo 1b48730446 [IMP] website_rating : allow to comment message-based ratings
PURPOSE

Allow publishers to add a comment on frontend reviews with ratings. Purpose
is to allow to give some feedback or context on published reviews.

SPECIFICATIONS

In order to answer to a rating message (review) of a course (eLearning) or a
product (eCommerce) we add a way to the publisher to directly comment a review
inside the website rating chatter.

Any publisher can add/edit/remove comment of a rating message from the website.

The goal is not to enter into a discussion but just to give a feedback. This
comment is not sent or propagated to anyone, just displayed for information
purpose.

In portal chatter

* add 1 button below a review "Comment" (for publishers of the website only)
* only one comment possible by review/rating
* when the comment is added, display

* author name, date, comment
* 2 buttons, only visible by the website publisher: edit and delete

LINKS

Task ID : 2026911

closes odoo/odoo#35956

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2019-08-22 13:58:15 +00:00

29 lines
1.3 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_read_dict_postprocess(self, message_values, message_tree):
""" Override the method to add information about a publisher comment
on each rating messages if requested, and compute a plaintext value of it.
"""
res = super(MailMessage, self)._message_read_dict_postprocess(message_values, message_tree)
if self._context.get('rating_include'):
infos = ["id", "publisher_comment", "publisher_id", "publisher_datetime", "message_id"]
related_rating = self.env['rating.rating'].search([('message_id', 'in', self.ids)]).read(infos)
mid_rating_tree = dict((rating['message_id'][0], rating) for rating in related_rating)
for values in message_values:
values["rating"] = mid_rating_tree.get(values['id'], {})
return res