Files
odoo_source/addons/gamification/models/gamification_karma_rank.py
T
Thibault Delavallée e7b3535884 [REF] gamification: clean next rank motivational implementation
Purpose of this commit is to clean motivational capabilities of gamification
ranks[1]. It makes more sense to store a motivational to achieve on next rank
itself. We therefore rename the field and provide nice demo data that will be
used in elearning use of gamification ranks.

Commit linked to task ID 1941250 and PR #31133.

[1] task ID 1922159 (landed at 91ee6ba5a7)
2019-02-15 17:45:11 +00:00

55 lines
2.2 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from werkzeug.exceptions import Forbidden
from odoo import api, tools, fields, models
from odoo.tools.translate import html_translate
class KarmaError(Forbidden):
""" Karma-related error, used for forum and posts. """
pass
class KarmaRank(models.Model):
_name = 'gamification.karma.rank'
_description = 'Rank based on karma'
_order = 'karma_min'
name = fields.Text(string='Rank Name', translate=True, required=True)
description = fields.Html(string='Description', translate=html_translate, sanitize_attributes=False,)
description_motivational = fields.Html(
string='Motivational', translate=html_translate, sanitize_attributes=False,
help="Motivational phrase to reach this rank")
karma_min = fields.Integer(string='Required Karma', help='Minimum karma needed to reach this rank')
user_ids = fields.One2many('res.users', 'rank_id', string='Users', help="Users having this rank")
image = fields.Binary('Rank Icon')
image_medium = fields.Binary(
"Medium-sized rank icon",
help="Medium-sized icon of the rank. It is automatically "
"resized as a 128x128px image, with aspect ratio preserved. "
"Use this field in form views or some kanban views.")
image_small = fields.Binary(
"Small-sized rank icon",
help="Small-sized icon of the rank. It is automatically "
"resized as a 64x64px image, with aspect ratio preserved. "
"Use this field anywhere a small image is required.")
@api.model_create_multi
def create(self, values_list):
for vals in values_list:
tools.image_resize_images(vals)
res = super(KarmaRank, self).create(values_list)
users = self.env['res.users'].sudo().search([('karma', '>', 0)])
users._recompute_rank()
return res
@api.multi
def write(self, vals):
tools.image_resize_images(vals)
res = super(KarmaRank, self).write(vals)
users = self.env['res.users'].sudo().search([('karma', '>', 0)])
users._recompute_rank()
return res