[IMP] gamification: move write in goal update inside the first loop to be able to group the computation by definition (and potentially apply intermediate commits)
bzr revid: mat@openerp.com-20140506112109-z4rsx5umet5x6n26
This commit is contained in:
parent
ccf4d142b0
commit
697dcae728
|
@ -241,7 +241,6 @@ class gamification_goal(osv.Model):
|
||||||
context = {}
|
context = {}
|
||||||
|
|
||||||
goals_by_definition = {}
|
goals_by_definition = {}
|
||||||
goals_to_write = {}
|
|
||||||
all_goals = {}
|
all_goals = {}
|
||||||
for goal in self.browse(cr, uid, ids, context=context):
|
for goal in self.browse(cr, uid, ids, context=context):
|
||||||
if goal.state in ('draft', 'canceled'):
|
if goal.state in ('draft', 'canceled'):
|
||||||
|
@ -249,10 +248,10 @@ class gamification_goal(osv.Model):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
goals_by_definition.setdefault(goal.definition_id, []).append(goal)
|
goals_by_definition.setdefault(goal.definition_id, []).append(goal)
|
||||||
goals_to_write[goal.id] = {}
|
|
||||||
all_goals[goal.id] = goal
|
all_goals[goal.id] = goal
|
||||||
|
|
||||||
for definition, goals in goals_by_definition.items():
|
for definition, goals in goals_by_definition.items():
|
||||||
|
goals_to_write = dict((goal.id, {}) for goal in goals)
|
||||||
if definition.computation_mode == 'manually':
|
if definition.computation_mode == 'manually':
|
||||||
for goal in goals:
|
for goal in goals:
|
||||||
goals_to_write[goal.id].update(self._check_remind_delay(cr, uid, goal, context))
|
goals_to_write[goal.id].update(self._check_remind_delay(cr, uid, goal, context))
|
||||||
|
@ -343,22 +342,22 @@ class gamification_goal(osv.Model):
|
||||||
if new_value != goal.current:
|
if new_value != goal.current:
|
||||||
goals_to_write[goal.id]['current'] = new_value
|
goals_to_write[goal.id]['current'] = new_value
|
||||||
|
|
||||||
for goal_id, value in goals_to_write.items():
|
for goal_id, value in goals_to_write.items():
|
||||||
if not value:
|
if not value:
|
||||||
continue
|
continue
|
||||||
goal = all_goals[goal_id]
|
goal = all_goals[goal_id]
|
||||||
|
|
||||||
# check goal target reached
|
# check goal target reached
|
||||||
if (goal.definition_condition == 'higher' and value.get('current', goal.current) >= goal.target_goal) \
|
if (goal.definition_condition == 'higher' and value.get('current', goal.current) >= goal.target_goal) \
|
||||||
or (goal.definition_condition == 'lower' and value.get('current', goal.current) <= goal.target_goal):
|
or (goal.definition_condition == 'lower' and value.get('current', goal.current) <= goal.target_goal):
|
||||||
value['state'] = 'reached'
|
value['state'] = 'reached'
|
||||||
|
|
||||||
# check goal failure
|
# check goal failure
|
||||||
elif goal.end_date and fields.date.today() > goal.end_date:
|
elif goal.end_date and fields.date.today() > goal.end_date:
|
||||||
value['state'] = 'failed'
|
value['state'] = 'failed'
|
||||||
value['closed'] = True
|
value['closed'] = True
|
||||||
if value:
|
if value:
|
||||||
self.write(cr, uid, [goal.id], value, context=context)
|
self.write(cr, uid, [goal.id], value, context=context)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def action_start(self, cr, uid, ids, context=None):
|
def action_start(self, cr, uid, ids, context=None):
|
||||||
|
|
Loading…
Reference in New Issue