[IMP] gamification: minor improvements and fix

bzr revid: mat@openerp.com-20130222094745-jxe0m4i11qbbe1vp
This commit is contained in:
Martin Trigaux 2013-02-22 10:47:45 +01:00
parent 0cc2ab390e
commit 14d9a9b573
4 changed files with 31 additions and 21 deletions

View File

@ -5,7 +5,6 @@
<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">days</field>
<field name="numbercall">-1</field>
@ -15,10 +14,9 @@
<field name="args">()</field>
</record>
<record forcecreate="True" id="ir_cron_check_goal"
<record forcecreate="True" id="ir_cron_check_plan"
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">days</field>
<field name="numbercall">-1</field>
@ -27,5 +25,6 @@
<field name="function">_update_all</field>
<field name="args">()</field>
</record>
</data>
</openerp>

View File

@ -167,8 +167,7 @@ class gamification_goal(osv.Model):
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)
ids = self.search(cr, uid, [('state', 'in', ('inprogress','inprogress_update', 'reached'))])
return self.update(cr, uid, ids, context=context)
def update(self, cr, uid, ids, context=None, force_update=False):
@ -180,11 +179,16 @@ class gamification_goal(osv.Model):
: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 ?
if not force_update and goal.state not in ('inprogress','inprogress_update','reached'):
# skip if goal failed 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)
continue
if goal.type_id.computation_mode == 'manually':
towrite = {'current': current}
towrite = {'current':goal.current}
# check for remind to update
if goal.remind_update_delay and goal.last_update:
delta_max = timedelta(days=goal.remind_update_delay)
@ -195,8 +199,8 @@ class gamification_goal(osv.Model):
obj = self.pool.get(goal.type_id.model_id.model)
field_date_name = goal.type_id.field_date_id.name
domain = safe_eval(goal.type_id.domain)
domain.append(('user_id', '=', goal.user_id.id))
domain = safe_eval(goal.type_id.domain,
{'user_id': goal.user_id.id})
if goal.start_date:
domain.append((field_date_name, '>=', goal.start_date))
if goal.end_date:
@ -244,10 +248,11 @@ class gamification_goal(osv.Model):
('user_id', '=', user_id),
('start_date', '=', start_date.isoformat())]
goal_ids = obj.search(cr, uid, domain, context=context)
print(domain, goal_ids)
if len(goal_ids) > 0:
# already exist, skip
return True
print("creating goal for", planline_id, user_id, start_date)
planline = self.pool.get('gamification.goal.planline').browse(cr, uid, planline_id, context)
values = {
'type_id':planline.type_id.id,
@ -327,7 +332,7 @@ class gamification_goal_plan(osv.Model):
string='Group',
help='Group of users whose members will automatically be added to the users'),
'period' : fields.selection([
('once', 'Manual'),
('once', 'No Periodicity'),
('daily', 'Daily'),
('weekly', 'Weekly'),
('monthly', 'Monthly'),
@ -397,8 +402,9 @@ class gamification_goal_plan(osv.Model):
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)
ids = self.search(cr, uid, [('state', '=', 'inprogress'),
('period', '!=', 'once')])
print("_update_all plans", ids)
return self.generate_goals_from_plan(cr, uid, ids, context=context)
def action_start(self, cr, uid, ids, context=None):

View File

@ -20,7 +20,7 @@
<field name="name">Goal List</field>
<field name="model">gamification.goal</field>
<field name="arch" type="xml">
<tree string="Goal List" colors="red:state == 'failed';green:state == 'reached'">
<tree string="Goal List" colors="red:state == 'failed';green:state == 'reached';grey:state == 'canceled'">
<field name="type_id"/>
<field name="user_id"/>
<field name="current"/>
@ -57,7 +57,12 @@
<field name="start_date"/>
<field name="end_date"/>
<field name="computation_mode" invisible="1"/>
<field name="remind_update_delay" attrs="{'invisible':[('computation_mode','!=', 'manually')]}"/>
<label for="remind_update_delay" attrs="{'invisible':[('computation_mode','!=', 'manually')]}"/>
<div attrs="{'invisible':[('computation_mode','!=', 'manually')]}">
<field name="remind_update_delay" class="oe_inline"/>
days
</div>
<field name="last_update" groups="base.group_no_one"/>
</group>
<group string="Data">

View File

@ -53,12 +53,12 @@
<field name="state" widget="statusbar"/>
</header>
<sheet>
<h1>
<div class="oe_edit_only">
<label for="name"/>
</div>
<field name="name" attrs="{'readonly':[('state','!=','draft')]}"/>
</h1>
<div class="oe_title">
<label for="name" class="oe_edit_only"/>
<h1>
<field name="name" attrs="{'readonly':[('state','!=','draft')]}"/>
</h1>
</div>
<!-- action buttons -->
<div class="oe_right oe_button_box">