diff options
| author | Rémy Baranx (bar) <bar@odoo.com> | 2021-04-16 05:49:57 +0000 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2021-04-30 09:50:06 +0000 |
| commit | d75deff4791702e1f085b2b16247d7f7c5335720 (patch) | |
| tree | 5ffa6347f46816502f6eca2d8c2c39b5041b05d2 /addons/gamification | |
| parent | 8da349e785b5b461ea19874df9686f8cd26af8ad (diff) | |
[FIX] gamification: apply res.users ir rules when retrieving badge owner info
When retreiving the list of badge owners in `_get_owners_info()`,
we should apply `res.users` ir rules to be sure to respect multi-company
rules.
upg-7081
closes odoo/odoo#69840
X-original-commit: 1190fc327e8efddd8d44c3fbd685bb97f472cd46
Signed-off-by: Christophe Simonis <chs@odoo.com>
Diffstat (limited to 'addons/gamification')
| -rw-r--r-- | addons/gamification/models/badge.py | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/addons/gamification/models/badge.py b/addons/gamification/models/badge.py index 81a9d0564e8..ed9a4c82631 100644 --- a/addons/gamification/models/badge.py +++ b/addons/gamification/models/badge.py @@ -146,14 +146,25 @@ class GamificationBadge(models.Model): 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, - array_agg(distinct(user_id)) as unique_owner_ids - FROM gamification_badge_user - WHERE badge_id in %s - GROUP BY badge_id - """, [tuple(self.ids)]) + Users = self.env["res.users"] + query = Users._where_calc([]) + Users._apply_ir_rules(query) + badge_alias = query.join("res_users", "id", "gamification_badge_user", "user_id", "badges") + + tables, where_clauses, where_params = query.get_sql() + + self.env.cr.execute( + f""" + SELECT {badge_alias}.badge_id, count(res_users.id) as stat_count, + count(distinct(res_users.id)) as stat_count_distinct, + array_agg(distinct(res_users.id)) as unique_owner_ids + FROM {tables} + WHERE {where_clauses} + AND {badge_alias}.badge_id IN %s + GROUP BY {badge_alias}.badge_id + """, + [*where_params, tuple(self.ids)] + ) mapping = { badge_id: { |
