Regole di automazione

Automation rules allow the execution of one or more predefined actions in response to a specific trigger, e.g., create an activity when a field is set to a specific value, or archive a record 7 days after its last update.

When creating an automation rule, domain filters allow you 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, proceed as follows:

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

  2. Give the automation rule a clear, meaningful name that identifies its purpose.

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

  4. fai clic su Aggiungi un’azione, per poi selezionare il Tipo di action e compila i campi che appaiono sullo schermo in base all’azione selezionata

  5. fai clic su Salva e chiudi oppure su Salva e nuova.

Example

To ensure follow-up on less satisfied clients, this automation rule creates an activity 3 months after a sales order is created for clients with a satisfaction percentage lower than 30%.

Example of an automation rule on the Subscription model

Suggerimento

  • Use the Notes tab to document the purpose and functioning of automation rules. This makes rules easier to maintain and facilitates collaboration between users.

  • To modify the model targeted by the automation rule, switch models before clicking Automations in Studio, or activate developer mode, create or edit an automation rule, and select the Model in the Automation Rules form.

  • Automation rules can be created from any kanban stage by clicking the (Settings) icon that appears when hovering over the kanban stage name, then selecting Automations. In this case, the Trigger is set to Stage is set to by default, but it can be changed if necessary.

    Creare automazioni da una fase kanban

Trigger

The Trigger is used to define what kind of event needs to occur for the automation rule to run. The available triggers depend on the model. Five trigger categories are available overall:

Adding conditions

Domain filters allow you to determine the records an automation rule should target or exclude. Efficient filtering enhances overall performance as it avoids unnecessary processing on records that are not impacted by the rule.

Suggerimento

Activate developer mode before creating an automation rule to have the most flexibility in adding domain filters.

Depending on the trigger chosen, it is possible to define one or more conditions a record must meet before and/or after a trigger occurs.

  • 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.

  • Extra Conditions, or in some cases Apply on filters, define 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 if needed, click Add conditions or Edit Domain, as relevant, then 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.

  • 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.

In seguito, puoi indicare:

  • a Delay: Specify the number of minutes, hours, days, or months. To have an action executed before the trigger date, specify a negative number. If you selected the Based on date field trigger, you must also select the date field to be used to determine the delay.

    Nota

    By default, the scheduler checks for time-triggered automation rules every 240 minutes, or 4 hours. This frequency is generally sufficient for delays such as 3 months after the order date or 7 days after the last update.

    For delays of less than the equivalent of 2400 minutes, or 40 hours, the system recalculates the frequency of this check to ensure that more granular delays, e.g., 1 hour before the event start date and time, or 30 minutes after creation, can be respected as closely as possible.

    An on-screen message indicates the possible delay after the scheduled triggering of the rule.

    Message about possible delay after scheduled execution

    To view or manually edit the frequency of the scheduler, with developer mode activated, go to Settings ‣ Technical ‣ Scheduled Actions to see all scheduled actions for your database.

    Enter Automation in the search bar, then, in the list of results, click Automation Rules: check and execute. If desired, update the value of the Execute Every field. Click Run Manually at any time to manually trigger this scheduled action.

  • Extra Conditions: Click Add condition, then specify the conditions to be met for the automation rule to run. Click New Rule to add another condition.

The action is executed when the delay is reached and the conditions are met.

Example

To send a reminder email 30 minutes before the start of a calendar event, select Start (Calendar Event) as the date field for the Trigger and set the Delay to -30 Minutes.

Esempio trigger Basato su campo data

Personalizzata

Trigger azioni automatizzate:

  • On save: when a 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.

Per i trigger Al momento del salvataggio e Al momento della modifica IU, devi selezionare i campi da utilizzare per attivare la regola di automazione nel campo Quando si aggiorna.

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.

Example

To trigger an automated action upon the creation of a record, e.g., when a new contact is created, select the On save trigger and use ID is not set as the Before Update Domain and ID is set as the Apply on domain. Make sure the correct field is selected in the When updating field.

When a new contact is saved, it is automatically assigned a database ID, thereby triggering the automation rule.

Example of a triggering an action upon creation of a record

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 to be executed.

Suggerimento

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 updates one of the record’s (related) fields. Click the Update field and, in the list that opens, select or search for the field to be updated. If needed, click the (right arrow) next to the field name to access the list of related fields.

Se selezioni un :ref:` campo molti a molti <studio/fields/relational-fields-many2many>`, scegli se il campo deve essere aggiornato Aggiungendo, Eliminando, o Impostandolo sul valore selezionato oppure Eliminandolo.

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.

Esempio di azione Aggiorna record

Suggerimento

In alternativa, puoi anche configurare il campo di un record in modo dinamico utilizzando il codice Python. Per farlo, seleziona Calcola invece di Aggiorna e poi inserisci il codice da usare per il calcolo del valore del campo. Ad esempio, se vuoi che la regola di automazione calcoli un campo data personalizzato quando la priorità di un lavoro è impostata su Alta (aggiungendo stelline al lavoro), puoi impostare il valore del trigger La priorità è impostata su a Alta e definire l’azione Aggiorna record come segue:

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

Crea attività

Quest’azione viene utilizzata per programmare una nuova attività collegata al record. Seleziona un Tipo di attività, inserisci un Titolo e una descrizione per poi specificare quando vuoi che l’attività venga programmata nel campo Data di scadenza tra e seleziona un Tipo di utente:

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

  • per raggiungere un utente collegato al record in modo dinamico, seleziona Utente dinamico (in base al record) e modifica il Campo utente se necessario.

Example

Dopo aver convertito un lead in opportunità, vuoi che l’azione automatizzata programmi una chiamata per l’utente responsabile del lead. Per farlo, configura il Tipo di attività su Utente dinamico (in base al record).

Esempio di un'azione Crea attività

Inviare e-mail e SMS

Queste azioni vengono utilizzate per inviare un’e-mail o un messaggio di testo a un contatto collegato a un record specifico. Per farlo, seleziona o crea un Modello e-mail o un Modello SMS, e poi nel campo Invia e-mail come o Invia SMS come, scegli come vuoi inviare l’e-mail o il messaggio di testo:

  • 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

  • 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. To do so, select the appropriate WhatsApp Template from the dropdown menu.

Aggiungere ed eliminare follower

This action is used to subscribe/unsubscribe existing contacts to/from the record.

Crea record

L’azione viene utilizzata per creare un nuovo record su ogni modello.

Seleziona il modello richiesto per il campo Record da creare che contiene il modello attuale per impostazione predefinita. Specifica un Nome per il record e poi, se vuoi creare il record su un altro modello, seleziona un campo nel Campo link per collegare il record che ha attivato l’azione del nuovo record.

Nota

L’elenco a discesa collegato al Campo link contiene solo campi uno a molti esistenti nel modello attuale e che sono collegati a un campo molti a uno nel modello di destinazione.

Suggerimento

You can create another automation rule with Aggiorna record actions to update the fields of the new 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.

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.

Esegui azioni esistenti

L’azione viene utilizzata per attivare più azioni (collegate al modello attuale) nello stesso momento. Per farlo, fai clic su Aggiungi una riga, poi nella finestra pop-up Aggiungi: azioni figlie seleziona un’azione esistente oppure fai clic su Nuova per crearne una nuova.