[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.
This commit is contained in:
Debauche Stéphane
2019-09-27 15:11:27 +00:00
committed by Thibault Delavallée
parent 09c9d1f0d0
commit f518a7dc63
2 changed files with 11 additions and 2 deletions
+10 -1
View File
@@ -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
+1 -1
View File
@@ -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>