Automation guidelines in Odoo

AMR ALI HARSHAD
October 22, 2024
odoo-automation

Computerized modifications are caused by automation policies based on user moves (e.g., a change is followed when a field is set to a specific price), email activities, time conditions (e.g., a file is archived 7 days after its last update), or outside events. To create an automation rule with Studio, the following steps should be proceeded with:

  1. Studio should be opened and Automations should be clicked, then New.   
  2. The trigger should be selected and, if important, the fields that appear on the display should be filled in based on the selected cause.   
  3. An action should be added by clicking Add an action, then the type of action should be selected and the fields that appear on the screen should be filled in based on the chosen action.   
  4. Save & Close or Save & New should be clicked. To alter the model of the automation rule, models should be switched before Automations is clicked in Studio, or the developer mode should be activated, an automation rule should be created or edited, and the model should be selected in the Automation policies form.
odoo-automation

Trigger

The trigger is used to define when the automation rule should be applied. The available triggers depend on the model. Five trigger categories are available overall:

    • Values updated

    • Email events

    • Timing conditions

    • Custom

  •     • External

Values updated

The triggers available in this category depend on the model and are based on common field changes, such as a specific tag being added (e.g., to a task) or the User field being set. The trigger should be selected, then a value should be chosen if required.

triggers-in-odoo

Email events

Automated actions are triggered upon receiving or sending emails. Timing conditions

Automated actions are triggered based on a date field. The following triggers are available:

  • Based on the date field: The field to be used next to the Delay field should be selected.   
  • After creation: The action is triggered when a record is created and saved.   
  • After the last update: The action is triggered when an existing record is edited and saved. Then, the following can be defined:
  • A delay: The number of minutes, hours, days, or months should be specified. A negative number should be specified before the trigger date to trigger the action. If the Based on date field trigger is selected, the date field to be used to determine the delay should also be chosen.   
  • Extra conditions: The condition should be added by clicking Add condition, and then the conditions that need to be met to trigger the automation rule should be specified. A new Rule should be clicked to add another condition. The action is triggered when the delay is reached and the conditions are met.
events-in-odoo

Custom

Automated actions are triggered:

    • On save: When the record is saved;

    • On deletion: When a record is deleted;

    • On UI change: When a field’s value is changed on the Form view, even before the record is saved. For the On save and On UI change triggers, the field(s) to be used to trigger the automation rule when updating the field should then be selected. Optionally, additional conditions can also be defined to be met to trigger the automation rule in the Apply on field.

External

Automated actions are triggered based on an external event using a webhook. A webhook is a method of communication between two systems where the source system sends an HTTP(S) request to a destination system based on a specific event. It usually includes a data payload containing information about the event that occurred. To configure the On webhook trigger, the URL generated by Odoo should be copied into the destination system (i.e., the system receiving the request). Then, in the Target Record field, the code to run to define the record(s) to be updated using the automation rule should be entered.

Logging calls can also be chosen to record the payloads received, e.g., to ensure the data sent by the source system matches the expected format and content. This also helps identify and diagnose any issues that may arise. To access the logs, the Logs smart button at the top of the Automation policies form should be clicked.

Actions

Once the trigger of the automation rule has been defined, an action should be added by clicking Add an action to define the action to be executed.

Update record

This action allows one of the record’s (related) fields to be updated. The Update field should be clicked and, in the list that opens, the field to be updated should be selected or searched for; the right arrow next to the field name should be clicked to access the list of related fields if needed. If a many2many field is selected, whether the field must be updated by Adding, Removing, or Setting it to the selected value or by Clearing it should be chosen.

create-actions

Create Activity

This action is used to schedule a new activity linked to the record. An Activity Type should be selected, a Title and description entered, then when the activity should be scheduled in the Due Date In field should be specified, and a User type should be selected:

    • To always assign the activity to the same user, a Specific User should be selected and the user should be added to the Responsible field;

    • To dynamically target a user linked to the record, Dynamic User (based on the record) should be selected and the User Field should be changed if necessary. Send email and send SMS

Send Email and Send SMS

These actions are used to send an email or a text message to a contact linked to a specific record. To do so, an Email Template or an SMS Template should be selected or created, and then, in the Send Email As or Send SMS As field, the method of sending the email or text message should be chosen:

  • Email: The message should be sent as an email to the recipients of the Email Template.   
  • Message: The message should be posted on the record and the record’s followers should be notified.
  • Note: The message should be sent as an internal note visible to internal users in the chatter.  
  • SMS (without note): The message should be sent as a text message to the recipients of the SMS template.   
  • SMS (with note): The message should be sent as a text message to the recipients of the SMS template and should be posted as an internal note in the chatter.   
  • Note only: The message should only be posted as an internal note in the chatter. Add followers and remove followers

These actions are used to (un)subscribe existing contacts to/from the record. Create record

This action is used to create a new record on any model. The required model in the Record to Create field should be selected; it contains the current model by default. A Name for the record should be specified, and then, if the record is to be created on another model, a field in the Link Field field should be selected to link the record that triggered the creation of the new record.

Execute code

This action is used to execute Python code. The code can be written into the Code tab using the following variables:

    • env: The environment in which the action is triggered

    • model: The model of the record on which the action is triggered; it is a void record

    • record: The record on which the action is triggered; it may be void

    • records: The record of all records on which the action is triggered in multi-mode; it may be left empty

    • time, datetime, dateutil, timezone: Useful Python libraries

    • float_compare: A utility function to compare floats based on specific precision

    • log(message, level=’info’): A logging function to record debug information in it. logging table

    • _logger.info(message): A logger to emit messages in server logs

    • UserError: An exception class for raising user-facing warning messages

    • Command: The x2many commands namespace

    • action = {…}: To return an action

Send webhook notification

This action allows a POST request with the values of the Fields to be sent to the URL specified in the URL field. The Sample Payload provides a preview of the data included in the request using a random record’s data or dummy data if no record is available. Execute existing actions

The action is used to trigger multiple actions (linked to the current model) at the same time. To do so, Add a line should be clicked, then, in the Add: Child Actions pop-up, an existing action should be selected or New should be clicked to create a new one.

"Unlock the Full Potential of Your Business with Odoo ERP!"

"Get a Cost Estimate for Your ERP Project, Absolutely FREE!"

Get a Free Quote

Leave a Reply

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