Regole di automazione

Le regole di automazione permettono di eseguire una o più azioni predefinite in risposta a uno specifico trigger, ad esempio creare un’attività quando un campo viene impostato su un valore specifico o archiviare un record 7 giorni dopo il suo ultimo aggiornamento.

When creating an automation rule, it is possible to add conditions that must be met for the automation rule to run, e.g., the opportunity must be assigned to a specific salesperson, or the state of the record must not be Draft.

To create an automation rule with Odoo Studio:

  1. apri Studio e fai clic su Automazioni e poi Nuova.

  2. assegna alla regola di automazione un nome chiaro e significativo che ne identifichi lo scopo

  3. Select the Trigger and, if necessary, fill in the fields that appear on the screen based on the chosen trigger.

  4. Click Add an action in the Actions To Do tab.

  5. Select the Type of action and complete the relevant fields based on the chosen action.

  6. Click Save & Close or, to define additional actions, Save & New.

Example

Per garantire il follow-up dei clienti meno soddisfatti, questa regola di automazione crea un’attività 3 mesi dopo la creazione di un ordine di vendita per i clienti con una percentuale di soddisfazione inferiore al 30%.

Esempio di regola di automazione sul modello di abbonamento

Suggerimento

  • Utilizza la scheda Note per descrivere lo scopo e il funzionamento delle regole di automazione così da rendere la manutenzione più semplice e facilitare la collaborazione tra utenti.

  • Per modificare il modello oggetto della regola di automazione, cambia modello prima di fare clic su Automazioni in Studio, oppure attiva la modalità sviluppatore, crea o modifica una regola di automazione e seleziona il Modello nel modulo Regole di automazione.

  • Le regole di automazione possono essere create da qualsiasi fase kanban facendo clic sull’icona (Impostazioni) che appare quando si passa con il mouse sul nome della fase kanban per poi selezionare Automazioni. In questo caso, il trigger è impostato su Fase impostata su per impostazione predefinita ma può essere modificato se necessario.

    Creare automazioni da una fase kanban

Trigger

Il trigger viene utilizzato per stabilire cosa deve accadere per far sì che venga eseguita la regola di automazione. I trigger disponibili dipendono dal modello. Nel complesso, sono disponibili cinque categorie di trigger:

Aggiungere condizioni

I filtri di dominio consentono di determinare i record che una regola di automazione deve includere o escludere. Un filtraggio efficiente migliora le prestazioni complessive, poiché evita l’elaborazione superflua dei record che non sono interessati dalla regola.

Suggerimento

Attiva la modalità sviluppatore prima di creare una regola di automazione per avere la massima flessibilità durante l’aggiunta di filtri di dominio.

A seconda del trigger scelto, è possibile definire una o più condizioni che un record deve soddisfare prima e/o dopo che si verifica un trigger.

  • The Before Update Domain defines the conditions a record must meet before the trigger event occurs, e.g., the record must have Type = Customer Invoice and Status = Posted.

    With developer mode activated, click Edit Domain, if available, then New Rule.

  • The Apply on domain defines the conditions a record must meet after the trigger event occurs, e.g., the customer invoice must have Payment Status = Partially Paid.

    With developer mode activated, click Edit Domain then New Rule.

    Suggerimento

    If developer mode is not activated, to define an Apply on domain, click Add condition. Complete or delete the suggested condition. To add a condition, click New Rule.

When a trigger occurs, e.g., the payment status of a posted customer invoice is updated, the automation rule checks the defined conditions and only executes the action if the record matches those conditions.

Example

If the automated action should be executed when an email address is set for the first time (in contrast to modifying an email address) on an existing contact that is an individual rather than a company, use Email is not set and Is a Company is not set as the Before Update Domain and Email is set as the Apply on domain.

Esempio di un trigger con Dominio prima dell'aggiornamento

Nota

The Before Update Domain is not checked upon the creation of a record.

Valori aggiornati

Trigger automated actions when specific changes happen in the database. The triggers available in this category depend on the model and are based on common changes, such as adding a specific tag (e.g., to a task) or setting a field’s value (e.g., setting the User field).

Select the trigger, then select a value if required.

E-mail eventi

Attiva azioni automatizzate dopo aver ricevuto o inviato e-mail.

Condizioni di tempo

Trigger automated actions at a point in time relative to a date field or to the creation or update of a record. The following triggers are available:

  • Based on date field: The action is triggered a defined period of time before or after the date of the selected date field, e.g., 30 days before the contract end date.

  • After creation: The action is triggered a defined period of time after a record is created and saved.

  • After last update: The action is triggered a defined period of time after an existing record is edited and saved.

