Enable Dark Mode!
how-to-add-email-notifications-for-multi-step-approvals-in-odoo-19.jpg
By: Yadu Krishna N P

How to Add Email Notifications for Multi-Step Approvals in Odoo 19

Odoo 19 Technical

Approval workflows are part of business operations that need the validation of requests by relevant users before processing. With Odoo 19, developers can extend approval workflows with custom multi-step approval systems along with automated email notifications.

In this blog, we will learn how to add Email Notifications for Multi-Step Approvals in an Odoo 19 module. This implementation enables us to automatically notify each approver whenever a request moves to the next stage of approval. We are also going to learn about how to add Email Notifications for Multi-Step Approvals in a custom Odoo 19 module. This implementation helps in automatically notifying each approver as a request moves to the next approval stage.

Why Add Email Notifications to Multi-Step Approvals?

In a multi-step approval workflow, requests are typically routed to multiple approvers, such as Team Leaders, Department Managers, Finance Managers, and HR Managers. Without proper notifications, approvers may overlook pending requests, resulting in delays in the approval process. Organisations can use email notifications from a custom approval module to further automate communication, more efficiently track the approval process, and keep approvers updated in real time.

Creating the Custom Approval Model

First, we build a custom model for handling approval requests.

from odoo import api, fields, models
class MultiStepApproval(models.Model):
    _name = 'multi.step.approval'
    _description = 'Multi Step Approval'
    name = fields.Char(string='Reference')
    state = fields.Selection([
        ('draft', 'Draft'),
        ('manager', 'Manager Approval'),
        ('finance', 'Finance Approval'),
        ('approved', 'Approved'),
        ('rejected', 'Rejected')
    ], default='draft')
    manager_id = fields.Many2one(
        'res.users',
        string='Manager'
    )
    finance_manager_id = fields.Many2one(
        'res.users',
        string='Finance Manager'
    )

This model defines multiple approval stages for the workflow.

Adding Approval Actions

Next, we create methods to change or move the request from one approval stage to another.

def action_manager_approve(self):
    self.state = 'finance'
    self.send_approval_email(
        self.finance_manager_id.partner_id.email
    )
def action_finance_approve(self):
    self.state = 'approved'

When the manager approves the request, the workflow proceeds to the finance stage and sends an email notification to the finance manager.

Sending Email Notifications

To automate emails, we create a reusable function to send emails within the model.

def send_approval_email(self, email_to):
    template = self.env.ref(
        'your_module.email_template_multi_step_approval'
    )
    if template:
        template.send_mail(
            self.id,
            force_send=True,
            email_values={'email_to': email_to}
        )

This approach selects the email template and sends the notification to the next approver.

Creating the Email Template

This way, we can create an XML file for the email template.

<odoo>
    <record id="email_template_multi_step_approval"
            model="mail.template">
        <field name="name">
            Multi Step Approval Notification
        </field>
        <field name="model_id"
               ref="model_multi_step_approval"/>
        <field name="subject">
            Approval Request Pending
        </field>
        <field name="email_from">
            ${user.email}
        </field>
        <field name="body_html" type="html">
            <![CDATA[
            <p>Hello,</p>
            <p>
                A new approval request requires your attention.
            </p>
            <p>
                <strong>Reference:</strong>
                ${object.name}
            </p>
            <p>
                Please review the request in Odoo.
            </p>
            ]]>
        </field>
    </record>
</odoo>

This template generates automatic approval emails from the record values.

Adding Security Access

Also need to create an access control CSV file so that we can provide permissions for the custom approval model.

id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_multi_step_approval,multi.step.approval,model_multi_step_approval,base.group_user,1,1,1,1

Adding the XML File to the Manifest

Lastly, we update the module manifest

'data': [
'security/ir.model.access.csv',
'data/email_template.xml',
'views/multi_step_approval_views.xml',
]

Workflow Execution

Once the module is installed in our Odoo 19 environment, we can create a new approval request and submit it to the manager for approval. Once the manager approves the request, it will be automatically sent for approval from the finance manager. The finance manager will receive an email notification. When the finance manager approves the request, the request is marked as approved, and the approval process is complete. This is how a fully automated multi-step approval workflow with email notifications works.

By adding email notifications to a custom multi-step approval module in Odoo 19, organisations can successfully automate their approval workflows. This integration enables businesses to combine approval stages with automated email notifications, ensuring that each approver receives timely notifications, which reduces delays that can negatively impact productivity. Odoo's flexible framework allows developers to customize approval workflows and notification systems according to specific business requirements, thus making the approval process more organised and efficient.

To read more about How to Manage Reception of Chat Notification to the Inbox with Odoo 18, refer to our blog How to Manage Reception of Chat Notification to the Inbox with Odoo 18.


Frequently Asked Questions

What are the uses of email notifications in multi-step approval?

Notifications ensure the next approver user is notified when the request reaches their approval stage. It reduces the delays caused by missed requests. It helps keep the process without manual follow-ups.

Can we add this email notification feature in existing approval modules?

If you already have a custom approval flow, you can add this by creating an email template and triggering it from your approval methods.

Can emails be sent automatically without user intervention?

Yes. Once approval actions are configured, odoo automatically sends an email whenever a request reaches the next approver's approval stage.

If you need any assistance in odoo, we are online, please chat with us.



0
Comments



Leave a comment



WhatsApp