Permalink
Browse files

[IMP] gamification : rename rank.karma_required into karma_min for gr…

…ep convenience

Rename rank.karma_required into karma_min to avoid confusion
with karma_required from website_forum

Linked to Task ID : 1922159
Closes PR #30965
  • Loading branch information...
dbeguin committed Feb 8, 2019
1 parent a20408e commit b9902d961e0e14cfcf7987fbf4cb5c534baaecc5
@@ -6,7 +6,7 @@
<field name="name">Newbie</field>
<field name="description" type="html"><p>You just began the adventure! Welcome!</p></field>
<field name="description_reach_next" type="html"><p>Keep going !</p></field>
<field name="karma_required">1</field>
<field name="karma_min">1</field>
<field name="image" type="base64" file="gamification/static/img/rank_newbie.png"/>
</record>
</data>
@@ -5,31 +5,31 @@
<field name="name">Student</field>
<field name="description" type="html"><p>You begin to understand things ! Keep going!</p></field>
<field name="description_reach_next" type="html"><p>Keep going !</p></field>
<field name="karma_required">100</field>
<field name="karma_min">100</field>
<field name="image" type="base64" file="gamification/static/img/rank_student.png"/>
</record>

<record id="rank_bachelor" model="gamification.karma.rank">
<field name="name">Bachelor</field>
<field name="description" type="html"><p>Hey ! You're not so dumb after all !</p></field>
<field name="description_reach_next" type="html"><p>Keep going !</p></field>
<field name="karma_required">500</field>
<field name="karma_min">500</field>
<field name="image" type="base64" file="gamification/static/img/rank_bachelor.png"/>
</record>

<record id="rank_master" model="gamification.karma.rank">
<field name="name">Master</field>
<field name="description" type="html"><p>You're good ! Really Good !</p></field>
<field name="description_reach_next" type="html"><p>Keep going !</p></field>
<field name="karma_required">2000</field>
<field name="karma_min">2000</field>
<field name="image" type="base64" file="gamification/static/img/rank_master.png"/>
</record>

<record id="rank_doctor" model="gamification.karma.rank">
<field name="name">Doctor</field>
<field name="description" type="html"><p>Ok, RESPECT !</p></field>
<field name="description_reach_next" type="html"><p>Keep going !</p></field>
<field name="karma_required">10000</field>
<field name="karma_min">10000</field>
<field name="image" type="base64" file="gamification/static/img/rank_doctor.png"/>
</record>

@@ -15,14 +15,14 @@ class KarmaError(Forbidden):
class KarmaRank(models.Model):
_name = 'gamification.karma.rank'
_description = 'Rank based on karma'
_order = 'karma_required'
_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_reach_next = fields.Html(
string='Motivation phrase', translate=html_translate, sanitize_attributes=False,
help="Motivation phrase to reach next rank")
karma_required = fields.Integer(string='Required Karma', help='Minimum karma needed 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(
@@ -58,7 +58,7 @@ def add_karma(self, karma):
return True

def _rank_changed(self):
if self.rank_id.karma_required > 0:
if self.rank_id.karma_min > 0:
template = self.env.ref('gamification.mail_template_data_new_rank_reached', raise_if_not_found=False)
if template:
template.send_mail(self.id, force_send=True, notif_layout='mail.mail_notification_light')
@@ -68,11 +68,11 @@ def _recompute_rank(self):
The caller should filter the users on karma > 0 before calling this method
to avoid looping on every single users
"""
ranks = [{'rank': rank, 'karma_required': rank.karma_required} for rank in
self.env['gamification.karma.rank'].search([], order="karma_required DESC")]
ranks = [{'rank': rank, 'karma_min': rank.karma_min} for rank in
self.env['gamification.karma.rank'].search([], order="karma_min DESC")]
for user in self:
for i in range(0, len(ranks)):
if user.karma >= ranks[i]['karma_required']:
if user.karma >= ranks[i]['karma_min']:
if user.rank_id != ranks[i]['rank']:
user.rank_id = ranks[i]['rank'].id
user.next_rank_id = ranks[i - 1]['rank'].id if i > 0 else False
@@ -21,7 +21,7 @@
<field name="arch" type="xml">
<search string="Search Ranks">
<field name="name"/>
<field name="karma_required"/>
<field name="karma_min"/>
<field name="description"/>
<field name="user_ids"/>
</search>
@@ -34,7 +34,7 @@
<field name="arch" type="xml">
<tree string="Ranks List">
<field name="name"/>
<field name="karma_required"/>
<field name="karma_min"/>
<field name="description"/>
<field name="user_ids"/>
</tree>
@@ -56,7 +56,7 @@
</h1>
</div>
<group>
<field name="karma_required"/>
<field name="karma_min"/>
<field name="description" placeholder="e.g. A Master Chief knows quite everything on the forum! You cannot beat him!"/>
<field name="create_date" invisible="1"/>
</group>

0 comments on commit b9902d9

Please sign in to comment.