diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/portal_rating/controllers/portal_chatter.py | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/portal_rating/controllers/portal_chatter.py')
| -rw-r--r-- | addons/portal_rating/controllers/portal_chatter.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/addons/portal_rating/controllers/portal_chatter.py b/addons/portal_rating/controllers/portal_chatter.py new file mode 100644 index 00000000..fb3116bc --- /dev/null +++ b/addons/portal_rating/controllers/portal_chatter.py @@ -0,0 +1,40 @@ +# -*- 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 += ['rating_value', 'rating_feedback'] + return fields + + @http.route() + def portal_chatter_post(self, res_model, res_id, message, redirect=None, attachment_ids='', attachment_tokens='', **kwargs): + if kwargs.get('rating_value'): + kwargs['rating_feedback'] = kwargs.pop('rating_feedback', message) + return super(PortalChatter, self).portal_chatter_post(res_model, res_id, message, redirect=redirect, attachment_ids=attachment_ids, attachment_tokens=attachment_tokens, **kwargs) + + @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.sudo().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) |
