[ADD] gamification: send email for individual report
bzr revid: mat@openerp.com-20130226113403-2hw21ush1gw1kis0
This commit is contained in:
@@ -1,2 +1,3 @@
|
||||
import goal
|
||||
import res_users
|
||||
import res_users
|
||||
import report
|
||||
|
||||
+29
-20
@@ -2,26 +2,28 @@
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2013 Tiny SPRL (<http://openerp.com>).
|
||||
# Copyright (C) 2010-Today OpenERP SA (<http://www.openerp.com>)
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from openerp.osv import fields, osv
|
||||
from openerp.tools.safe_eval import safe_eval
|
||||
|
||||
from mako.template import Template as MakoTemplate
|
||||
|
||||
from datetime import date, timedelta
|
||||
import calendar
|
||||
import itertools
|
||||
@@ -476,7 +478,6 @@ class gamification_goal_plan(osv.Model):
|
||||
:param ids: ids of plans to which the users will be added
|
||||
:param user_ids: ids of the users to add"""
|
||||
|
||||
print("subscibe users", ids, user_ids)
|
||||
for plan in self.browse(cr,uid, ids, context):
|
||||
subscription = [user.id for user in plan.user_ids]
|
||||
subscription.extend(user_ids)
|
||||
@@ -489,21 +490,30 @@ class gamification_goal_plan(osv.Model):
|
||||
"""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:
|
||||
if not plan.report_message_group_id:
|
||||
continue
|
||||
|
||||
# generate individual reports
|
||||
report_title = "Individual Report for {0} - {1}".format(plan.name, fields.date.today())
|
||||
template_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'gamification', 'email_template_gamification_individual')[1]
|
||||
|
||||
for user in plan.user_ids:
|
||||
|
||||
goal_ids = self.get_current_related_user_goals(cr, uid, plan.id, user.id, context)
|
||||
if len(goal_ids) == 0:
|
||||
continue
|
||||
|
||||
template_context = dict(context)
|
||||
template_context['goals'] = goal_obj.browse(cr, uid, goal_ids, context=context)
|
||||
template_context['user'] = user
|
||||
self.pool.get('email.template').send_mail(cr, uid, template_id, plan.id, context=template_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
|
||||
|
||||
@@ -512,7 +522,7 @@ class gamification_goal_plan(osv.Model):
|
||||
return the goals started the 1st of this month).
|
||||
"""
|
||||
|
||||
plan in self.browse(cr, uid, plan_id, context=context)
|
||||
plan = self.browse(cr, uid, plan_id, context=context)
|
||||
today = date.today()
|
||||
if plan.period == 'daily':
|
||||
start_date = today
|
||||
@@ -542,11 +552,13 @@ class gamification_goal_plan(osv.Model):
|
||||
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)))
|
||||
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)))
|
||||
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)
|
||||
|
||||
return related_goal_ids
|
||||
|
||||
class gamification_goal_planline(osv.Model):
|
||||
"""Gamification goal planline
|
||||
|
||||
@@ -589,7 +601,4 @@ class gamification_goal_planline(osv.Model):
|
||||
store={
|
||||
'gamification.goal.type': (_get_planline_types, ['sequence'], 10),
|
||||
}),
|
||||
}
|
||||
|
||||
# class gamification_goal_report(osv.Model):
|
||||
# _name = 'gamification.goal.report'
|
||||
}
|
||||
@@ -8,30 +8,23 @@
|
||||
<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">
|
||||
<data>
|
||||
<!--Email template -->
|
||||
<record id="email_template_edi_invoice" model="email.template">
|
||||
<record id="email_template_gamification_individual" 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="subject">Individual report - ${object.name}</field>
|
||||
<field name="email_recipients">${object.report_message_group_id.alias_id.name_get()[0][1]}</field>
|
||||
<field name="model_id" ref="gamification.model_gamification_goal_plan"/>
|
||||
<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; ">
|
||||
<div>
|
||||
<h1>Individual report - ${object.name}</h1>
|
||||
|
||||
<h1>${report.title}</h1>
|
||||
|
||||
<p>Hello ${report.user}, bellow are your latest results for the plan ${report.plan_name}.</p>
|
||||
<p>Hello ${ctx['user'].name}, bellow are your latest results for the plan ${object.name}.</p>
|
||||
|
||||
<table width="100%" border="1">
|
||||
<tr>
|
||||
@@ -40,7 +33,7 @@
|
||||
<th>Current</th>
|
||||
<th>Completeness</th>
|
||||
</tr>
|
||||
% for goal in report:
|
||||
% for goal in ctx['goals']:
|
||||
<tr>
|
||||
<td>${goal.type_id.name}</td>
|
||||
<td>${goal.target_goal}</td>
|
||||
|
||||
@@ -9,7 +9,6 @@ class res_users_gamification_group(osv.Model):
|
||||
_inherit = ['res.users']
|
||||
|
||||
def write(self, cr, uid, ids, vals, context=None):
|
||||
print("Overwrite res_users_gamification_group", ids)
|
||||
write_res = super(res_users_gamification_group, self).write(cr, uid, ids, vals, context=context)
|
||||
if vals.get('groups_id'):
|
||||
# form: {'group_ids': [(3, 10), (3, 3), (4, 10), (4, 3)]} or {'group_ids': [(6, 0, [ids]}
|
||||
@@ -31,7 +30,6 @@ class res_groups_gamification_group(osv.Model):
|
||||
_inherit = 'res.groups'
|
||||
|
||||
def write(self, cr, uid, ids, vals, context=None):
|
||||
print("Overwrite res_groups_gamification_group", ids)
|
||||
write_res = super(res_groups_gamification_group, self).write(cr, uid, ids, vals, context=context)
|
||||
if vals.get('users'):
|
||||
# form: {'group_ids': [(3, 10), (3, 3), (4, 10), (4, 3)]} or {'group_ids': [(6, 0, [ids]}
|
||||
|
||||
@@ -50,6 +50,7 @@
|
||||
<button string="Close Plan" type="object" name="action_close" states="inprogress" class="oe_highlight"/>
|
||||
<button string="Cancel Plan" type="object" name="action_cancel" states="inprogress"/>
|
||||
<button string="Reset Plan" type="object" name="action_reset" states="done"/>
|
||||
<button string="Report Progress" type="object" name="report_progress" states="inprogress,done" groups="base.group_no_one"/>
|
||||
<field name="state" widget="statusbar"/>
|
||||
</header>
|
||||
<sheet>
|
||||
|
||||
Reference in New Issue
Block a user