[ADD] gamification: send reminder for update
bzr revid: mat@openerp.com-20130227105956-pu0xjsswucjou5o9
This commit is contained in:
parent
86bb3fbb2a
commit
504b6c4ca7
|
@ -33,6 +33,7 @@
|
|||
'view/menu.xml',
|
||||
'cron.xml',
|
||||
'report/report_progress.xml',
|
||||
'report/reminder.xml',
|
||||
],
|
||||
'installable': True,
|
||||
'application': True,
|
||||
|
|
|
@ -24,7 +24,7 @@ from openerp.tools.safe_eval import safe_eval
|
|||
|
||||
from mako.template import Template as MakoTemplate
|
||||
|
||||
from datetime import date, timedelta
|
||||
from datetime import date, datetime, timedelta
|
||||
import calendar
|
||||
import itertools
|
||||
|
||||
|
@ -115,13 +115,6 @@ class gamification_goal_type(osv.Model):
|
|||
|
||||
|
||||
|
||||
def compute_goal_completeness(current, target_goal):
|
||||
# more than 100% case is handled by the widget
|
||||
if target_goal > 0:
|
||||
return 100.0 * current / target_goal
|
||||
else:
|
||||
return 0.0
|
||||
|
||||
class gamification_goal(osv.Model):
|
||||
"""Goal instance for a user
|
||||
|
||||
|
@ -132,9 +125,14 @@ class gamification_goal(osv.Model):
|
|||
_inherit = 'mail.thread'
|
||||
|
||||
def _get_completeness(self, cr, uid, ids, field_name, arg, context=None):
|
||||
"""Return the percentage of completeness of the goal, between 0 and 100"""
|
||||
res = {}
|
||||
for goal in self.browse(cr, uid, ids, context):
|
||||
res[goal.id] = compute_goal_completeness(goal.current, goal.target_goal)
|
||||
if goal.current > 0:
|
||||
res[goal.id] = min(100, round(100.0 * goal.current / goal.target_goal, 2))
|
||||
else:
|
||||
res[goal.id] = 0.0
|
||||
|
||||
return res
|
||||
|
||||
def on_change_type_id(self, cr, uid, ids, type_id=False, context=None):
|
||||
|
@ -194,7 +192,6 @@ class gamification_goal(osv.Model):
|
|||
}
|
||||
|
||||
|
||||
|
||||
def _update_all(self, cr, uid, ids=False, context=None):
|
||||
"""Update every goal in progress"""
|
||||
if not ids:
|
||||
|
@ -208,7 +205,7 @@ class gamification_goal(osv.Model):
|
|||
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."""
|
||||
|
||||
|
||||
for goal in self.browse(cr, uid, ids, context=context or {}):
|
||||
if goal.state not in ('inprogress','inprogress_update','reached'):
|
||||
# skip if goal failed or canceled
|
||||
|
@ -223,9 +220,14 @@ class gamification_goal(osv.Model):
|
|||
# check for remind to update
|
||||
if goal.remind_update_delay and goal.last_update:
|
||||
delta_max = timedelta(days=goal.remind_update_delay)
|
||||
if fields.date.today() - goal.last_update > delta_max:
|
||||
last_update = datetime.strptime(goal.last_update,'%Y-%m-%d').date()
|
||||
if date.today() - last_update > delta_max:
|
||||
towrite['state'] = 'inprogress_update'
|
||||
|
||||
# generate a remind report
|
||||
template_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'gamification', 'email_template_goal_reminder')[1]
|
||||
self.pool.get('email.template').send_mail(cr, uid, template_id, goal.id, context=context)
|
||||
|
||||
else: # count or sum
|
||||
obj = self.pool.get(goal.type_id.model_id.model)
|
||||
field_date_name = goal.type_id.field_date_id.name
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" ?>
|
||||
<openerp>
|
||||
<data>
|
||||
<record id="email_template_goal_reminder" model="email.template">
|
||||
<field name="name">Goal Update Reminder - Send by Email</field>
|
||||
<field name="email_from">noreply@localhost</field>
|
||||
<field name="subject">Goal Update Reminder</field>
|
||||
<field name="email_recipients">${object.user_id.email}</field>
|
||||
<field name="model_id" ref="gamification.model_gamification_goal"/>
|
||||
<field name="auto_delete" eval="True"/>
|
||||
<field name="body_html"><![CDATA[
|
||||
<div>
|
||||
<p>Hello ${object.user_id.name}</p>
|
||||
|
||||
<p>You have not updated your progress for the goal ${object.type_id.name} (currently reached at ${object.completeness}%) for at least ${object.remind_update_delay}. Do not forget to do it.</p>
|
||||
|
||||
<p>If you have not changed your score yet, you can use the button "The current value is up to date" to indicate so.</p>
|
||||
</div>
|
||||
]]></field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
|
@ -1,16 +1,5 @@
|
|||
<?xml version="1.0" ?>
|
||||
<openerp>
|
||||
<data>
|
||||
<!-- EDI related Email Templates menu -->
|
||||
<record model="ir.actions.act_window" id="action_email_templates">
|
||||
<field name="name">Email Templates</field>
|
||||
<field name="res_model">email.template</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form,tree</field>
|
||||
<field name="view_id" ref="email_template.email_template_tree" />
|
||||
</record>
|
||||
</data>
|
||||
|
||||
<data>
|
||||
<!--Email template for individual report -->
|
||||
<record id="email_template_gamification_individual" model="email.template">
|
||||
|
|
|
@ -48,7 +48,7 @@
|
|||
</header>
|
||||
<sheet>
|
||||
<div class="oe_right oe_button_box" attrs="{'invisible':[('computation_mode','!=', 'manually')]}">
|
||||
<button name="write" type="object" string="Refresh/The value is up to date" help="Indicate that the current value of the manual goal is still correct and avoid reminders"/>
|
||||
<button name="write" type="object" string="The current value is up to date" help="Indicate that the current value of the manual goal is still correct and avoid reminders"/>
|
||||
</div>
|
||||
<group>
|
||||
<group string="Reference">
|
||||
|
|
Loading…
Reference in New Issue