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: _get_user_badge_level

Inputs Method Outputs
""" Return total badge per level of users
        TDE CLEANME: shouldn't check type is forum ? """
for user in self:
            user.gold_badge = 0
            user.silver_badge = 0
            user.bronze_badge = 0
self.env.cr.execute("""
            SELECT bu.user_id, b.level, count(1)
            FROM gamification_badge_user bu, gamification_badge b
            WHERE bu.user_id IN %s
              AND bu.badge_id = b.id
              AND b.level IS NOT NULL
            GROUP BY bu.user_id, b.level
            ORDER BY bu.user_id;
        """, [tuple(self.ids)])
for (user_id, level, count) in self.env.cr.fetchall():
            # levels are gold, silver, bronze but fields have _badge postfix
            self.browse(user_id)['{}_badge'.format(level)] = count

Back to entity