I have a new module called new_leaves as I made some changes in hr.holidays module
I have to approves one for the manager of the department and the other for leaves manager( I created a new user and I set his sittings as manager of leaves and an officer in employee category) , I want that the leaves manager receives a notification after manager approve for an employee leave I updated this function in my new module but it does not work , any help?
class new_leaves(models.Model):
_inherit = 'hr.holidays'
state = fields.Selection([
('draft', 'To Submit'),
('cancel', 'Cancelled'),
('confirm', 'To Approve'),
('manager', 'Manager Approve'),
('hr_approve','HR Approve'),
('refuse', 'Refused'),
('validate1', 'Second Approval'),
('validate', 'Approved')
], string='Status', readonly=True, track_visibility='onchange', copy=False, default='confirm',
help="The status is set to 'To Submit', when a holiday request is created." +
"\nThe status is 'To Approve', when holiday request is confirmed by user." +
"\nThe status is 'Refused', when holiday request is refused by manager." +
"\nThe status is 'Approved', when holiday request is approved by manager.")
@api.multi
def _notification_recipients(self, message, groups):
""" Handle HR users and officers recipients that can validate or refuse holidays
directly from email. """
groups = super(new_leaves, self)._notification_recipients(message, groups)
self.ensure_one()
hr_actions = []
if self.state == 'manager':
app_action = self._notification_link_helper('controller', controller='/new_leaves/hr_approve')
hr_actions += [{'url': app_action, 'title': _('Approve')}]
if self.state in ['confirm', 'validate', 'validate1','manager','hr_approve']:
ref_action = self._notification_link_helper('controller', controller='/new_leaves/refuse')
hr_actions += [{'url': ref_action, 'title': _('Refuse')}]
new_group = (
'group_hr_holidays_manager', lambda partner: bool(partner.user_ids) and any(user.has_group('hr_holidays.group_hr_holidays_manager') for user in partner.user_ids), {
'actions': hr_actions,
})
return [new_group] + groups
and in controller file :
from odoo.addons.mail.controllers.main import MailController
from odoo import http
class Ra(http.Controller):
@http.route('/new_leaves/manager', type='http', auth='user', methods=['GET'])
def hr_holidays_validate(self, res_id, token):
comparison, record, redirect = MailController._check_token_and_record_or_redirect('hr.holidays', int(res_id), token)
if comparison and record:
try:
record.action_approve()
except Exception:
return MailController._redirect_to_messaging()
return redirect
@http.route('/new_leaves/refuse', type='http', auth='user', methods=['GET'])
def hr_holidays_refuse(self, res_id, token):
comparison, record, redirect = MailController._check_token_and_record_or_redirect('hr.holidays', int(res_id), token)
if comparison and record:
try:
record.action_refuse()
except Exception:
return MailController._redirect_to_messaging()
return redirect