'Return total badge per level of users
TDE CLEANME: shouldn\'t check type is forum ?'

@api.multi
@api.depends('badge_ids')
def _get_user_badge_level(self):

    for user in self:
        user.gold_badge = 0
        user.silver_badge = 0
        user.bronze_badge = 0
    self.env.cr.execute('\n                                                SELECT    bu.user_id,    b.level,    count(1)\n                                                FROM    gamification_badge_user    bu,    gamification_badge    b\n                                                WHERE    bu.user_id    IN    %s\n                                                        AND    bu.badge_id    =    b.id\n                                                        AND    b.level    IS    NOT    NULL\n                                                GROUP    BY    bu.user_id,    b.level\n                                                ORDER    BY    bu.user_id;\n                                ', [tuple(self.ids)])
    for (user_id, level, count) in self.env.cr.fetchall():
        self.browse(user_id)['{}_badge'.format(level)] = count
