From 9e1df28731a22fca948ad99f524abc28a1d48240 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Thu, 28 Feb 2013 10:22:47 +0100 Subject: [PATCH] [FIX] gamification: send messages correctly bzr revid: mat@openerp.com-20130228092247-v5jv7xt0mlsav4jx --- addons/gamification/goal.py | 35 +++++++++++++------ .../templates/group_progress.mako | 18 ++++++---- addons/gamification/view/goal.xml | 2 +- addons/gamification/view/plan.xml | 4 +++ 4 files changed, 40 insertions(+), 19 deletions(-) diff --git a/addons/gamification/goal.py b/addons/gamification/goal.py index d19b5cb5371..b2ef4b71df1 100644 --- a/addons/gamification/goal.py +++ b/addons/gamification/goal.py @@ -324,7 +324,11 @@ class gamification_goal(osv.Model): """Overwrite the write method to update the last_update field to today""" for goal in self.browse(cr, uid, ids, vals): # TODO if current in vals - vals['last_update'] = fields.date.today() + if 'current' in vals: + vals['last_update'] = fields.date.today() + if goal.report_message_frequency == 'onchange': + plan_obj = self.pool.get('gamification.goal.plan') + plan_obj.report_progress(cr, uid, [goal.planline_id.plan_id.id], users=[goal.user_id], context=context) write_res = super(gamification_goal, self).write(cr, uid, ids, vals, context=context) return write_res @@ -342,6 +346,7 @@ class gamification_goal_plan(osv.Model): _name = 'gamification.goal.plan' _description = 'Gamification goal plan' + _inherit = 'mail.thread' _columns = { 'name' : fields.char('Plan Name', required=True), @@ -583,9 +588,10 @@ class gamification_goal_plan(osv.Model): return True - def report_progress(self, cr, uid, ids, context=None): + def report_progress(self, cr, uid, ids, users=False, context=None): """Post report about the progress of the goals""" + context = context or {} goal_obj = self.pool.get('gamification.goal') for plan in self.browse(cr, uid, ids, context=context): @@ -593,8 +599,6 @@ class gamification_goal_plan(osv.Model): # no report group, skipping continue - # copy of context to access more variables in templates - template_context = dict(context) if plan.visibility_mode == 'board': # generate a shared report planlines_boards = [] @@ -625,12 +629,16 @@ class gamification_goal_plan(osv.Model): planlines_boards.append({'goal_type':planline.type_id.name, 'board_goals':sorted_board}) body_html = mako_template_env.get_template('group_progress.mako').render({'object':plan, 'planlines_boards':planlines_boards}) - self.pool.get('mail.thread').message_post(cr, uid, False, + self.message_post(cr, uid, plan.id, body=body_html, partner_ids=[user.partner_id.id for user in plan.user_ids], - context=context) - #self.pool.get('email.template').send_mail(cr, uid, template_id, plan.id, context=template_context) - + context=context, + subtype='mail.mt_comment') + self.pool.get('mail.group').message_post(cr, uid, plan.report_message_group_id.id, + body=body_html, + context=context, + subtype='mail.mt_comment') + else: # generate individual reports for user in plan.user_ids: @@ -645,11 +653,16 @@ class gamification_goal_plan(osv.Model): 'goals':goal_obj.browse(cr, uid, goal_ids, context=context) } body_html = mako_template_env.get_template('personal_progress.mako').render(variables) - self.pool.get('mail.thread').message_post(cr, uid, False, + + self.message_post(cr, uid, plan.id, body=body_html, partner_ids=[user.partner_id.id], - context=context) - #self.pool.get('email.template').send_mail(cr, uid, template_id, plan.id, context=template_context) + context=context, + subtype='mail.mt_comment') + self.pool.get('mail.group').message_post(cr, uid, plan.report_message_group_id.id, + body=body_html, + context=context, + subtype='mail.mt_comment') return True diff --git a/addons/gamification/templates/group_progress.mako b/addons/gamification/templates/group_progress.mako index b0b6e7d6243..a815b711114 100644 --- a/addons/gamification/templates/group_progress.mako +++ b/addons/gamification/templates/group_progress.mako @@ -5,16 +5,17 @@
- % if object.report_header - ${object.report_header} - % endif + ${object.name}
- - Below are the latest results for the plan ${object.name} for the group ${object.report_message_group_id.name}.

- !${planlines_boards}! + +

${object.report_header or ''}

+ % for planline in planlines_boards: -

${planline['goal_type']}

+ + + + @@ -34,5 +35,8 @@ % endfor
${planline['goal_type']}
# User
+ +

+ % endfor \ No newline at end of file diff --git a/addons/gamification/view/goal.xml b/addons/gamification/view/goal.xml index c497270eff0..80cced0590e 100644 --- a/addons/gamification/view/goal.xml +++ b/addons/gamification/view/goal.xml @@ -78,7 +78,7 @@
- +
diff --git a/addons/gamification/view/plan.xml b/addons/gamification/view/plan.xml index fbf4dc4a3e3..2c9efc5342f 100644 --- a/addons/gamification/view/plan.xml +++ b/addons/gamification/view/plan.xml @@ -138,6 +138,10 @@ +
+ + +