[IMP] gamification: add sql constraint to force rank's min_karma > 0
This commit adds a SQL constraint to force the min_karma of the gamification.karma.rank model to be above 0. A karma_min set to 0 (or lower) could create some frontend issues when displaying required karma. PR #39870 Task#2032649
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
from odoo import api, fields, models, exceptions
|
||||
from odoo import api, fields, models
|
||||
from odoo.tools.translate import html_translate
|
||||
|
||||
class KarmaRank(models.Model):
|
||||
@@ -14,9 +14,14 @@ class KarmaRank(models.Model):
|
||||
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')
|
||||
karma_min = fields.Integer(string='Required Karma', required=True, default=1,
|
||||
help='Minimum karma needed to reach this rank')
|
||||
user_ids = fields.One2many('res.users', 'rank_id', string='Users', help="Users having this rank")
|
||||
|
||||
_sql_constraints = [
|
||||
('karma_min_check', "CHECK( karma_min > 0 )", 'The required karma has to be above 0.')
|
||||
]
|
||||
|
||||
@api.model_create_multi
|
||||
def create(self, values_list):
|
||||
res = super(KarmaRank, self).create(values_list)
|
||||
|
||||
@@ -219,7 +219,7 @@ class TestComputeRankCommon(common.SavepointCase):
|
||||
|
||||
cls.rank_1 = cls.env['gamification.karma.rank'].create({
|
||||
'name': 'rank 1',
|
||||
'karma_min': 0,
|
||||
'karma_min': 1,
|
||||
})
|
||||
|
||||
cls.rank_2 = cls.env['gamification.karma.rank'].create({
|
||||
|
||||
Reference in New Issue
Block a user