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 | |
| 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')
| -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 | |||
| -rw-r--r-- | addons/website_profile/views/website_profile.xml | 13 | ||||
| -rw-r--r-- | addons/website_slides/views/website_slides_templates_homepage.xml | 14 |
5 files changed, 35 insertions, 18 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 diff --git a/addons/website_profile/views/website_profile.xml b/addons/website_profile/views/website_profile.xml index 602258ee30f..96de581b036 100644 --- a/addons/website_profile/views/website_profile.xml +++ b/addons/website_profile/views/website_profile.xml @@ -178,8 +178,8 @@ </div> <button class="btn btn-sm d-md-none bg-white border" type="button" data-toggle="collapse" data-target="#o_wprofile_sidebar_collapse" aria-expanded="false" aria-controls="o_wprofile_sidebar_collapse">More info</button> </div> - <div t-if="user.rank_id" class="collapse d-md-block" id="o_wprofile_sidebar_collapse"> - <div class="mb-3"> + <div class="collapse d-md-block" id="o_wprofile_sidebar_collapse"> + <div t-if="user.next_rank_id" class="mb-3"> <small class="font-weight-bold mt-1">Next rank:</small> <t t-call="website_profile.profile_next_rank_card"> <t t-set="img_max_width">40%</t> @@ -228,9 +228,14 @@ </template> <template id="profile_next_rank_card" name="Profile Next Rank Card"> - <div class="o_wprofile_progress_circle"> + <div t-if="user.next_rank_id" class="o_wprofile_progress_circle"> <svg viewBox="0 0 36 36" class="o_pc_circular_chart"> - <t t-set="user_points" t-value="int(100*(user.karma - user.rank_id.karma_min)/(user.next_rank_id.karma_min - user.rank_id.karma_min))"/> + <t t-if="(user.next_rank_id.karma_min - user.rank_id.karma_min) > 0"> + <t t-set="user_points" t-value="int(100*(user.karma - user.rank_id.karma_min)/(user.next_rank_id.karma_min - user.rank_id.karma_min))"/> + </t> + <t t-else=""> + <t t-set="user_points" t-value="0"/> + </t> <path class="o_pc_circle_bg" d="M18 2.0845 a 15.9155 15.9155 0 0 1 0 31.831 a 15.9155 15.9155 0 0 1 0 -31.831" /> <path class="o_pc_circle" t-attf-stroke-dasharray="#{user_points}, 100" d="M18 2.0845 a 15.9155 15.9155 0 0 1 0 31.831 a 15.9155 15.9155 0 0 1 0 -31.831" stroke="url(#gradient)" /> <linearGradient id="gradient"> diff --git a/addons/website_slides/views/website_slides_templates_homepage.xml b/addons/website_slides/views/website_slides_templates_homepage.xml index 932903d2e9f..de99ad1eef8 100644 --- a/addons/website_slides/views/website_slides_templates_homepage.xml +++ b/addons/website_slides/views/website_slides_templates_homepage.xml @@ -342,17 +342,19 @@ <template id='slides_home_user_profile_small' name="User Profile"> <div class="o_wslides_home_aside"> - <div class="d-flex align-items-center"> + <div t-if="user.rank_id" class="d-flex align-items-center"> <span class="font-weight-bold text-muted mr-2">Current rank:</span> <img t-attf-src="/web/image/gamification.karma.rank/#{user.rank_id.id}/image_small" height="16" alt="" class="mr-1"/> <a href="/profile/ranks" t-field="user.rank_id"/> </div> - <div class="font-weight-bold text-muted mt-1">Next rank:</div> - <t t-call="website_profile.profile_next_rank_card"> - <t t-set="bg_class">bg-200</t> - <t t-set="img_max_width">50%</t> + <t t-if="user.next_rank_id"> + <div class="font-weight-bold text-muted mt-1">Next rank:</div> + <t t-call="website_profile.profile_next_rank_card"> + <t t-set="bg_class">bg-200</t> + <t t-set="img_max_width">50%</t> + </t> + <div t-field="user.next_rank_id.description_motivational"/> </t> - <div t-field="user.next_rank_id.description_motivational"/> </div> </template> |
