Skip to Content
मेन्यू
This question has been flagged
1 Reply
106 Views

Hello, 
In Odoo 12 CE, I am trying to do the following 
for HR department I set two approvals after the first approval from the direct manager the leave request not assigned to the leave manager and email not sent 
I need this process done automatically without manual reassigned.

I have tried many ways but not works with me  

Avatar
Discard
Best Answer

Hi,

You can override the method that validates the first approval (action_approve) in the hr_holidays model and add logic to:

Reassign the request to the HR manager,

Send an email notification automatically.


Code:

from odoo import api, models


class HrLeave(models.Model):

    _inherit = 'hr.leave'


    @api.multi

    def action_approve(self):

        res = super(HrLeave, self).action_approve()


        for leave in self:

            # Check if double validation is needed

            if leave.holiday_status_id.validation_type == 'both':

                # Automatically reassign to HR Manager group

                hr_group = self.env.ref('hr_holidays.group_hr_holidays_manager')

                hr_manager_users = hr_group.users

                if hr_manager_users:

                    leave.write({'manager_id': hr_manager_users[0].id})


                    # Send email notification

                    template = self.env.ref('hr_holidays.mail_template_leave_approval_manager', raise_if_not_found=False)

                    if template:

                        self.env['mail.template'].browse(template.id).send_mail(leave.id, force_send=True)


        return res


Hope it helps

Avatar
Discard
Related Posts Replies Views Activity
3
सित॰ 25
385
1
अग॰ 25
529
1
जुल॰ 25
870
1
जुल॰ 25
1100
2
मई 25
1764