[IMP] create new method to broadcast message to employess in hr.

bzr revid: tpa@tinyerp.com-20140212111238-3b3ddlwl3062fjef
This commit is contained in:
Turkesh Patel (Open ERP) 2014-02-12 16:42:38 +05:30
parent 6d17db2101
commit 49351f6edb
1 changed files with 24 additions and 20 deletions

View File

@ -248,30 +248,34 @@ class hr_employee(osv.osv):
'color': 0,
}
def mail_broadcast(self, cr, uid, employee_id, context=None):
employee = self.browse(cr, uid, employee_id, context=context)
partner_ids = []
if employee.user_id:
res_users = self.pool['res.users']
# send a copy to every user of the company
# TODO: post to the `Whole Company` mail.group when we'll be able to link to the employee record
_model, group_id = self.pool['ir.model.data'].get_object_reference(cr, uid, 'base', 'group_user')
user_ids = res_users.search(cr, uid, [('company_id', '=', employee.user_id.company_id.id),
('groups_id', 'in', group_id)], context=context)
partner_ids = list(set(u.partner_id.id for u in res_users.browse(cr, uid, user_ids, context=context)))
self.message_post(cr, uid, [employee_id],
body=_('Welcome to %s! Please help him/her take the first steps with OpenERP!') % (employee.name),
partner_ids=partner_ids,
subtype='mail.mt_comment', context=context
)
return True
def create(self, cr, uid, data, context=None):
if context is None:
context = {}
if context.get("mail_broadcast"):
create_ctx = dict(context, mail_create_nolog=True)
employee_id = super(hr_employee, self).create(cr, uid, data, context=create_ctx)
employee = self.browse(cr, uid, employee_id, context=context)
if employee.user_id:
res_users = self.pool['res.users']
# send a copy to every user of the company
# TODO: post to the `Whole Company` mail.group when we'll be able to link to the employee record
_model, group_id = self.pool['ir.model.data'].get_object_reference(cr, uid, 'base', 'group_user')
user_ids = res_users.search(cr, uid, [('company_id', '=', employee.user_id.company_id.id),
('groups_id', 'in', group_id)], context=context)
partner_ids = list(set(u.partner_id.id for u in res_users.browse(cr, uid, user_ids, context=context)))
else:
partner_ids = []
self.message_post(cr, uid, [employee_id],
body=_('Welcome to %s! Please help him/her take the first steps with OpenERP!') % (employee.name),
partner_ids=partner_ids,
subtype='mail.mt_comment', context=context
)
else:
employee_id = super(hr_employee, self).create(cr, uid, data, context=context)
context.update({'mail_create_nolog': True})
employee_id = super(hr_employee, self).create(cr, uid, data, context=context)
if context.get("mail_broadcast"):
self.mail_broadcast(cr, uid, employee_id, context=context)
return employee_id
def unlink(self, cr, uid, ids, context=None):