From 341d9317828c4e54705cd51035e034cfa49aed10 Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Mon, 2 May 2016 16:17:09 +0200 Subject: [PATCH] [FIX] hr_holidays: mail notification on leave request confirm The followers of the departments subscribed to the `Leaves/Allocations Confirmed` are supposed to receive a mail notification when an employee confirms a leave request. It was no longer the case since the below revision: 2be1dfc1ed7c9814cd3dbf4eb4cc95f842f738c2 This revision subscribes the followers of the department following the `confirmed` subtype manually ,on the leave request confirmation, because `message_auto_subscribe` only works on fields for which the value is passed to the `create` or `write` methods, it doesn't work for related/computed fields This can be removed as soon as `department_id` on `hr.holidays` becomes a regular fields or as soon as `message_auto_subscribe` works with related/computed fields. opw-676521 --- addons/hr_holidays/hr_holidays.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/addons/hr_holidays/hr_holidays.py b/addons/hr_holidays/hr_holidays.py index bdce2f9de44..b694b882ca9 100644 --- a/addons/hr_holidays/hr_holidays.py +++ b/addons/hr_holidays/hr_holidays.py @@ -450,6 +450,19 @@ class hr_holidays(osv.osv): return True def holidays_confirm(self, cr, uid, ids, context=None): + for record in self.browse(cr, uid, ids, context=context): + if record.department_id: + # Subscribe the followers of the department following the `confirmed` subtype + # It's done manually because `message_auto_subscribe` only works on fields for which + # the value is passed to the `create` or `write` methods, + # it doesn't work for related/computed fields + # This can be removed as soon as `department_id` on `hr.holidays` becomes a regular + # fields or as soon as `message_auto_subscribe` works with related/computed fields. + confirmed_subtype = self.pool['ir.model.data'].xmlid_to_object(cr, uid, 'hr_holidays.mt_department_holidays_confirmed', context=context) + self.message_subscribe(cr, uid, [record.id], [ + follower.partner_id.id for follower in record.department_id.message_follower_ids + if confirmed_subtype in follower.subtype_ids + ], context=context) return self.write(cr, uid, ids, {'state': 'confirm'}) def holidays_refuse(self, cr, uid, ids, context=None):