From 1cf4d9173040a3d8726c2acea22e1f4e287041d7 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Tue, 12 Mar 2013 17:15:56 +0100 Subject: [PATCH] [IMP] overwrite message_post to send mail to employee bzr revid: mat@openerp.com-20130312161556-cy1w6lxistdwjeys --- addons/gamification/badge.py | 1 + addons/gamification/badge_view.xml | 5 ++++- addons/hr_gamification/badge.py | 22 +++++++++++++++++++--- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/addons/gamification/badge.py b/addons/gamification/badge.py index cf4da83f79b..9ea8a0b572a 100644 --- a/addons/gamification/badge.py +++ b/addons/gamification/badge.py @@ -193,6 +193,7 @@ class gamification_badge(osv.Model): else: values['user_from'] = False body_html = template_env.get_template('badge_received.mako').render(values) + context['badge_user'] = badge_user res = self.message_post(cr, uid, 0, body=body_html, diff --git a/addons/gamification/badge_view.xml b/addons/gamification/badge_view.xml index 4c583acfb76..9ec13682df1 100644 --- a/addons/gamification/badge_view.xml +++ b/addons/gamification/badge_view.xml @@ -74,7 +74,10 @@ - + + + + diff --git a/addons/hr_gamification/badge.py b/addons/hr_gamification/badge.py index 08a2c5d6238..d1aba7b84f2 100644 --- a/addons/hr_gamification/badge.py +++ b/addons/hr_gamification/badge.py @@ -22,7 +22,7 @@ from openerp.osv import fields, osv -class gamification_badge_user(osv.Model): +class hr_gamification_badge_user(osv.Model): """User having received a badge""" _name = 'gamification.badge.user' @@ -44,7 +44,23 @@ class gamification_badge_user(osv.Model): ] -class grant_badge_wizard(osv.TransientModel): +class hr_gamification_badge(osv.Model): + _name = 'gamification.badge' + _inherit = ['gamification.badge', 'mail.thread'] + + def message_post(self, cr, uid, thread_id, context=None, **kwargs): + """Overwrite the message_post method to send the badge to the employee""" + # badge_user included in the send_badge method and 'badge_id' in the wizard view + if 'badge_user' in context and 'badge_id' in context: + badge = self.browse(cr, uid, context['badge_id'], context=context) + badge_user = context['badge_user'] + if badge.public and badge_user.employee_id: + return self.pool.get('hr.employee').message_post(cr, uid, + badge_user.employee_id.id, context=context, **kwargs) + return super(hr_gamification_badge, self).message_post(cr, uid, thread_id, context=context, **kwargs) + + +class hr_grant_badge_wizard(osv.TransientModel): _name = 'gamification.badge.user.wizard' _inherit = ['gamification.badge.user.wizard'] @@ -82,4 +98,4 @@ class grant_badge_wizard(osv.TransientModel): badge_obj.send_badge(cr, uid, wiz.badge_id.id, [badge_user], user_from=user_from, context=context) return {} -grant_badge_wizard() \ No newline at end of file +hr_grant_badge_wizard()