[REF] gamification : rename stat_* fields into granted_* to ease understanding

In this commit we rename stat_count into granted_count, and stat_count_distinct
into granted_users_count to reflect more what are those variables, aka count
of granted badges.

Task ID: 1961053
PR #32594
This commit is contained in:
David Beguin
2019-11-22 14:44:39 +00:00
committed by Thibault Delavallée
parent e85faf3986
commit 6f0d36fa67
5 changed files with 16 additions and 16 deletions
+8 -8
View File
@@ -107,8 +107,8 @@ class GamificationBadge(models.Model):
'gamification.badge.user', 'badge_id',
string='Owners', help='The list of instances of this badge granted to users')
stat_count = fields.Integer("Total", compute='_get_owners_info', help="The number of time this badge has been received.")
stat_count_distinct = fields.Integer("Number of users", compute='_get_owners_info', help="The number of time this badge has been received by unique users.")
granted_count = fields.Integer("Total", compute='_get_owners_info', help="The number of time this badge has been received.")
granted_users_count = fields.Integer("Number of users", compute='_get_owners_info', help="The number of time this badge has been received by unique users.")
unique_owner_ids = fields.Many2many(
'res.users', string="Unique Owners", compute='_get_owners_info',
help="The list of unique users having received this badge.")
@@ -139,8 +139,8 @@ class GamificationBadge(models.Model):
the total number of users this badge was granted to
"""
self.env.cr.execute("""
SELECT badge_id, count(user_id) as stat_count,
count(distinct(user_id)) as stat_count_distinct,
SELECT badge_id, count(user_id) as granted_count,
count(distinct(user_id)) as granted_users_count,
array_agg(distinct(user_id)) as unique_owner_ids
FROM gamification_badge_user
WHERE badge_id in %s
@@ -148,14 +148,14 @@ class GamificationBadge(models.Model):
""", [tuple(self.ids)])
defaults = {
'stat_count': 0,
'stat_count_distinct': 0,
'granted_count': 0,
'granted_users_count': 0,
'unique_owner_ids': [],
}
mapping = {
badge_id: {
'stat_count': count,
'stat_count_distinct': distinct_count,
'granted_count': count,
'granted_users_count': distinct_count,
'unique_owner_ids': owner_ids,
}
for (badge_id, count, distinct_count, owner_ids) in self.env.cr._obj
+5 -5
View File
@@ -35,7 +35,7 @@
<field name="arch" type="xml">
<tree string="Badge List">
<field name="name"/>
<field name="stat_count"/>
<field name="granted_count"/>
<field name="stat_this_month"/>
<field name="stat_my"/>
<field name="rule_auth"/>
@@ -93,9 +93,9 @@
</group>
<group string="Statistics">
<group>
<field name="stat_count"/>
<field name="granted_count"/>
<field name="stat_this_month"/>
<field name="stat_count_distinct"/>
<field name="granted_users_count"/>
</group>
<group>
<field name="stat_my"/>
@@ -117,7 +117,7 @@
<field name="name"/>
<field name="description"/>
<field name="stat_my"/>
<field name="stat_count"/>
<field name="granted_count"/>
<field name="stat_this_month"/>
<field name="unique_owner_ids"/>
<field name="stat_my_monthly_sending"/>
@@ -141,7 +141,7 @@
</span>
<div t-if="record.remaining_sending.value == 0" class="oe_grey">Can not grant</div>
<div>
<strong><t t-esc="record.stat_count.raw_value"/></strong> granted,
<strong><t t-esc="record.granted_count.raw_value"/></strong> granted,
<strong><t t-esc="record.stat_this_month.raw_value"/></strong> this month
</div>
<div t-if="record.description.value" class="o_kanban_badge_description">
@@ -7,7 +7,7 @@
<field name="inherit_id" ref="gamification.badge_form_view"/>
<field name="arch" type="xml">
<div name="button_box" position="inside">
<button class="oe_stat_button" type="object" name="get_granted_employees" attrs="{'invisible': [('stat_count','=',0)]}" icon="fa-user">
<button class="oe_stat_button" type="object" name="get_granted_employees" attrs="{'invisible': [('granted_count','=',0)]}" icon="fa-user">
<field name="granted_employees_count" string="Granted" widget="statinfo"/>
</button>
</div>
+1 -1
View File
@@ -180,7 +180,7 @@ class WebsiteProfile(http.Controller):
Badge = request.env['gamification.badge']
badges = Badge.sudo().search(self._prepare_badges_domain(**kwargs))
badges = sorted(badges, key=lambda b: b.stat_count_distinct, reverse=True)
badges = sorted(badges, key=lambda b: b.granted_users_count, reverse=True)
values = self._prepare_user_values(searches={'badges': True})
values.update({
@@ -442,7 +442,7 @@
<h6 t-field="badge.name" class="d-inline my-0"/>
</td>
<td class="align-middle d-none d-md-table-cell">
<b t-esc="badge.stat_count_distinct"/>
<b t-esc="badge.granted_users_count"/>
<i class="text-muted"> awarded users</i>
</td>
<td class="align-middle">