diff --git a/addons/gamification/models/gamification_karma_rank.py b/addons/gamification/models/gamification_karma_rank.py index fc50218148e..a324b323773 100644 --- a/addons/gamification/models/gamification_karma_rank.py +++ b/addons/gamification/models/gamification_karma_rank.py @@ -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) diff --git a/addons/gamification/tests/test_karma_tracking.py b/addons/gamification/tests/test_karma_tracking.py index 3bbd904a86b..47b6eb577a7 100644 --- a/addons/gamification/tests/test_karma_tracking.py +++ b/addons/gamification/tests/test_karma_tracking.py @@ -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({