To configure a Timing Conditions trigger, with developer mode activated:

  1. Select the appropriate Trigger from the Timing Conditions category. If you select the Based on date field trigger, select the relevant date field.

  2. Configure the Delay to determine the execution date time of the action(s). To do so, enter the number of Minutes, Hours, Days, or Months after which the action should be triggered. If you selected the Based on date field trigger, the action can be triggered After or Before the selected date field.

  3. Optionally, add conditions that the record must meet before and/or after the rule is triggered.

  4. Click Save manually.

  5. Click Scheduled action to open the Automation Rules: check and execute scheduled action.

    Nota

    This scheduled action checks for execution date times that have been reached since its previous run, and executes the related action(s), if relevant. By default, the scheduled action is set to Execute Every 4 hours, which is generally sufficient for delays such as 3 months after the order date or 7 days after the last update.

    If any automation rule has a time-based trigger with a delay of less than the equivalent of 40 hours, e.g., 3 hours before the event start date time, the frequency of the scheduled action is automatically increased, e.g., to Execute Every 18 minutes. This allows the action to be executed closer to its scheduled execution date time.

  6. Click Run manually at the top left.

    Avvertimento

    This step is critical to prevent the rule from running retroactively on historical records. Running the scheduled action manually initializes the timestamp of its last run in the automation rule, which is a key element of the rule’s execution logic.

  7. Click the automation rule name in the breadcrumbs to return to the automation rule setup.

  8. Add the action(s) to be executed then, when all actions have been defined, click Save manually.

The action is executed the first time the Automation Rules: check and execute scheduled action runs after the execution date time is reached, and when the conditions are met.

Execution logic

When using a time-based trigger, an action is only executed when the execution date time falls between the last run of the scheduled action and the current run (whether scheduled or run manually), i.e.:

last run –> execution date and time –> current run

Nota

Running the Automation Rules: check and execute scheduled action manually does not necessarily result in a rule’s action being executed. When testing an automation rule with a time-based trigger, ensure that this sequence is true, then check if the action has been executed.

Example

On the morning of October 15, you create an automation rule that triggers the sending of an email 30 days before the Contract end date; contracts end at 11:59 pm on their contract end date. During the creating of the rule, the Automation Rules: check and execute scheduled action was run manually at 11:00 am and is set to run every four hours thereafter.

This new automation rule will apply for contracts whose end date is at least 30 days after the creation of the rule, i.e., an end date of November 14 or later.

For a contract with an end date of November 14, the execution date time of the action is 11:59 pm on October 15. The action will therefore be executed the first time the Automation Rules: check and execute scheduled action runs after that date and time has passed, i.e.,:

  • last run of the scheduled action: 11:00 pm on October 15

  • execution date time: 11:59 pm on October 15

  • current run of the scheduled action: 3:00 am on October 16

Personalizzata

Trigger azioni automatizzate:

  • On create: when a record is saved for the first time.

  • On create and edit: when a record is saved for the first time and any subsequent time.

  • 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 create and edit and On UI change triggers, you must then select the field(s) to be used to trigger the automation rule in the When updating field.

Avvertimento

Se non viene selezionata nessuna opzione per il campo Quando si aggiorna, l’azione automatizzata potrebbe essere eseguita più volte per record.

In alternativa, puoi anche indicare condizioni aggiuntive da rispettare per attivare la regola di automazione nel campo Applicato a.

Nota

The On UI change trigger can only be used with the Execute Code action and only works when a modification is made manually. The action is not executed if the field is changed through another automation rule.

Esterno

Trigger automated actions based on a specific event in an external system or application using a webhook.

After the webhook is configured in Odoo, where the webhook’s URL is generated and the target record defined, it needs to be implemented in the external system.

Avvertimento

È altamente consigliato consultare uno sviluppatore, un architetto di soluzioni o un altro ruolo tecnico quando si decide di utilizzare i webhook nonché durante l’intero processo di implementazione. Se non configurati correttamente, i webhook possono disturbare il database di Odoo e possono richiedere tempo per essere ripristinati.

Esempio trigger Basato su campo data

Nota

It is also possible to set up an automated action that sends data to a external system’s webhook when an event occurs in your Odoo database.

Azioni

Once you have defined the automation rule’s trigger, click Add an action in the Actions To Do tab to define the action(s) to be executed.

Suggerimento

  • If no explicit name is entered, the name of the action will be automatically generated based on the action you define; the name can be updated at any time.

  • You can define multiple actions for the same automation rule. By default, actions are executed in the order in which they were defined.

    This means, for example, that if you define an Update record action and then a Send email action where the email references the field that was updated, the email uses the updated values. However, if the Send email action is defined before the Update record action, the email uses the values set before the record is updated.

    To change the order of defined actions, click the (drag handle) icon beside an action and drag it to the desired position.

