19.0 vanilla

This commit is contained in:
Ernad Husremovic 2026-03-09 09:32:43 +01:00
parent 4607ccbd2e
commit 825ff6514e
487 changed files with 184979 additions and 195262 deletions

View file

@ -5,6 +5,8 @@ import logging
from datetime import date
from odoo import api, fields, models, _, exceptions
from odoo.tools import SQL
_logger = logging.getLogger(__name__)
@ -98,24 +100,24 @@ class GamificationBadge(models.Model):
return
Users = self.env["res.users"]
query = Users._where_calc([])
Users._apply_ir_rules(query)
query = Users._search([])
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,
rows = self.env.execute_query(SQL(
"""
SELECT %(badge_alias)s.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
FROM %(from_clause)s
WHERE %(where_clause)s
AND %(badge_alias)s.badge_id IN %(ids)s
GROUP BY %(badge_alias)s.badge_id
""",
[*where_params, tuple(self.ids)]
)
from_clause=query.from_clause,
where_clause=query.where_clause or SQL("TRUE"),
badge_alias=SQL.identifier(badge_alias),
ids=tuple(self.ids),
))
mapping = {
badge_id: {
@ -123,7 +125,7 @@ class GamificationBadge(models.Model):
'granted_users_count': distinct_count,
'unique_owner_ids': owner_ids,
}
for (badge_id, count, distinct_count, owner_ids) in self.env.cr._obj
for (badge_id, count, distinct_count, owner_ids) in rows
}
for badge in self:
badge.update(mapping.get(badge.id, defaults))
@ -195,8 +197,6 @@ class GamificationBadge(models.Model):
def _can_grant_badge(self):
"""Check if a user can grant a badge to another user
:param uid: the id of the res.users trying to send the badge
:param badge_id: the granted badge id
:return: integer representing the permission.
"""
if self.env.is_admin():