From 21c550cdc499eb6d5114a250c6e9d44faf4803f0 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Wed, 6 Mar 2013 16:59:53 +0100 Subject: [PATCH] [ADD] send messages to followers as employee and not res.users bzr revid: mat@openerp.com-20130306155953-q08xnkjogm80ie7g --- addons/hr/__openerp__.py | 1 + addons/hr/hr.py | 19 +++++++++++++++++++ addons/hr/mail_hr_view.xml | 3 ++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/addons/hr/__openerp__.py b/addons/hr/__openerp__.py index b4b8e982845..b978a83e658 100644 --- a/addons/hr/__openerp__.py +++ b/addons/hr/__openerp__.py @@ -59,6 +59,7 @@ You can manage: 'hr_installer.xml', 'hr_data.xml', 'res_config_view.xml', + 'mail_hr_view.xml', ], 'demo': ['hr_demo.xml'], 'test': [ diff --git a/addons/hr/hr.py b/addons/hr/hr.py index 665af732d22..d5e7f010bf8 100644 --- a/addons/hr/hr.py +++ b/addons/hr/hr.py @@ -276,6 +276,25 @@ class hr_employee(osv.osv): return self.message_unsubscribe_users(cr, uid, ids, context=context) + def message_post_user_api(self, cr, uid, thread_id, context=None, **kwargs): + """Overwrite the message_post method when using the send to my followers screen + + The context should be extended with sent_from_action_mail_inbox_feeds + and default_res_id contains the id of the user linked to the employee + that will be linked the message (done from the action_mail_inbox_feeds + view)""" + + print("message_post_user_api", uid, thread_id, context) + if 'sent_from_action_mail_inbox_feeds' in context and 'default_res_id' in context: + employee_ids = self.search(cr, uid, [('user_id','=',context['default_res_id'])], context=context) + if len(employee_ids) > 0: + for employee_id in employee_ids: + res = super(hr_employee, self).message_post_user_api(cr, uid, employee_id, context=context, **kwargs) + return res + + # if no overwrite or no linked employee, send message as usual + return super(hr_employee, self).message_post_user_api(cr, uid, thread_id, context=context, **kwargs) + _defaults = { 'active': 1, 'image': _get_default_image, diff --git a/addons/hr/mail_hr_view.xml b/addons/hr/mail_hr_view.xml index 79b753ec62f..d49b2b0c891 100644 --- a/addons/hr/mail_hr_view.xml +++ b/addons/hr/mail_hr_view.xml @@ -4,8 +4,9 @@ { - 'default_model': 'res.users', + 'default_model': 'hr.employee', 'default_res_id': uid, + 'sent_from_action_mail_inbox_feeds': True, }