Files
odoo_source/addons/website_rating/controllers/portal_chatter.py
T
Thibault Delavallée 532b1a5093 [FIX] portal, website_rating: re-allow rating from frontend
PURPOSE

Fix frontend rating and clean a bit module organization

SPECIFICATIONS

Broken since 3620cb68a0

LINKS

Task 2057301
PR #35870
2019-08-21 12:50:51 +00:00

35 lines
1.4 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import http
from odoo.http import request
from odoo.addons.portal.controllers.mail import PortalChatter
class PortalChatter(PortalChatter):
def _portal_post_filter_params(self):
fields = super(PortalChatter, self)._portal_post_filter_params()
fields.append('rating_value')
return fields
@http.route()
def portal_chatter_init(self, res_model, res_id, domain=False, limit=False, **kwargs):
result = super(PortalChatter, self).portal_chatter_init(res_model, res_id, domain=domain, limit=limit, **kwargs)
# get the rating statistics about the record
if kwargs.get('rating_include'):
record = request.env[res_model].browse(res_id)
if hasattr(record, 'rating_get_stats'):
result['rating_stats'] = record.rating_get_stats()
return result
@http.route()
def portal_message_fetch(self, res_model, res_id, domain=False, limit=False, offset=False, **kw):
# add 'rating_include' in context, to fetch them in portal_message_format
if kw.get('rating_include'):
context = dict(request.context)
context['rating_include'] = True
request.context = context
return super(PortalChatter, self).portal_message_fetch(res_model, res_id, domain=domain, limit=limit, offset=offset, **kw)