1. Home
  2. Knowledge Base
  3. Odoo
  4. Conditional e-mail addresses in Odoo v17 e-mail templates

Conditional e-mail addresses in Odoo v17 e-mail templates

How to use conditional email addresses in Odoo v17 email templates

In this article we will show you how to use conditional email addresses in email templates in Odoo v17.
Often you want to make sure that emails are sent to the right address depending on whether a certain field is filled in or not.
In this case, we combine custom fields and standard fields to create a reliable solution.

Step-by-step instructions

1. create the user-defined field Rechnungsemail:

  • Navigate to Odoo Studio by clicking on “Studio” in the main menu.
  • Select the “Partner” or “Contact” model (depending on how it is labeled in your Odoo instance).
  • Click on “Add field” and create a new field of the type “Email”.
  • Name the field Rechnungsemail.
    The technical name of the field is automatically set as x_studio_rechnungsemail.
  • Save and activate the new field.

2. open Odoo and navigate to the e-mail templates:

  • Go to “Settings” and select “Email” or “Technical settings” (depending on your Odoo version and your user rights).
  • Search for “Email templates” and open the template you want to customize.

3. find the field for the e-mail address:

  • In the “Advanced settings” area or directly in the template editor, you will find the email_to field.
    This field determines the address to which the email is sent.

4. use the following code in the field email_to:

{{ object.partner_id.x_studio_rechnungsemail if object.partner_id.x_studio_rechnungsemail != '' else object.partner_id.email }}
  • This code checks whether the user-defined field x_studio_rechnungsemail is not empty.
    If this field is filled in, its value is used.
    If it is empty, the partner’s default field email is used instead.

5. save the changes:

  • Click on “Save” to apply the changes to your email template.

Explanation of the code

object.partner_id.x_studio_rechnungsemail: Here we access the user-defined field x_studio_rechnungsemail of the partner. if object.partner_id.x_studio_rechnungsemail != ''The condition checks whether this field is not empty. else object.partner_id.emailIf the user-defined field is empty, the standard field email of the partner.

Advantages of this method

  • Flexibility: You can use different e-mail addresses based on specific conditions.
  • Fault tolerance: If a user-defined field is empty, an alternative address is automatically used.
  • Easy maintenance: The code is clear and easy to understand, which makes future adjustments easier.

Conclusion

With this simple but effective approach, you can ensure that your emails are always sent to the right address.
Using conditional expressions in Odoo email templates gives you the flexibility you need for efficient communication.
We hope this guide helps you get the most out of your email templates in Odoo v17.
If you have any further questions or comments, please do not hesitate to contact the noprob.it team!


Feel free to publish this article on your blog or forward it to your colleagues.
At noprob.it we always strive to provide you with the best tips and tricks for your Odoo implementation!  

Dieser Beitrag ist auch verfügbar auf: Deutsch (German)

Was this article helpful?

Related Articles

Submit a Comment

Your email address will not be published. Required fields are marked *

Skip to content