[FIX] website_slides: fix some rating issues

Last review should be a comment. When fetching the last message on a course
the returned message can be a system notification (like "Channel created").
This is not what we want, mostly with the feature allowing to modify the body
of a message. This commit add restriction on the domain fetch last message.

Fix default rating value on popup widget. The conversation ratio (rating 1-10
and 5 stars) was not applied everywhere. So, the number of displayed stars was
doubled. This is now fixed.

Commit linked to task ID 1941250 and PR #31317.
This commit is contained in:
jem-odoo
2019-02-21 16:38:14 +00:00
committed by Thibault Delavallée
parent 55f93a240f
commit 7d1af42c06
5 changed files with 12 additions and 5 deletions
@@ -33,6 +33,11 @@ odoo.define('website_rating.thread', function(require) {
init: function(parent, options){
this._super.apply(this, arguments);
// apply ratio to default rating value
if (options.default_rating_value) {
options.default_rating_value = parseFloat(options.default_rating_value) / STAR_RATING_RATIO;
}
// default options
this.options = _.defaults(this.options, {
'default_message': false,
@@ -50,7 +55,7 @@ odoo.define('website_rating.thread', function(require) {
'5': _t("I love it"),
};
this.user_click = false; // user has click or not
this.set("star_value", this.options.rating_default_value);
this.set("star_value", this.options.default_rating_value);
this.on("change:star_value", this, this._onChangeStarValue);
},
start: function(){
@@ -59,7 +64,7 @@ odoo.define('website_rating.thread', function(require) {
// rating stars
self.$input = self.$('input[name="rating_value"]');
self.$star_list = self.$('.stars').find('i');
self.set("star_value", self.options.rating_default_value); // set the default value to trigger the display of star widget
self.set("star_value", self.options.default_rating_value); // set the default value to trigger the display of star widget
});
},
@@ -265,7 +270,7 @@ odoo.define('website_rating.thread', function(require) {
_onChangeRatingDomain: function(){
var domain = [];
if(this.get('rating_value')){
domain = [['rating_value', '=', this.get('rating_value')]];
domain = [['rating_value', '=', this.get('rating_value') * STAR_RATING_RATIO]];
}
this._changeCurrentPage(1, domain);
},
@@ -79,7 +79,7 @@
<div class="rate_text">
<span class="badge badge-info"></span>
</div>
<input type="hidden" readonly="readonly" name="rating_value" t-att-value="default_rating"/>
<input type="hidden" readonly="readonly" name="rating_value" t-att-value="default_rating || ''"/>
</div>
</t>
@@ -18,7 +18,7 @@
Rating widget static: show 5 stars (full or empty) regarding the given rating_avg and rating_count
-->
<template id="rating_widget_stars_static" name="Rating: static star widget">
<t t-set="rating_avg" t-value="round(rating_avg * 100) / 100"/>
<t t-set="rating_avg" t-value="round(rating_avg * 100) / 100 / 2"/>
<t t-set="val_decimal" t-value="round(rating_avg % 1, 1)"/>
<t t-set="val_integer" t-value="int(rating_avg)"/>
<t t-set="empty_star" t-value="5 - (val_integer+1) if val_decimal else 5 - val_integer"/>
@@ -33,6 +33,7 @@ class SlidesMail(http.Controller):
('res_id', '=', res_id),
('website_published', '=', True),
('author_id', '=', request.env.user.partner_id.id),
('message_type', '=', 'comment'),
('id', '=', message_id)
] # restrict to the given message_id
message = request.env['mail.message'].search(domain, limit=1)
@@ -300,6 +300,7 @@ class WebsiteSlides(WebsiteProfile):
('model', '=', channel._name),
('res_id', '=', channel.id),
('author_id', '=', request.env.user.partner_id.id),
('message_type', '=', 'comment'),
('website_published', '=', True)
], order='write_date DESC', limit=1).read(['body', 'rating_value'])
last_message_data = last_message_values[0] if last_message_values else {}