diff --git a/addons/gamification/__init__.py b/addons/gamification/__init__.py index a406bf3a621..540d22424d0 100644 --- a/addons/gamification/__init__.py +++ b/addons/gamification/__init__.py @@ -1,2 +1,3 @@ import goal -import res_users \ No newline at end of file +import res_users +import report diff --git a/addons/gamification/goal.py b/addons/gamification/goal.py index b01553ab768..ba9f665188c 100644 --- a/addons/gamification/goal.py +++ b/addons/gamification/goal.py @@ -2,26 +2,28 @@ ############################################################################## # # OpenERP, Open Source Management Solution -# Copyright (C) 2004-2013 Tiny SPRL (). +# Copyright (C) 2010-Today OpenERP SA () # # 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 . +# You should have received a copy of the GNU General Public License +# along with this program. If not, see # ############################################################################## 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' + } \ No newline at end of file diff --git a/addons/gamification/report/report_progress.xml b/addons/gamification/report/report_progress.xml index 67d7e564098..b8a2c3b22db 100644 --- a/addons/gamification/report/report_progress.xml +++ b/addons/gamification/report/report_progress.xml @@ -8,30 +8,23 @@ form form,tree - - - - - + - + Individual Report - Send by Email noreply@localhost - ${object.title} - ${object.partner_id.id} - + Individual report - ${object.name} + ${object.report_message_group_id.alias_id.name_get()[0][1]} + - Individual_Report_${(object.number or '').replace('/','_')}_${object.state == 'draft' and 'draft' or ''} +
+

Individual report - ${object.name}

-

${report.title}

- -

Hello ${report.user}, bellow are your latest results for the plan ${report.plan_name}.

+

Hello ${ctx['user'].name}, bellow are your latest results for the plan ${object.name}.

@@ -40,7 +33,7 @@ - % for goal in report: + % for goal in ctx['goals']: diff --git a/addons/gamification/res_users.py b/addons/gamification/res_users.py index f2f54d9b324..38d4950b185 100644 --- a/addons/gamification/res_users.py +++ b/addons/gamification/res_users.py @@ -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]} diff --git a/addons/gamification/view/plan.xml b/addons/gamification/view/plan.xml index 66af613c2fd..f4b3313c76e 100644 --- a/addons/gamification/view/plan.xml +++ b/addons/gamification/view/plan.xml @@ -50,6 +50,7 @@
Current Completeness
${goal.type_id.name} ${goal.target_goal}