Aggiorna record

This action is used to update one of the record’s (related) fields. The following options are available:

  • Update: updates the selected field with the specified value.

  • Update with AI: updates the selected field dynamically based on the AI prompt provided. This option requires the Odoo AI app to be installed.

  • Sequence: update the selected field with a defined sequence.

  • Compute: updates the selected field dynamically using Python code.

To define the action:

  1. With the Update, Update with AI, Sequence or Compute option selected, as relevant, select or search for the field to be updated or computed. If needed, click the (right arrow) next to the field name to access the list of related fields.

  2. Provide the relevant information based on the option selected.

Aggiorna

Select or enter the updated value for the field.

If a many2many field is being updated, choose whether the field must be updated by Adding, Removing, or Setting it to the selected value or by Clearing it.

Example

If you want the automated action to remove a tag from the customer record, set the Update field to Customer > Tags, select by Removing, then select the tag to be removed.

Esempio di azione Aggiorna record

Aggiorna con l’AI

Enter a prompt to instruct Odoo AI how to update the field. Type / to open the AI prompt tools; use Field Selector to tell Odoo AI which related fields to check for context, and Records Selector to provide possible values for the updated field.

Example

If you want the automation rule to update the Assignees field of a newly created task based on the employees” expertise, you can write a prompt to instruct Odoo AI to check the Display Name field of the task for the context, then to assign the most suitable employee.

Example of updating a record using AI

Sequenza

Select an existing sequence or, to create a new sequence:

  1. Click Search more, then click New.

  2. In the window that opens, enter the Name of the sequence.

  3. In the Sequence tab, configure the sequence:

    • Prefix: characters added before the next number in the sequence.

    • Suffix: characters added after the next number in the sequence.

    • Sequence Size: determines the number of digits in every number in the sequence. If needed, leading zeros are added before the number to achieve the indicated sequence size, e.g., for a sequence size of 5, the first number in the sequence is 00001.

    • Step: determines the increments between the numbers in the sequence.

    • Next Number: the next number that will be used in the sequence, without leading zeros.

    Suggerimento

    • Use dynamic placeholders like %(year)s or %(month)s as a Prefix and/or Suffix to create sequences with elements like current year, month, etc. Possible placeholders are shown at the bottom of the window.

    • To use sub-sequences, e.g., to have the sequence restart each year or each month, enable Use subsequences per date_range, then Add a line for each date range and indicate the Next Number for the range.

  4. fai clic su Salva.

Example

If you want the automated action to create a sequential customer reference each time a new customer is created, set the Sequence field to Reference, then, in the dropdown, click Search more. Click New to create a new sequence.

In the example, each new customer receives a sequential reference with the prefix #-REF-%(year)s-, where %(year)s is the current year including the century, and the suffix /CL, e.g., #-REF-2025-00001/CL, #-REF-2025-00002/CL, etc.

Example of an Update Record action using a sequence

Calcola

Enter the code to be used for computing the field’s value.

Example

If you want the automation rule to compute a custom datetime field, Escalated on, when a task’s priority is set to Very high (three stars), you can define the trigger Priority is set to to Very High and define the Update Record action as follows:

Calcolo di un campo data/ora personalizzato utilizzando un'espressione Python

Create Record and Duplicate Record

These actions are used to create a new or duplicated record on any model.

To define the action:

  1. With Create Record or Duplicate Record selected as the Type of action, as relevant, select the required model in the Record to Create field; the field contains the current model by default.

  2. Specify a Name for the record, or, if the action duplicates a record, indicate the record being duplicated in the Duplicate from field.

  3. If the new or duplicated record is being created on another model, select a field in the Link Field field to link the record that triggered the creation of the new or duplicated record.

Suggerimento

The Link Field dropdown menu only contains one2many fields existing on the current model that are linked to a many2one field on the target model.

Example

If you want the automation rule to duplicate a project, e.g. a project template with predefined tasks, when an opportunity is set to Won, add a custom Related opportunity many2one field field on the Project model and a custom Related project one2many field field on the Lead model, then provide the following details about the record being duplicated:

Duplicate a record in a different model

Suggerimento

You can create another automation rule with Aggiorna record actions to update the fields of the new or duplicated record if necessary. For example, you can use a Create Record action to create a new project task and then assign it to a specific user using an Update Record action.

Crea attività

This action is used to schedule a new activity linked to the record.

