diff --git a/addons/gamification/__openerp__.py b/addons/gamification/__openerp__.py
index 896a5b4eb01..f76d7a03c72 100644
--- a/addons/gamification/__openerp__.py
+++ b/addons/gamification/__openerp__.py
@@ -31,6 +31,7 @@
'view/goal.xml',
'view/plan.xml',
'view/menu.xml',
+ 'cron.xml',
],
'installable': True,
'application': True,
diff --git a/addons/gamification/cron.xml b/addons/gamification/cron.xml
new file mode 100644
index 00000000000..b222d0e6d8c
--- /dev/null
+++ b/addons/gamification/cron.xml
@@ -0,0 +1,31 @@
+
+
+
+
+
+ Run Goal Checker
+
+ 1
+ day
+ -1
+
+ gamification.goal
+ _update_all
+ ()
+
+
+
+ Run Goal Plan Checker
+
+ 1
+ day
+ -1
+
+ gamification.goal.plan
+ _update_all
+ ()
+
+
+
\ No newline at end of file
diff --git a/addons/gamification/goal.py b/addons/gamification/goal.py
index 0c0a0af325a..aa9bf282788 100644
--- a/addons/gamification/goal.py
+++ b/addons/gamification/goal.py
@@ -94,8 +94,7 @@ def compute_goal_completeness(current, target_goal):
class gamification_goal(osv.Model):
"""Goal instance for a user
- An individual goal for a user on a specified time period
- """
+ An individual goal for a user on a specified time period"""
_name = 'gamification.goal'
_description = 'Gamification goal instance'
@@ -163,14 +162,22 @@ class gamification_goal(osv.Model):
'last_update': fields.date.today,
}
+
+
+ def _update_all(self, cr, uid, ids=False, context=None):
+ """Update every goal in progress"""
+ if not ids:
+ ids = self.search(cr, uid, [('state', 'in', ('inprogress','inprogress_update'))])
+ print("_update_all", ids)
+ return self.update(cr, uid, ids, context=context)
+
def update(self, cr, uid, ids, context=None, force_update=False):
"""Update the goals to recomputes values and change of states
If a goal reaches the target value, the status is set to reach
If the end date is passed (at least +1 day, time not considered) without
the target value being reached, the goal is set as failed
- If the force_update parameter is false, only goals in progress are
- checked."""
+ :param force_update: if false, only goals in progress are checked."""
for goal in self.browse(cr, uid, ids, context=context or {}):
if not force_update and goal.state not in ('inprogress','inprogress_update'): # reached ?
@@ -276,7 +283,6 @@ class gamification_goal(osv.Model):
obj = self.pool.get('gamification.goal')
goal_ids = obj.search(cr, uid, [('planline_id', '=', planline_id)], context=context)
- print("cancel goals", goal_ids)
return self.write(cr, uid, goal_ids, {'state': 'canceled'}, context=context)
def action_reach(self, cr, uid, ids, context=None):
@@ -388,6 +394,13 @@ class gamification_goal_plan(osv.Model):
(_check_nonzero_users, "At least one user is required to create a non-draft goal plan", ['user_ids']),
]
+ def _update_all(self, cr, uid, ids=False, context=None):
+ """Update every plan in progress"""
+ if not ids:
+ ids = self.search(cr, uid, [('state', '=', 'inprogress')])
+ print("_update_all", ids)
+ return self.generate_goals_from_plan(cr, uid, ids, context=context)
+
def action_start(self, cr, uid, ids, context=None):
"""Start a draft goal plan
@@ -402,6 +415,9 @@ class gamification_goal_plan(osv.Model):
Recompute the current value for each goal related"""
self.generate_goals_from_plan(cr, uid, ids, context=context)
for plan in self.browse(cr, uid, ids, context):
+ if plan.state != 'improgress':
+ continue
+
for planline in plan.planline_ids:
goal_obj = self.pool.get('gamification.goal')
goal_ids = goal_obj.search(cr, uid, [('planline_id', '=', planline.id)] , context=context)
diff --git a/addons/gamification/view/goal.xml b/addons/gamification/view/goal.xml
index f23749b846f..9c641de2711 100644
--- a/addons/gamification/view/goal.xml
+++ b/addons/gamification/view/goal.xml
@@ -44,7 +44,7 @@
-
+
@@ -58,6 +58,7 @@
+