summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorAurélien Warnon <awa@odoo.com>2019-11-04 08:03:36 +0000
committerAurélien Warnon <awa@odoo.com>2019-11-06 13:01:13 +0000
commit3773a0c552e1e671fa5dbcfa23cac82e12d24f67 (patch)
tree6df61625cd9347788420954a92ab6e7178b24e73 /addons
parent2390ef9bcd81f0e5d3a1be24f2b17839c21a2856 (diff)
[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
Diffstat (limited to 'addons')
-rw-r--r--addons/gamification/models/gamification_karma_rank.py9
-rw-r--r--addons/gamification/tests/test_karma_tracking.py2
2 files changed, 8 insertions, 3 deletions
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({