This question has been flagged
1 Reply
3522 Views

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

Avatar
Discard
Best Answer

Hi marwa,

in case your question is still not answered, I extended hr.leave (not hr.holidays) like that:


from odoo import models, fields, api


class HRLeave(models.Model):

     _inherit = "hr.leave"

     @api.multi

     def action_approve(self):

          self.ensure_one()

          result = super(HRLeave, self).action_approve()

          self.env['mail.template'].browse(23).send_mail(self.id)

          return result


I also created a mail template with the email address of the hr officer in the "TO: " field. This template, in my case, is referenced in the database by id "23".

What's still necessary ist to make your module depend on "hr" in the __manifest.py__:

'depends': ['base','hr'],




Best regards


Thomas

Avatar
Discard