[FIX] rating: value range of star notation
When rating with the smiley mecanism, the rating value will be 1, 3 or 7. The rating model allow value in range [0, 10]. When using the star mecanism, usually, only 5 stars are used to introduced a rating. This will set a rating value in the range [0, 5], which is not aligned with the range of the model, nor the smiley range. Purpose of this commit is to uniformize the range of rating, so if a model is using both mecanism, the average will be correct. Solving this problem implies to apply a conversion factor between the database value and the displayed one. Migration: As only product.template was using star mecanism in odoo community, a migration step should be applied to multiply of ratings of product.template by 2. Task-1941432 closes odoo/odoo#31141
This commit is contained in:
@@ -15,6 +15,8 @@ odoo.define('website_rating.thread', function(require) {
|
||||
var PortalComposer = require('portal.chatter').PortalComposer;
|
||||
var PortalChatter = require('portal.chatter').PortalChatter;
|
||||
|
||||
var STAR_RATING_RATIO = 2; // conversion factor from the star (1-5) to the db rating range (1-10)
|
||||
|
||||
/**
|
||||
* PortalComposer
|
||||
*
|
||||
@@ -71,7 +73,7 @@ odoo.define('website_rating.thread', function(require) {
|
||||
*/
|
||||
_onClickStar: function(e){
|
||||
this.user_click = true;
|
||||
this.$input.val(this.get("star_value"));
|
||||
this.$input.val(this.get("star_value") * STAR_RATING_RATIO);
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
@@ -145,13 +147,14 @@ odoo.define('website_rating.thread', function(require) {
|
||||
// rating card
|
||||
if(result['rating_stats']){
|
||||
var rating_data = {
|
||||
'avg': Math.round(result['rating_stats']['avg'] * 100) / 100,
|
||||
'avg': Math.round(result['rating_stats']['avg'] / STAR_RATING_RATIO * 100) / 100,
|
||||
'percent': [],
|
||||
};
|
||||
_.each(_.keys(result['rating_stats']['percent']), function(rating){
|
||||
if(0 < rating && rating <= 5){
|
||||
|
||||
if (rating % 2 == 0) { // is even number
|
||||
rating_data['percent'].push({
|
||||
'num': rating,
|
||||
'num': rating / STAR_RATING_RATIO,
|
||||
'percent': result['rating_stats']['percent'][rating],
|
||||
});
|
||||
}
|
||||
@@ -176,7 +179,7 @@ odoo.define('website_rating.thread', function(require) {
|
||||
var messages = this._super.apply(this, arguments);
|
||||
if(this.options['display_rating']){
|
||||
_.each(messages, function(m){
|
||||
m['rating_value'] = self.round_to_half(m['rating_value']);
|
||||
m['rating_value'] = self.round_to_half(m['rating_value'] / STAR_RATING_RATIO);
|
||||
});
|
||||
}
|
||||
return messages;
|
||||
@@ -285,7 +288,7 @@ odoo.define('website_rating.thread', function(require) {
|
||||
|
||||
init: function(parent, options){
|
||||
this._super.apply(this, arguments);
|
||||
this.rating_avg = Math.round(options['ratingAvg'] * 100) / 100 || 0.0;
|
||||
this.rating_avg = Math.round(options['ratingAvg'] / STAR_RATING_RATIO * 100) / 100 || 0.0;
|
||||
this.rating_total = options['ratingTotal'] || 0.0;
|
||||
|
||||
this.options = _.defaults({}, options, {
|
||||
|
||||
Reference in New Issue
Block a user