[ADD] gamification: add basic report templates
bzr revid: mat@openerp.com-20130225084540-u6m6csrcnp4555jt
This commit is contained in:
@@ -23,7 +23,7 @@
|
||||
'version': '1.0',
|
||||
'author': 'OpenERP SA',
|
||||
'category': 'Human Resources',
|
||||
'depends': ['mail'],
|
||||
'depends': ['mail', 'report_webkit'],
|
||||
'description': """Gamification of goals""",
|
||||
|
||||
'data': [
|
||||
@@ -32,6 +32,7 @@
|
||||
'view/plan.xml',
|
||||
'view/menu.xml',
|
||||
'cron.xml',
|
||||
'report/report_progress.xml',
|
||||
],
|
||||
'installable': True,
|
||||
'application': True,
|
||||
|
||||
@@ -382,7 +382,7 @@ class gamification_goal_plan(osv.Model):
|
||||
"""Reset a closed goal plan
|
||||
|
||||
Change the state of the plan to in progress
|
||||
Closing a pan does not affect the goals so reset as well"""
|
||||
Closing a plan does not affect the goals so neither does reset"""
|
||||
return self.write(cr, uid, ids, {'state': 'inprogress'}, context=context)
|
||||
|
||||
def action_cancel(self, cr, uid, ids, context=None):
|
||||
@@ -403,7 +403,7 @@ class gamification_goal_plan(osv.Model):
|
||||
def generate_goals_from_plan(self, cr, uid, ids, context=None):
|
||||
"""Generate the lsit of goals fron a plan"""
|
||||
for plan in self.browse(cr, uid, ids, context):
|
||||
today = date.today() #fields.date.today()
|
||||
today = date.today()
|
||||
if plan.period == 'daily':
|
||||
start_date = today
|
||||
elif plan.period == 'weekly':
|
||||
@@ -485,6 +485,68 @@ class gamification_goal_plan(osv.Model):
|
||||
return True
|
||||
|
||||
|
||||
def report_progress(self, cr, uid, ids, context=None):
|
||||
"""Post report about the progress of the goals"""
|
||||
|
||||
goal_obj = self.pool.get('gamification.goal')
|
||||
|
||||
for plan in self.browse(cr, uid, ids, context=context):
|
||||
if plan.visibility_mode == 'board':
|
||||
# generate a shared report
|
||||
pass
|
||||
else:
|
||||
# generate individual reports
|
||||
report_title = "Individual Report for {0} - {1}".format(plan.name, fields.date.today())
|
||||
for user in plan.user_ids:
|
||||
goal_ids = self.get_current_related_user_goals(cr, uid, plan.id, user.id, context)
|
||||
|
||||
for goal in goal_obj.browse(cr, uid, goal_ids, context=context):
|
||||
pass
|
||||
|
||||
|
||||
def get_current_related_user_goals(self, cr, uid, plan_id, user_id, context=None):
|
||||
"""Get the ids of goals linked to a plan for the current instance
|
||||
|
||||
If several goals are linked to the same planline and user, only the
|
||||
latest instance of the plan is checked (eg :if the plan is monthly,
|
||||
return the goals started the 1st of this month).
|
||||
"""
|
||||
|
||||
plan in self.browse(cr, uid, plan_id, context=context)
|
||||
today = date.today()
|
||||
if plan.period == 'daily':
|
||||
start_date = today
|
||||
elif plan.period == 'weekly':
|
||||
delta = timedelta(days=today.weekday())
|
||||
start_date = today - delta
|
||||
elif plan.period == 'monthly':
|
||||
delta = timedelta(days=today.day-1)
|
||||
start_date = today - delta
|
||||
elif plan.period == 'yearly':
|
||||
start_date = today.replace(month=1, day=1)
|
||||
elif plan.period == 'once':
|
||||
start_date = False # for manual goal, start each time
|
||||
|
||||
goal_obj = self.pool.get('gamification.goal')
|
||||
related_goal_ids = []
|
||||
|
||||
for planline in plan.planline_ids:
|
||||
domain = [('planline_id', '=', planline.id),
|
||||
('user_id', '=', user_id)]
|
||||
|
||||
if start_date:
|
||||
domain.append(('start_date', '=', start_date.isoformat()))
|
||||
|
||||
goal_ids = goal_obj.search(cr, uid, domain, context=context)
|
||||
if len(goal_ids) == 1:
|
||||
related_goal_ids.append(goal_ids[0])
|
||||
elif len(goal_ids) == 0:
|
||||
# this goal has been deleted
|
||||
raise osv.except_osv(_('Warning!'), _('Planline {0} has no goal present for user {1} at date {2}'.format(planline.id, user.id, start_date)))
|
||||
else: # more than one goal ?
|
||||
raise osv.except_osv(_('Warning!'), _('Duplicate goals for planline {0}, user {1}, date {2}'.format(planline.id, user.id, start_date)))
|
||||
related_goal_ids.extend(goal_ids)
|
||||
|
||||
class gamification_goal_planline(osv.Model):
|
||||
"""Gamification goal planline
|
||||
|
||||
@@ -528,3 +590,6 @@ class gamification_goal_planline(osv.Model):
|
||||
'gamification.goal.type': (_get_planline_types, ['sequence'], 10),
|
||||
}),
|
||||
}
|
||||
|
||||
# class gamification_goal_report(osv.Model):
|
||||
# _name = 'gamification.goal.report'
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
<?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" />
|
||||
<field name="search_view_id" ref="email_template.view_email_template_search"/>
|
||||
</record>
|
||||
<menuitem id="menu_email_templates" parent="gamification_menu" action="action_email_templates" sequence="30" groups="base.group_no_one"/>
|
||||
|
||||
</data>
|
||||
|
||||
<!-- Mail template are declared in a NOUPDATE block
|
||||
so users can freely customize/delete them -->
|
||||
<data noupdate="1">
|
||||
<!--Email template -->
|
||||
<record id="email_template_edi_invoice" model="email.template">
|
||||
<field name="name">Individual Report - Send by Email</field>
|
||||
<field name="email_from">noreply@localhost</field>
|
||||
<field name="subject">${object.title}</field>
|
||||
<field name="email_recipients">${object.partner_id.id}</field>
|
||||
<field name="model_id" ref="gamification.goal.report"/>
|
||||
<field name="auto_delete" eval="True"/>
|
||||
<field name="report_name">Individual_Report_${(object.number or '').replace('/','_')}_${object.state == 'draft' and 'draft' or ''}</field>
|
||||
<field name="body_html"><![CDATA[
|
||||
<div style="font-family: 'Lucica Grande', Ubuntu, Arial, Verdana, sans-serif; font-size: 12px; color: rgb(34, 34, 34); background-color: #FFF; ">
|
||||
|
||||
<h1>${report.title}</h1>
|
||||
|
||||
<p>Hello ${report.user}, bellow are your latest results for the plan ${report.plan_name}.</p>
|
||||
|
||||
<table width="100%" border="1">
|
||||
<tr>
|
||||
<th>Goal</th>
|
||||
<th>Target</th>
|
||||
<th>Current</th>
|
||||
<th>Completeness</th>
|
||||
</tr>
|
||||
% for goal in report:
|
||||
<tr>
|
||||
<td>${goal.type_id.name}</td>
|
||||
<td>${goal.target_goal}</td>
|
||||
<td>${goal.current}</td>
|
||||
<td>${goal.completeness} %</td>
|
||||
</tr>
|
||||
% endfor
|
||||
</table>
|
||||
|
||||
</div>
|
||||
]]></field>
|
||||
</record>
|
||||
</data>
|
||||
</openerp>
|
||||
Reference in New Issue
Block a user