summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDebauche Stéphane <std@odoo.com>2019-09-24 13:51:31 +0000
committerThibault Delavallée <tde@odoo.com>2019-09-27 15:11:27 +0000
commitf518a7dc637122ad320b49bfb5e996fb71961d95 (patch)
tree9f9fc071dd0c4f3044093e611804d5d30a219c85
parent09c9d1f0d0d1db251c074045e5c2fdc52165c6b7 (diff)
[FIX] rating: fix image computation and display
Currently if we try to display image of a rating having a different value of 0/1/5/10 there is an infinite loading. Indeed images for rating are limited to those values. In this commit we fix that by computing a rounded value to find the closest image. Text display in form view is also centered for better wow onboarding back 2 basics demo usability fiximp effect.
-rw-r--r--addons/rating/models/rating.py11
-rw-r--r--addons/rating/views/rating_view.xml2
2 files changed, 11 insertions, 2 deletions
diff --git a/addons/rating/models/rating.py b/addons/rating/models/rating.py
index 04f8c474e14..238f1e6b25d 100644
--- a/addons/rating/models/rating.py
+++ b/addons/rating/models/rating.py
@@ -67,9 +67,18 @@ class Rating(models.Model):
@api.depends('rating')
def _compute_rating_image(self):
+ # Due to some new widgets, we may have ratings different from 0/1/5/10 (e.g. slide.channel review)
+ # Let us have some custom rounding while finding a better solution for images.
for rating in self:
+ rating_for_img = 0
+ if rating.rating >= 8:
+ rating_for_img = 10
+ elif rating > 3:
+ rating_for_img = 5
+ elif rating.rating >= 1:
+ rating_for_img = 1
try:
- image_path = get_resource_path('rating', 'static/src/img', 'rating_%s.png' % (int(rating.rating),))
+ image_path = get_resource_path('rating', 'static/src/img', 'rating_%s.png' % rating_for_img)
rating.rating_image = base64.b64encode(open(image_path, 'rb').read())
except (IOError, OSError):
rating.rating_image = False
diff --git a/addons/rating/views/rating_view.xml b/addons/rating/views/rating_view.xml
index 768577979af..3c82f82be8a 100644
--- a/addons/rating/views/rating_view.xml
+++ b/addons/rating/views/rating_view.xml
@@ -42,7 +42,7 @@
<group>
<div colspan="2" class="text-center">
<field name="rating_image" widget='image'/>
- <div class="mt4 text-left">
+ <div class="mt4">
<strong><field name="rating_text"/></strong>
</div>
</div>