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>
26 lines
1.2 KiB
Python
26 lines
1.2 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
from odoo import fields, models, exceptions, _
|
|
|
|
|
|
class Rating(models.Model):
|
|
_inherit = 'rating.rating'
|
|
|
|
# Add this related field to mail.message for performance reason
|
|
website_published = fields.Boolean(related='message_id.website_published', store=True, readonly=False)
|
|
# Adding information for comment a rating message
|
|
publisher_comment = fields.Text("Publisher Comment")
|
|
publisher_id = fields.Many2one('res.partner', 'Commented by',
|
|
ondelete='set null', readonly=True)
|
|
publisher_datetime = fields.Datetime("Commented on", readonly=True)
|
|
|
|
def write(self, values):
|
|
if values.get('publisher_comment'):
|
|
if not self.env.user.has_group("website.group_website_publisher"):
|
|
raise exceptions.AccessError(_("Only the publisher of the website can change the rating comment"))
|
|
if not values.get('publisher_datetime'):
|
|
values['publisher_datetime'] = fields.Datetime.now()
|
|
if not values.get('publisher_id'):
|
|
values['publisher_id'] = self.env.user.partner_id.id
|
|
return super(Rating, self).write(values)
|