diff --git a/addons/gamification/cron.xml b/addons/gamification/cron.xml
index c025ba3dad7..52726176841 100644
--- a/addons/gamification/cron.xml
+++ b/addons/gamification/cron.xml
@@ -9,7 +9,7 @@
-1
gamification.goal.plan
- _update_all
+ _cron_update
()
diff --git a/addons/gamification/goal.py b/addons/gamification/goal.py
index 60b39c2e5a0..ccf14dce35f 100644
--- a/addons/gamification/goal.py
+++ b/addons/gamification/goal.py
@@ -40,6 +40,7 @@ class gamification_goal_type(osv.Model):
_columns = {
'name': fields.char('Type Name', required=True, translate=True),
'description': fields.text('Description'),
+ 'unit': fields.char('Unit', help="The unit of the target and current values", translate=True),
'computation_mode': fields.selection([
('sum','Sum'),
('count','Count'),
@@ -64,8 +65,8 @@ class gamification_goal_type(osv.Model):
help="Technical filters rules to apply",
required=True), # how to apply it ?
'condition' : fields.selection([
- ('minus','<='),
- ('plus','>=')
+ ('lower','<='),
+ ('higher','>=')
],
string='Validation Condition',
help='A goal is considered as completed when the current value is compared to the value to reach',
@@ -78,7 +79,7 @@ class gamification_goal_type(osv.Model):
_order = 'sequence'
_defaults = {
'sequence': 1,
- 'condition': 'plus',
+ 'condition': 'higher',
'computation_mode':'manually',
'domain':"[]",
}
@@ -158,7 +159,6 @@ class gamification_goal(osv.Model):
'current': 0,
'state': 'draft',
'start_date': fields.date.today,
- 'last_update': fields.date.today,
}
@@ -172,12 +172,11 @@ class gamification_goal(osv.Model):
the target value being reached, the goal is set as failed."""
for goal in self.browse(cr, uid, ids, context=context or {}):
- if goal.state not in ('inprogress','inprogress_update','reached'):
- # skip if goal draft, failed or canceled
+ if goal.state in ('draft','canceled'):
+ # skip if goal draft or canceled
continue
- if goal.state == 'reached' and goal.end_date and fields.date.today() > goal.end_date:
- # only a goal reached but not passed the end date will still be
- # checked (to be able to improve the score)
+ if goal.last_update and goal.end_date and goal.last_update > goal.end_date:
+ # skip if a goal is finished (updated after the goal end date)
continue
if goal.type_id.computation_mode == 'manually':
@@ -220,9 +219,9 @@ class gamification_goal(osv.Model):
towrite = {'current': len(res)}
# check goal target reached
- if (goal.type_id.condition == 'plus' \
+ if (goal.type_id.condition == 'higher' \
and towrite['current'] >= goal.target_goal) \
- or (goal.type_id.condition == 'minus' \
+ or (goal.type_id.condition == 'lower' \
and towrite['current'] <= goal.target_goal):
towrite['state'] = 'reached'
diff --git a/addons/gamification/plan.py b/addons/gamification/plan.py
index 6131fc3f827..7a74e686c53 100644
--- a/addons/gamification/plan.py
+++ b/addons/gamification/plan.py
@@ -112,6 +112,7 @@ class gamification_goal_plan(osv.Model):
string='Periodicity',
help='Period of automatic goal assigment. If none is selected, should be launched manually.',
required=True),
+ 'start_date' : fields.date('Starting Date', help="The day a new plan will be automatically started. The start and end dates for goals are still defined by the periodicity (eg: weekly goals run from Monday to Sunday)."),
'state': fields.selection([
('draft', 'Draft'),
('inprogress', 'In progress'),
@@ -153,7 +154,8 @@ class gamification_goal_plan(osv.Model):
'state': 'draft',
'visibility_mode' : 'progressbar',
'report_message_frequency' : 'onchange',
- 'last_report_date' : fields.date.today
+ 'last_report_date' : fields.date.today,
+ 'start_date' : fields.date.today,
}
def _check_nonzero_planline(self, cr, uid, ids, context=None):
@@ -192,14 +194,19 @@ class gamification_goal_plan(osv.Model):
return write_res
- def _update_all(self, cr, uid, context=None, ids=False):
- """Update the plans and goals
+ def _cron_update(self, cr, uid, context=None, ids=False):
+ """Daily cron check.
+ Start planned plans (in draft and with start_date = today)
Create the goals for planlines not linked to goals (eg: modified the
plan to add planlines)
- :param list(int) ids: the ids of the plans to update, if False will
- update only plans in progress."""
- if not context: context = {}
+ Update every goal running"""
+ if not context: context = {}
+
+ # start planned plans
+ planned_plan_ids = self.search(cr, uid, [('state', '=', 'draft'),('start_date','=',fields.date.today())])
+ self.action_start(cr, uid, planned_plan_ids, context=context)
+
if not ids:
ids = self.search(cr, uid, [('state', '=', 'inprogress')])
@@ -208,15 +215,26 @@ class gamification_goal_plan(osv.Model):
goal_obj = self.pool.get('gamification.goal')
# we use yesterday to update the goals that just ended
yesterday = date.today() - timedelta(days=1)
+ # TOCHECK conflict with date rule in goal update() function
goal_ids = goal_obj.search(cr, uid, [
'&',
- ('state', 'in', ('inprogress','inprogress_update', 'reached')),
+ ('state', 'not in', ('draft','canceled')),
'|',
('end_date', '>=', yesterday.isoformat()),
('end_date', '=', False)
], context=context)
goal_obj.update(cr, uid, goal_ids, context=context)
+ return self._update_all(cr, uid, ids, context=context)
+
+
+ def _update_all(self, cr, uid, ids, context=None):
+ """Update the plans and related goals
+
+ :param list(int) ids: the ids of the plans to update, if False will
+ update only plans in progress."""
+ if not context: context = {}
+
for plan in self.browse(cr, uid, ids, context=context):
# goals closed but still opened at the last report date
closed_goals_to_report = []
@@ -246,15 +264,15 @@ class gamification_goal_plan(osv.Model):
if plan.autojoin_group_id:
self.plan_subscribe_users(cr, uid, ids, [user.id for user in plan.autojoin_group_id.users], context=context)
- self.generate_goals_from_plan(cr, uid, ids, context=context)
- return self.write(cr, uid, ids, {'state': 'inprogress'}, context=context)
+ self.write(cr, uid, ids, {'state': 'inprogress'}, context=context)
+ return self.generate_goals_from_plan(cr, uid, ids, context=context)
def action_check(self, cr, uid, ids, context=None):
"""Check a goal plan
Create goals that haven't been created yet (eg: if added users of planlines)
Recompute the current value for each goal related"""
- return self._update_all(cr, uid, ids=ids, context=context)
+ return self._update_all(cr, uid, ids=ids, context=context)
def action_close(self, cr, uid, ids, context=None):
@@ -324,11 +342,10 @@ class gamification_goal_plan(osv.Model):
for plan in self.browse(cr, uid, ids, context):
(start_date, end_date) = start_end_date_for_period(plan.period)
-
+
for planline in plan.planline_ids:
for user in plan.user_ids:
- #self.create_goal_from_plan(cr, uid, ids, planline.id, user.id, start_date, context=context)
-
+
goal_obj = self.pool.get('gamification.goal')
domain = [('planline_id', '=', planline.id),
('user_id', '=', user.id)]
diff --git a/addons/gamification/plan_view.xml b/addons/gamification/plan_view.xml
index 9d0621082ba..6fe8ce30a34 100644
--- a/addons/gamification/plan_view.xml
+++ b/addons/gamification/plan_view.xml
@@ -44,7 +44,7 @@