summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorNicolas Martinelli <nim@odoo.com>2020-07-09 12:07:51 +0000
committerNicolas Martinelli <nim@odoo.com>2020-07-09 13:51:28 +0000
commitca3b3d894ba62b2709f073bc0f7379d02914bb32 (patch)
treec0bd21be353c333f816868eac168a731316512f4 /addons
parent259cf453463448fdd25b5d29f45e0d3e8eb18382 (diff)
[FIX] rating: count and average
In an app using rating (e.g. eLearning), get 3 ratings: - A 5-star review - A 3-star review - A 0-star review The average is 2.5 stars, while it should be 4 stars. This happens because the 0-star review is taken into account in the average computation, while it shouldn't. Indeed, zero star means no review. We apply the same login than: https://github.com/odoo/odoo/blob/0028a602bea6a48aaa2747127ec075394732b324/addons/rating/models/rating_mixin.py#L205 opw-2290617 closes odoo/odoo#54279 X-original-commit: 4f7981f80fb55ab4bf8b30d137e45b4fda4013cd Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
Diffstat (limited to 'addons')
-rw-r--r--addons/rating/models/rating_mixin.py4
1 files changed, 2 insertions, 2 deletions
diff --git a/addons/rating/models/rating_mixin.py b/addons/rating/models/rating_mixin.py
index e0cf0e6837e..05e1df49874 100644
--- a/addons/rating/models/rating_mixin.py
+++ b/addons/rating/models/rating_mixin.py
@@ -3,7 +3,7 @@
from datetime import timedelta
from odoo import api, fields, models, tools
-from odoo.addons.rating.models.rating import RATING_LIMIT_SATISFIED, RATING_LIMIT_OK
+from odoo.addons.rating.models.rating import RATING_LIMIT_SATISFIED, RATING_LIMIT_OK, RATING_LIMIT_MIN
from odoo.osv import expression
@@ -68,7 +68,7 @@ class RatingMixin(models.AbstractModel):
@api.depends('rating_ids.res_id', 'rating_ids.rating')
def _compute_rating_stats(self):
""" Compute avg and count in one query, as thoses fields will be used together most of the time. """
- domain = self._rating_domain()
+ domain = expression.AND([self._rating_domain(), [('rating', '>=', RATING_LIMIT_MIN)]])
read_group_res = self.env['rating.rating'].read_group(domain, ['rating:avg'], groupby=['res_id'], lazy=False) # force average on rating column
mapping = {item['res_id']: {'rating_count': item['__count'], 'rating_avg': item['rating']} for item in read_group_res}
for record in self: