Debian Codegraph @

addons/portal_rating/controllers/portal_rating.py

raw
1 # -*- coding: utf-8 -*-
2 # Part of Odoo. See LICENSE file for full copyright and licensing details.
3
4 from odoo import http, _
5 from odoo.http import request
6
7
8 class PortalRating(http.Controller):
9
10 @http.route(['/website/rating/comment'], type='jsonrpc', auth="user", methods=['POST'], website=True)
11 def publish_rating_comment(self, rating_id, publisher_comment):
12 rating = request.env['rating.rating'].search_fetch(
13 [('id', '=', int(rating_id))],
14 ['publisher_comment', 'publisher_id', 'publisher_datetime'],
15 )
16 if not rating:
17 return {'error': _('Invalid rating')}
18 rating.write({'publisher_comment': publisher_comment})
19 # return to the front-end the created/updated publisher comment
20 return request.env['mail.message']._portal_message_format_rating(
21 rating.read(['publisher_comment', 'publisher_id', 'publisher_datetime'])[0]
22 )