diff options
| author | David Beguin <dbe@odoo.com> | 2019-03-05 12:14:21 +0000 |
|---|---|---|
| committer | Thibault Delavallée <tde@odoo.com> | 2019-03-06 14:08:24 +0000 |
| commit | 1949c796b522dbb96b3823839742e8727ab670b5 (patch) | |
| tree | 1ad7297bdfe0975f7efd00c5cc68ce6c90b6d52f /addons/gamification | |
| parent | c7cceaef793052a98c159822a75ba0abf76d57a4 (diff) | |
[FIX] gamification, website_profile : re-fix division by zero if user has no karma
If a new user try to access the elearning platform or his porfile, if he has
no karma, has it is the case for new users, he won't get any rank. So that
the next rank karma minus current rank karma equals zero.
To avoid this, next_rank will always be first one existing if the user has no
karma. Also, the current rank will not be displayed if the user has no karma.
finally, next rank will not be displayed if the user reached the last existing
rank.
Task ID : 1941250
PR #31512
Diffstat (limited to 'addons/gamification')
| -rw-r--r-- | addons/gamification/data/gamification_karma_rank_data.xml | 6 | ||||
| -rw-r--r-- | addons/gamification/models/res_users.py | 20 | ||||
| -rw-r--r-- | addons/gamification/static/img/rank_misc_world.png | bin | 0 -> 53474 bytes |
3 files changed, 18 insertions, 8 deletions
diff --git a/addons/gamification/data/gamification_karma_rank_data.xml b/addons/gamification/data/gamification_karma_rank_data.xml index 2a5ad0231fe..b83c36327e7 100644 --- a/addons/gamification/data/gamification_karma_rank_data.xml +++ b/addons/gamification/data/gamification_karma_rank_data.xml @@ -13,6 +13,12 @@ <record id="rank_newbie" model="gamification.karma.rank"> <field name="name">Newbie</field> <field name="description" type="html"><p>You just began the adventure! Welcome!</p></field> + <field name="description_motivational" type="html"> + <div class="media align-items-center"> + <div class="media-body">Reach the next rank to start conquering the world!</div> + <img class="ml-3 img img-fluid" style="max-height: 72px;" src="/gamification/static/img/rank_misc_world.png"/> + </div> + </field> <field name="karma_min">1</field> <field name="image" type="base64" file="gamification/static/img/rank_newbie_badge.svg"/> </record> diff --git a/addons/gamification/models/res_users.py b/addons/gamification/models/res_users.py index 8f59f6c7591..f556dcc514a 100644 --- a/addons/gamification/models/res_users.py +++ b/addons/gamification/models/res_users.py @@ -47,9 +47,10 @@ class Users(models.Model): @api.multi def write(self, vals): + result = super(Users, self).write(vals) if 'karma' in vals: self._recompute_rank() - return super(Users, self).write(vals) + return result @api.multi def add_karma(self, karma): @@ -72,13 +73,16 @@ class Users(models.Model): self.env['gamification.karma.rank'].search([], order="karma_min DESC")] for user in self: old_rank = user.rank_id - for i in range(0, len(ranks)): - if user.karma >= ranks[i]['karma_min']: - user.write({ - 'rank_id': ranks[i]['rank'].id, - 'next_rank_id': ranks[i - 1]['rank'].id if i > 0 else False - }) - break + if user.karma == 0 and ranks: + user.write({'next_rank_id': ranks[-1]['rank'].id}) + else: + for i in range(0, len(ranks)): + if user.karma >= ranks[i]['karma_min']: + user.write({ + 'rank_id': ranks[i]['rank'].id, + 'next_rank_id': ranks[i - 1]['rank'].id if 0 < i else False + }) + break if old_rank != user.rank_id: user._rank_changed() diff --git a/addons/gamification/static/img/rank_misc_world.png b/addons/gamification/static/img/rank_misc_world.png Binary files differnew file mode 100644 index 00000000000..087b7e7bd1d --- /dev/null +++ b/addons/gamification/static/img/rank_misc_world.png |
