From 05179389bf78badad26ca5198e81f0f8c708eb53 Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Wed, 17 Feb 2016 12:04:05 +0100 Subject: [PATCH] =?UTF-8?q?[FIX]=C2=A0hr=5Fhollidays:=20message=5Ffollower?= =?UTF-8?q?=5Fids?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When an "hr.holliday" record is created or modified, the employee_id linked to this record has to be added in the followers. Inspired from ff1d384 opw:668515 --- addons/hr_holidays/hr_holidays.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/addons/hr_holidays/hr_holidays.py b/addons/hr_holidays/hr_holidays.py index 52ea1849196..b8ffde58371 100644 --- a/addons/hr_holidays/hr_holidays.py +++ b/addons/hr_holidays/hr_holidays.py @@ -321,19 +321,30 @@ class hr_holidays(osv.osv): return result + def add_follower(self, cr, uid, ids, employee_id, context=None): + employee = self.pool['hr.employee'].browse(cr, uid, employee_id, context=context) + if employee.user_id: + self.message_subscribe(cr, uid, ids, [employee.user_id.partner_id.id], context=context) + def create(self, cr, uid, values, context=None): """ Override to avoid automatic logging of creation """ if context is None: context = {} + employee_id = values.get('employee_id', False) context = dict(context, mail_create_nolog=True, mail_create_nosubscribe=True) if values.get('state') and values['state'] not in ['draft', 'confirm', 'cancel'] and not self.pool['res.users'].has_group(cr, uid, 'base.group_hr_user'): raise osv.except_osv(_('Warning!'), _('You cannot set a leave request as \'%s\'. Contact a human resource manager.') % values.get('state')) - return super(hr_holidays, self).create(cr, uid, values, context=context) + hr_holiday_id = super(hr_holidays, self).create(cr, uid, values, context=context) + self.add_follower(cr, uid, [hr_holiday_id], employee_id, context=context) + return hr_holiday_id def write(self, cr, uid, ids, vals, context=None): + employee_id = vals.get('employee_id', False) if vals.get('state') and vals['state'] not in ['draft', 'confirm', 'cancel'] and not self.pool['res.users'].has_group(cr, uid, 'base.group_hr_user'): raise osv.except_osv(_('Warning!'), _('You cannot set a leave request as \'%s\'. Contact a human resource manager.') % vals.get('state')) - return super(hr_holidays, self).write(cr, uid, ids, vals, context=context) + hr_holiday_id = super(hr_holidays, self).write(cr, uid, ids, vals, context=context) + self.add_follower(cr, uid, ids, employee_id, context=context) + return hr_holiday_id def holidays_reset(self, cr, uid, ids, context=None): self.write(cr, uid, ids, {