summaryrefslogtreecommitdiff
path: root/addons/gamification/models
diff options
context:
space:
mode:
authorBenjamin Vray <bvr@odoo.com>2020-10-20 09:23:53 +0000
committerBenjamin Vray <bvr@odoo.com>2020-10-20 09:23:53 +0000
commit85995b7a4f0544779f3de537f0e6024820abbd5d (patch)
tree26e416f7d2bdac764d74f6f6d312cc7744731a01 /addons/gamification/models
parentb4de3c4e34500c9d4e3e2eef68c880643953f2ff (diff)
[FIX] gamification: fix badge creation
Before this commit, we executed the request even when creating a new badge. And it thrown a traceback. After this commit, we return default values before executing the request if this is a new badge. task-2312878 closes odoo/odoo#60347 Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
Diffstat (limited to 'addons/gamification/models')
-rw-r--r--addons/gamification/models/badge.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/addons/gamification/models/badge.py b/addons/gamification/models/badge.py
index c202bde3374..81a9d0564e8 100644
--- a/addons/gamification/models/badge.py
+++ b/addons/gamification/models/badge.py
@@ -137,6 +137,15 @@ class GamificationBadge(models.Model):
the total number of time this badge was granted
the total number of users this badge was granted to
"""
+ defaults = {
+ 'granted_count': 0,
+ 'granted_users_count': 0,
+ 'unique_owner_ids': [],
+ }
+ if not self.ids:
+ self.update(defaults)
+ return
+
self.env.cr.execute("""
SELECT badge_id, count(user_id) as granted_count,
count(distinct(user_id)) as granted_users_count,
@@ -146,11 +155,6 @@ class GamificationBadge(models.Model):
GROUP BY badge_id
""", [tuple(self.ids)])
- defaults = {
- 'granted_count': 0,
- 'granted_users_count': 0,
- 'unique_owner_ids': [],
- }
mapping = {
badge_id: {
'granted_count': count,