diff options
Diffstat (limited to 'addons/gamification/models')
| -rw-r--r-- | addons/gamification/models/badge.py | 2 | ||||
| -rw-r--r-- | addons/gamification/models/challenge.py | 6 | ||||
| -rw-r--r-- | addons/gamification/models/goal.py | 9 |
3 files changed, 15 insertions, 2 deletions
diff --git a/addons/gamification/models/badge.py b/addons/gamification/models/badge.py index 4eb58b86a9f..1f21c03194a 100644 --- a/addons/gamification/models/badge.py +++ b/addons/gamification/models/badge.py @@ -95,7 +95,7 @@ class gamification_badge(osv.Model): the total number of time this badge was granted the total number of users this badge was granted to """ - result = dict.fromkeys(ids, {'stat_count':0, 'stat_count_distinct':0, 'unique_owner_ids':[]}) + result = dict((res_id, {'stat_count': 0, 'stat_count_distinct': 0, 'unique_owner_ids': []}) for res_id in ids) cr.execute(""" SELECT badge_id, count(user_id) as stat_count, diff --git a/addons/gamification/models/challenge.py b/addons/gamification/models/challenge.py index 2a1c6d5b0a5..4e128fc8f12 100644 --- a/addons/gamification/models/challenge.py +++ b/addons/gamification/models/challenge.py @@ -204,6 +204,7 @@ class gamification_challenge(osv.Model): 'category': 'hr', 'reward_failure': False, 'report_template_id': lambda s, *a, **k: s._get_report_template(*a, **k), + 'reward_realtime': True, } @@ -361,6 +362,9 @@ class gamification_challenge(osv.Model): return True + def action_start(self, cr, uid, ids, context=None): + """Start a challenge""" + return self.write(cr, uid, ids, {'state': 'inprogress'}, context=context) def action_check(self, cr, uid, ids, context=None): """Check a challenge @@ -707,7 +711,7 @@ class gamification_challenge(osv.Model): rewarded_users = [] challenge_ended = end_date == yesterday.strftime(DF) or force - if challenge.reward_id and challenge_ended or challenge.reward_realtime: + if challenge.reward_id and (challenge_ended or challenge.reward_realtime): # not using start_date as intemportal goals have a start date but no end_date reached_goals = self.pool.get('gamification.goal').read_group(cr, uid, [ ('challenge_id', '=', challenge.id), diff --git a/addons/gamification/models/goal.py b/addons/gamification/models/goal.py index 118991773ec..fb050753992 100644 --- a/addons/gamification/models/goal.py +++ b/addons/gamification/models/goal.py @@ -81,6 +81,8 @@ class gamification_goal_definition(osv.Model): 'model_id': fields.many2one('ir.model', string='Model', help='The model object for the field to evaluate'), + 'model_inherited_model_ids': fields.related('model_id', 'inherited_model_ids', type="many2many", obj="ir.model", + string="Inherited models", readonly="True"), 'field_id': fields.many2one('ir.model.fields', string='Field to Sum', help='The field containing the value to evaluate'), @@ -160,6 +162,13 @@ class gamification_goal_definition(osv.Model): return res + def on_change_model_id(self, cr, uid, ids, model_id, context=None): + """Prefill field model_inherited_model_ids""" + if not model_id: + return {'value': {'model_inherited_model_ids': []}} + model = self.pool['ir.model'].browse(cr, uid, model_id, context=context) + # format (6, 0, []) to construct the domain ('model_id', 'in', m and m[0] and m[0][2]) + return {'value': {'model_inherited_model_ids': [(6, 0, [m.id for m in model.inherited_model_ids])]}} class gamification_goal(osv.Model): """Goal instance for a user |
