[ADD] gamification: add cron for daily check
bzr revid: mat@openerp.com-20130221135000-zlycsakfxe0q1m05
This commit is contained in:
parent
721f5c5785
commit
1bc388a081
|
@ -31,6 +31,7 @@
|
|||
'view/goal.xml',
|
||||
'view/plan.xml',
|
||||
'view/menu.xml',
|
||||
'cron.xml',
|
||||
],
|
||||
'installable': True,
|
||||
'application': True,
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<!-- Scheduler for goal checking-->
|
||||
<record forcecreate="True" id="ir_cron_check_goal"
|
||||
model="ir.cron">
|
||||
<field name="name">Run Goal Checker</field>
|
||||
<field eval="True" name="active" />
|
||||
<field name="interval_number">1</field>
|
||||
<field name="interval_type">day</field>
|
||||
<field name="numbercall">-1</field>
|
||||
<field eval="False" name="doall" />
|
||||
<field name="model">gamification.goal</field>
|
||||
<field name="function">_update_all</field>
|
||||
<field name="args">()</field>
|
||||
</record>
|
||||
|
||||
<record forcecreate="True" id="ir_cron_check_goal"
|
||||
model="ir.cron">
|
||||
<field name="name">Run Goal Plan Checker</field>
|
||||
<field eval="True" name="active" />
|
||||
<field name="interval_number">1</field>
|
||||
<field name="interval_type">day</field>
|
||||
<field name="numbercall">-1</field>
|
||||
<field eval="False" name="doall" />
|
||||
<field name="model">gamification.goal.plan</field>
|
||||
<field name="function">_update_all</field>
|
||||
<field name="args">()</field>
|
||||
</record>
|
||||
</data>
|
||||
</openerp>
|
|
@ -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)
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
<button string="Goal Reached" type="object" name="action_reach" states="inprogress,inprogress_update" />
|
||||
<button string="Goal Failed" type="object" name="action_fail" states="inprogress,inprogress_update"/>
|
||||
<button string="Reset Completion" type="object" name="action_cancel" states="failed,reached"/>
|
||||
<field name="state" widget="statusbar" statusbar_visible="inprogress,inprogress_update" />
|
||||
<field name="state" widget="statusbar" statusbar_visible="inprogress" />
|
||||
</header>
|
||||
<sheet>
|
||||
<group>
|
||||
|
@ -58,6 +58,7 @@
|
|||
<field name="end_date"/>
|
||||
<field name="computation_mode" invisible="1"/>
|
||||
<field name="remind_update_delay" attrs="{'invisible':[('computation_mode','!=', 'manually')]}"/>
|
||||
<field name="last_update" groups="base.group_no_one"/>
|
||||
</group>
|
||||
<group string="Data">
|
||||
<field name="target_goal"/>
|
||||
|
|
Loading…
Reference in New Issue