mirror of
https://github.com/bringout/oca-ocb-vertical-industry.git
synced 2026-04-22 12:32:11 +02:00
19.0 vanilla
This commit is contained in:
parent
4607ccbd2e
commit
825ff6514e
487 changed files with 184979 additions and 195262 deletions
|
|
@ -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():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue