diff --git a/addons/gamification/models/challenge.py b/addons/gamification/models/challenge.py index f4704f2de29..e7176e8cb09 100644 --- a/addons/gamification/models/challenge.py +++ b/addons/gamification/models/challenge.py @@ -264,6 +264,9 @@ class gamification_challenge(osv.Model): - Create the missing goals (eg: modified the challenge to add lines) - Update every running challenge """ + if context is None: + context = {} + # start scheduled challenges planned_challenge_ids = self.search(cr, uid, [ ('state', '=', 'draft'), @@ -281,6 +284,9 @@ class gamification_challenge(osv.Model): if not ids: ids = self.search(cr, uid, [('state', '=', 'inprogress')], context=context) + # in cron mode, will do intermediate commits + # TODO in trunk: replace by parameter + context.update({'commit_gamification': True}) return self._update_all(cr, uid, ids, context=context) def _update_all(self, cr, uid, ids, context=None): diff --git a/addons/gamification/models/goal.py b/addons/gamification/models/goal.py index 2cbb8869eb7..b4a47a0d07a 100644 --- a/addons/gamification/models/goal.py +++ b/addons/gamification/models/goal.py @@ -239,6 +239,7 @@ class gamification_goal(osv.Model): the target value being reached, the goal is set as failed.""" if context is None: context = {} + commit = context.get('commit_gamification', False) goals_by_definition = {} all_goals = {} @@ -358,6 +359,8 @@ class gamification_goal(osv.Model): value['closed'] = True if value: self.write(cr, uid, [goal.id], value, context=context) + if commit: + cr.commit() return True def action_start(self, cr, uid, ids, context=None):