From 6ca81cd8685f4152173eaaadfb1941d905ad2b8f Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Fri, 23 Aug 2019 14:06:18 +0000 Subject: [PATCH] [FIX] gamification: tolerate invalid definitions If a goal definition with a target goal of 0 and "higher the better", instead of dividing by 0, set a progress of 0% (it is not possible to compute the progress) Task id: 2057898 --- addons/gamification/models/challenge.py | 2 +- addons/gamification/models/goal.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/gamification/models/challenge.py b/addons/gamification/models/challenge.py index 381b78f6693..ae51158290c 100644 --- a/addons/gamification/models/challenge.py +++ b/addons/gamification/models/challenge.py @@ -743,7 +743,7 @@ class Challenge(models.Model): all_reached = False if goal.definition_condition == 'higher': # can be over 100 - total_completeness += 100.0 * goal.current / goal.target_goal + total_completeness += (100.0 * goal.current / goal.target_goal) if goal.target_goal else 0 elif goal.state == 'reached': # for lower goals, can not get percentage so 0 or 100 total_completeness += 100 diff --git a/addons/gamification/models/goal.py b/addons/gamification/models/goal.py index e182769a2e3..ce775ab2bd4 100644 --- a/addons/gamification/models/goal.py +++ b/addons/gamification/models/goal.py @@ -195,7 +195,7 @@ class Goal(models.Model): if goal.current >= goal.target_goal: goal.completeness = 100.0 else: - goal.completeness = round(100.0 * goal.current / goal.target_goal, 2) + goal.completeness = round(100.0 * goal.current / goal.target_goal, 2) if goal.target_goal else 0 elif goal.current < goal.target_goal: # a goal 'lower than' has only two values possible: 0 or 100% goal.completeness = 100.0