Skip to content
Snippets Groups Projects
Commit 18799641 authored by Denis Vermylen (dve)'s avatar Denis Vermylen (dve)
Browse files

[FIX] hr_holidays: add followers to employee leave

from odoo#14848

Those subscribed to the department of the employee didn't get notified when
the employee encoded a leave.

It was due to the department_id not being given as value in create when the
employee made the leave.

This is because there's a group group_hr_holidays_user on that field in the
view, so only when they created a leave the followers would be added correctly
(as department_id was given as value in create).

This commit also remove the useless subscribe_followers method.
parent 347494c0
Branches
Tags
No related merge requests found
......@@ -348,9 +348,9 @@ class Holidays(models.Model):
employee_id = values.get('employee_id', False)
if not self._check_state_access_right(values):
raise AccessError(_('You cannot set a leave request as \'%s\'. Contact a human resource manager.') % values.get('state'))
if not values.get('department_id'):
values.update({'department_id': self.env['hr.employee'].browse(employee_id).department_id.id})
holiday = super(Holidays, self.with_context(mail_create_nolog=True, mail_create_nosubscribe=True)).create(values)
if values.get('state') == 'confirm':
self.subscribe_followers()
holiday.add_follower(employee_id)
return holiday
......@@ -360,8 +360,6 @@ class Holidays(models.Model):
if not self._check_state_access_right(values):
raise AccessError(_('You cannot set a leave request as \'%s\'. Contact a human resource manager.') % values.get('state'))
result = super(Holidays, self).write(values)
if values.get('state') == 'confirm':
self.subscribe_followers()
self.add_follower(employee_id)
return result
......@@ -375,20 +373,6 @@ class Holidays(models.Model):
# Business methods
####################################################
@api.multi
def subscribe_followers(self):
for holiday in self:
if holiday.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.env.ref('hr_holidays.mt_department_holidays_confirmed')
partner_ids = [follower.partner_id.id for follower in holiday.department_id.message_follower_ids if confirmed_subtype in follower.subtype_ids]
holiday.message_subscribe(partner_ids)
@api.multi
def _create_resource_leave(self):
""" This method will create entry in resource calendar leave object at the time of holidays validated """
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment