summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Trigaux <mat@odoo.com>2018-11-02 14:54:17 +0000
committerMartin Trigaux <mat@odoo.com>2018-11-02 15:41:00 +0000
commit2b4c1f3a45b08cc92206a460aa1b2b1fffad37d7 (patch)
treea3e1447d22366f949919b1af33f5bc168b566a17
parent079a3b602bf26b54d11532b29d28d41e310a8786 (diff)
[FIX] gamification: correct mail template on small challenges
A challenge with less than 3 participants was failing with a key error The challenge line has only one 'goal' result per participant As the template is set in a noupdate, even a module update does not fix the bug Generate fake goals that will be displayed in the top 3, e.g.: 1 Bob $100 42% 2 Alice $50 21% 3 0 0% closes odoo/odoo#28363
-rw-r--r--addons/gamification/data/goal_base.xml2
-rw-r--r--addons/gamification/models/challenge.py19
2 files changed, 18 insertions, 3 deletions
diff --git a/addons/gamification/data/goal_base.xml b/addons/gamification/data/goal_base.xml
index 80018820414..e26a64765f0 100644
--- a/addons/gamification/data/goal_base.xml
+++ b/addons/gamification/data/goal_base.xml
@@ -113,7 +113,7 @@ Thank you,
<tr><td style="padding:0 30px;">
<table cellspacing="0" cellpadding="0" width="100%" style="table-layout: fixed;">
<tr>
- % set top_goals = [line['goals'][1], line['goals'][0], line['goals'][2]]
+ % set top_goals = line['goals'][:3]
% for goal in top_goals:
<td align="center" style="width:32%;">
% if loop.index == 1:
diff --git a/addons/gamification/models/challenge.py b/addons/gamification/models/challenge.py
index dae80246da1..fc18220eae4 100644
--- a/addons/gamification/models/challenge.py
+++ b/addons/gamification/models/challenge.py
@@ -507,6 +507,9 @@ class Challenge(models.Model):
goals = Goals.search(domain, order="completeness desc, current desc")
else:
goals = Goals.search(domain, order="completeness desc, current asc")
+ if not goals:
+ continue
+
for ranking, goal in enumerate(goals):
if user and goal.user_id == user:
line_data['own_goal_id'] = goal.id
@@ -523,8 +526,20 @@ class Challenge(models.Model):
'completeness': goal.completeness,
'state': goal.state,
})
- if goals:
- res_lines.append(line_data)
+ if len(goals) < 3:
+ # display at least the top 3 in the results
+ missing = 3 - len(goals)
+ for ranking, mock_goal in enumerate([{'id': False,
+ 'user_id': False,
+ 'name': '',
+ 'current': 0,
+ 'completeness': 0,
+ 'state': False}] * missing,
+ start=len(goals)):
+ mock_goal['rank'] = ranking
+ line_data['goals'].append(mock_goal)
+
+ res_lines.append(line_data)
return res_lines
##### Reporting #####