Odoo Mindscape. Understand Odoo faster. Explore modules, fields, dependencies and version differences in one place instead of digging through the source code.

Module: Gamification

Entity: res.users

Compute Method: _compute_karma

Inputs Method Outputs
  • id
if self.env.context.get('skip_karma_computation'):
            # do not need to update the user karma
            # e.g. during the tracking consolidation
            return
self.env['gamification.karma.tracking'].flush_model()
select_query = """
            SELECT DISTINCT ON (user_id) user_id, new_value
              FROM gamification_karma_tracking
             WHERE user_id = ANY(%(user_ids)s)
          ORDER BY user_id, tracking_date DESC, id DESC
        """
self.env.cr.execute(select_query, {'user_ids': self.ids})
user_karma_map = {
            values['user_id']: values['new_value']
            for values in self.env.cr.dictfetchall()
        }
for user in self:
            user.karma = user_karma_map.get(user.id, 0)
self.sudo()._recompute_rank()

Back to entity