Skip to content

Commit

Permalink
[FIX] gamification: prevent division by zero in percentage completene…
Browse files Browse the repository at this point in the history
…ss 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 #40735

X-original-commit: 24546e7
Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
  • Loading branch information
alt-odoo authored and fw-bot committed Nov 22, 2019
1 parent c8e6362 commit ab60da1
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions addons/gamification/models/challenge.py
Expand Up @@ -377,11 +377,11 @@ def _generate_goals_from_challenge(self):
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
Expand Down

0 comments on commit ab60da1

Please sign in to comment.