[fix] gamification: correctly evaluate completness
bzr revid: mat@openerp.com-20130703102507-i85owm4ptmnulplc
This commit is contained in:
@@ -98,10 +98,10 @@ class gamification_badge(osv.Model):
|
||||
result = dict.fromkeys(ids, False)
|
||||
for badge in self.browse(cr, uid, ids, context=context):
|
||||
if self._can_grant_badge(cr, uid, uid, badge.id, context) != 1:
|
||||
#if the user cannot grant this badge at all, result is 0
|
||||
# if the user cannot grant this badge at all, result is 0
|
||||
result[badge.id] = 0
|
||||
elif not badge.rule_max:
|
||||
#if there is no limitation, -1 is returned which mean 'infinite'
|
||||
# if there is no limitation, -1 is returned which means 'infinite'
|
||||
result[badge.id] = -1
|
||||
else:
|
||||
result[badge.id] = badge.rule_max_number - badge.stat_my_monthly_sending
|
||||
|
||||
@@ -130,11 +130,13 @@ class gamification_goal(osv.Model):
|
||||
"""Return the percentage of completeness of the goal, between 0 and 100"""
|
||||
res = dict.fromkeys(ids, 0.0)
|
||||
for goal in self.browse(cr, uid, ids, context=context):
|
||||
if goal.type_condition == 'higher' and goal.current > 0:
|
||||
if goal.type_condition == 'higher':
|
||||
res[goal.id] = min(100, round(100.0 * goal.current / goal.target_goal, 2))
|
||||
elif goal.current < goal.target_goal:
|
||||
# a goal 'lower than' has only two values possible: 0 or 100%
|
||||
res[goal.id] = 100.0
|
||||
else:
|
||||
res[goal.id] = 0.0
|
||||
return res
|
||||
|
||||
def on_change_type_id(self, cr, uid, ids, type_id=False, context=None):
|
||||
|
||||
Reference in New Issue
Block a user