Design engaging Commission Email Templates with Odoo

Design engaging Commission Email Templates with Odoo

Writing good emails is vital to maintain professionalism, but you would not want to write the same structure of email again and, would you?

That is where email templates come in handy. Eliminating the need to write the entire email structure every time, you can save time focusing on the actual content of the email. Email templates also protect your brand reputation by keeping your emails on-brand and error-free.

If you were to rewrite emails from scratch every time, there’s a good chance that there would be variations or mistakes leading to broken emails and a bad experience for your customers. Typos can happen to even the best of us and, in the unforgiving email landscape, can lead to disastrous results.

In this blog, we will create an email template for commissions in Odoo 14, using XML, Jinja2, and Python.

Why Odoo?

Odoo is a platform that offers you all the basic tools and functions required to easily manage the resources, such as materials and warehouse management, human resources, accounting, sales, and finance. Odoo is a platform that is modifying itself along with the updated technologies.

We know Odoo ERP Development Services is a functional giant with immense possibilities for customizations. Even the latest version, Odoo 14 doesn’t disappoint the users as it comes with many options for everyone’s needs. 

[Also read: How to Transfer Files Securely and Quickly with SCP]

Have a Project Idea?

Want to convert your idea into a successful app or website? Schedule your free call with our expert now.

We are going to build a template that includes all the necessary information needed for a commission email that fetches data dynamically so that you don’t have to perform redundant tasks.

Step 1:

Firstly, we must ensure that we have ‘Developer Mode’ Switched on in your Odoo Dashboard.

Let’s see the requirements you’ll need to create your template in Odoo. First and foremost, you will need to add a dependency on the other modules, that is

‘depends’:[‘sales’, ‘crm’]

This means that to create this template, you will need access to the ‘sales’ and ‘crm’ modules beforehand. The data needed to fill the template will be fetched from these modules. 
If you are looking for the right Odoo Migration Company to take your business to the next-level, contact Brainvire today.

Step 2:

After we have set the dependencies, we have to create the email template now. In Odoo, the email templates are built-in XML, and as you send the email to some, Jinja2 would autofill your email with the corresponding data.

To create a template, we will need the following:

  1. record_id: this is the unique external ID for each record. With this field, we can identify the records in our ERP system.
  2. model: Every email template model will be the same because the Odoo platform has default email functions. 
  3. name: Name field is used for identification. This will be the name of the template we are creating.
  4. model_id: This field will tell your e-mail template on which model it will be used and where it should get data from. 
  5. email_from: this is the email ID of the sender. This will be the address from which the email is to be sent.
  6. email_to: this is the email ID of the receiver. This will be the address to which the email will be sent.
  7. subject: This is the subject of the email. You can put the Sales Invoice Number along with additional text here.
  8. body_html: This is the content of the email. You have to write HTML Code here, along with the content you want to include in your template.

With all of these fields, we are good to go! Now, let’s structure our XML Code.

As we are creating an email template, we should use the noupdate=”1” tag. Because, if you don’t use it the email template would be overridden every time that you update the module, which would result in losing data if you’ve changed something. Your XML file should now look like this:

 As you can see, we have enveloped our code under the <odoo> tag, and we are setting the record_id, to identify our template. Then, we have assigned all the values to the field tags accordingly, hence making our XML for the template.

Odoo Email templates come with Jinja2 by default. This means that you can access any value from a record with a $ (dollar sign) and will be filled into the email dynamically.

Another thing to be noted is that the code written under the body_html tag will be visible in our email. All the other fields act as metadata for our template. So we have used standard HTML5 tags, like division, paragraph, heading, break tags, to style our email. You can add even more HTML elements to make your email look more appealing.

Step 3:

Next, we will write a Python Script to send the email automatically. Here, we have created a function ‘action_send_commission_email’ with error handling.

Here, we have set the default template ID to our commission.details. In this way, our script knows to use the above XML Template we have created. Here, we have handled errors using try-catch.

After a successful compilation of our script, the receiver will receive the email just like this

The values have been fetched dynamically from our Odoo ERP. You can also customize this template as per your need by adding different fields to the html_body, giving a professional touch to your emails.

[Also read: How Odoo Helps Businesses Attract Customers through Discounts]


Creating email templates in Odoo is quite easy and only requires you to write some XML. You can also use if/else statements, content parsing, and lots of dynamic content, thanks to Jinja2. It is best practice to test your email templates in detail before placing them in production.

Thus, Odoo 14 has eliminated our need to repeat the mundane task of structuring an email every time we have to send a commission invoice. Now, instead of typing out similarly structured emails from scratch, you could automate sending emails efficiently. And, with the reduced effort, you have more time to focus on crafting better content and also eliminates errors.

How useful was this post?

Click on a star to rate it!

Average rating 4.9 / 5. Vote count: 455

No votes so far! Be the first to rate this post.