To define the action:

  1. With Create Activity selected as the Type of action, select the appropriate Activity Type from the dropdown menu.

  2. Enter a Title.

  3. Indicate by when the activity should be completed by specifying a number of Days, Weeks, or Months in the Due Date In field.

  4. Select a User type:

    • To always assign the activity to the same user, select Specific User, then add the user in the Responsible field.

    • To target a user linked to the record dynamically, select Dynamic User (based on record). If needed, change the User Field by clicking on the placeholder field name then selecting or searching for the user field in the list that appears. Clicking the (right arrow) next to the field name allows you to access related fields if needed.

  5. Optionally, add a Note to provide more information about the activity.

Example

After a proposition is sent to a opportunity with a high expected revenue, you want to create an activity for the salesperson’s team leader to call the potential client to increase the chances of closing the deal.

To do so, set the Activity Type to Call and the User Type to Dynamic User (based on record). Click on the placeholder field and select Sales Team, then click the (right arrow) and select Team Leader.

Esempio di un'azione Crea attività

Inviare e-mail e SMS

These actions are used to send an email or a text message to a contact linked to a specific record.

To define the action:

  1. With Send Email or Send SMS selected as the Type of action, as relevant, select or create an Email Template or SMS Template.

  2. In the Send Email As or Send SMS As field, choose how you want to send the email or text message.

    For an email, select:

    • E-mail: per inviare il messaggio come e-mail ai destinatari del Modello e-mail

    • Messaggio: per registrare il messaggio sul record e notificare i follower

    • Nota: per inviare il messaggio come nota interna visibile agli utenti interni nel chatter

    For a text message, select:

    • SMS (senza nota): per inviare il messaggio come messaggio di testo ai destinatari del modello SMS.

    • SMS (con nota): per inviare il messaggio come messaggio di testo ai destinatari del modello SMS e registrarlo come nota interna nel chatter.

    • Solo nota: per registrare il messaggio solo come nota interna nel chatter.

Invia Whatsapp

Importante

Per automatizzare l’invio di messaggi WhatsApp, è necessario creare un modello WhatsApp.

This action is used to send a WhatsApp message to a contact linked to a specific record.

With Send WhatsApp selected as the Type of action, select the appropriate WhatsApp Template from the dropdown menu.

Aggiungere ed eliminare follower

This action is used to subscribe/unsubscribe existing contacts as followers of the record.

With Add Followers or Remove Followers selected as the Type of action, as relevant, select a Followers Type:

  • To always add/remove the same contact(s), select Specific Followers then select the contact(s) from the dropdown menu. Multiple contacts can be added/removed.

  • To add/remove a contact linked to the record dynamically, select Dynamic Followers. If needed, change the Followers Field by clicking on the placeholder field name then selecting or searching for the partner field in the list that appears. Clicking the (right arrow) next to the field name allows you to access related fields if needed.

Example

To keep customers informed of progress on a project, this automated action adds the relevant customer as a follower when a project task is set to In progress.

Adding the customer as a follower when project task set to in progress

Esegui codice

Importante

For automation rules that require the execution of custom code, note that maintenance of custom code is not included in the Standard or Custom pricing plans and incurs additional fees.

L’azione viene utilizzata per eseguire il codice Python. Puoi inserire il codice nella scheda Codice utilizzando le seguenti variabili:

  • env: ambiente in cui viene attivata l’azione

  • model: modello del record su cui l’azione viene attivata, è un recordset vuoto

  • record: record su cui l’azione viene attivata, potrebbe essere vuoto

  • più record: recordset di tutti i record su cui l’azione viene attivata in modalità multipla, questo potrebbe restare vuoto

  • time, datetime, dateutil, timezone: librerie Python utili

  • float_compare: funzione di utilità per confrontare i float in base a una precisione specifica

  • log(message, level='info'): funzione di logging per registrare le informazioni di debug nella tabella ir.logging

  • _logger.info(message): logger per emettere messaggi nei log del server

  • UserError: classe di eccezione per visualizzare messaggi di avviso per gli utenti

  • Command: x2many spazio nome comando

  • action = {...}: per restituire un’azione

Suggerimento

Le variabili disponibili vengono descritte nelle schede Codice e Aiuto.

Invia notifica Webhook

This action is used to send a POST API request with the values of the selected Fields to the webhook URL specified in the URL field.

Il Payload campione fornisce un’anteprima dei dati inclusi nella richiesta utilizzando i dati di un record a caso o dati campione se non ci sono record disponibili.

Nota

It is also possible to set up an automated action that uses a webhook to receive data from an external system when a predefined event occurs in that system.

Più azioni

This action is used to trigger multiple actions (linked to the current model) at the same time.

To define the actions:

  1. With Multi Actions selected as the Type of action, click Add an action.

  2. In the Add: Child Actions pop-up:

    • select one or more existing actions and click Select; or

    • click New, define the action to be executed, then click Save & Close or, to create additional actions, Save & New .

  3. Repeat as many times as needed.

Define multiple actions to be executed