[FIX] gamification: prevent division by zero in percentage completeness computation

We are initializing over the limit to make sure we will compute it at least once.
If the target goal is set to 0, we are facing a division by zero error when
displaying the gamification goal just after initialization.

closes odoo/odoo#40735

X-original-commit: 24546e7c4cac61efea8d3f9e558518a55ef9acd2
Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
This commit is contained in:
alt-odoo
2019-11-22 16:57:21 +00:00
committed by fw-bot
parent c8e6362e60
commit ab60da1269
+5 -5
View File
@@ -377,11 +377,11 @@ class Challenge(models.Model):
if end_date:
values['end_date'] = end_date
# the goal is initialised over the limit to make sure we will compute it at least once
if line.condition == 'higher':
values['current'] = min(line.target_goal - 1, 0)
else:
values['current'] = max(line.target_goal + 1, 0)
# the goal is initialised over the limit to make sure we will compute it at least once
if line.condition == 'higher':
values['current'] = min(line.target_goal - 1, 0)
else:
values['current'] = max(line.target_goal + 1, 0)
if challenge.remind_update_delay:
values['remind_update_delay'] = challenge.remind_update_delay