Règles d’automatisation¶
Automation rules are used to trigger automatic changes based on user actions (e.g., apply a modification when a field is set to a specific value), email events, time conditions (e.g., archive a record 7 days after its last update), or external events.
To create an automation rule with Studio, proceed as follows:
Ouvrir Studio et cliquer sur Automatisations, puis Nouveau.
Select the Déclencher and, if necessary, fill in the fields that appear on the screen based on the chosen trigger.
Cliquer sur Ajouter une action, puis sélectionner le Type d”action et remplir les champs qui apparaissent à l’écran en fonction de l’action sélectionnée.
Cliquer sur Enregistrer & Fermer ou Enregistrer & Nouveau.
Example
Astuce
To modify the model of the automation rule, switch models before clicking Automations in Studio, or activate the developer mode, create or edit an automation rule, and select the Model in the Automation Rules form.
You can also create automation rules from any kanban stage by clicking the gear icon (⚙ ) next to the kanban stage name, then selecting Automations. In this case, the Trigger is set to Stage is set to by default, but you can change it if necessary.
Déclencher¶
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:
Astuce
You can also define a Before Update Domain to specify the conditions that must be met before the automation rule is triggered. In contrast, the conditions defined using the Extra Conditions and Apply on filters are checked during the execution of the automation rule.
To define a Before Update Domain, activate the developer mode, create or edit an automation rule, click Edit Domain, then click New Rule.
For example, if you want the automated action to happen when an email address is set on a contact that did not have an address before (in contrast to modifying their existing address), define the Before Update Domain to Email is not set, and the Apply on domain to Email is set.
Valeurs mises à jour¶
The triggers available in this category depend on the model and are based on common field changes, such as adding a specific tag (e.g., to a task) or setting the User field. Select the trigger, then select a value if required.
E-mail Evénéments¶
Déclencher des actions automatisées lors de la réception ou de l’envoi d’e-mails.
Conditions temporelles¶
Trigger automated actions based on a date field. The following triggers are available:
Based on date field: Select the field to be used next to the Delay field.
After creation: The action is triggered when a record is created and saved.
After last update: The action is triggered when an existing record is edited and saved.
Vous pouvez ensuite définir :
a Delay: Specify the number of minutes, hours, days, or months. To trigger the action 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.
Extra Conditions: Click Add condition, then specify the conditions to be met to trigger the automation rule. Click New Rule to add another condition.
The action is triggered when the delay is reached and the conditions are met.
Example
If you want to send a reminder email 30 minutes before the start of a calendar event, select the Start (Calendar Event) under Trigger Date and set the Delay to -30 Minutes.
Note
By default, the scheduler checks for trigger dates every 4 hours, meaning lower granularity in time-based automations may not always be honored.
Personnalisé¶
Déclencher des actions automatisées :
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 saving the record.
Pour les déclencheurs À l’enregistrement et Au changement UI, vous devez ensuite sélectionner le ou les champs à utiliser pour déclencher la règle d’automatisation dans le champ Lors de la mise à jour.
Avertissement
Si aucun champ n’est sélectionné dans le champ Lors de la mise à jour, l’action automatisée peut être exécutée plusieurs fois par enregistrement.
En option, vous pouvez également définir des conditions supplémentaires à remplir pour déclencher la règle d’automatisation dans le champ Appliquer sur.
Note
The On UI change trigger can only be used with the Exécuter le 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.
Externe¶
Trigger automated actions 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, copy the URL generated by Odoo into the destination system (i.e., the system receiving the request). Then, in the Target Record field, enter the code to run to define the record(s) to be updated using the automation rule.
Avertissement
The URL must be treated as confidential; sharing it online or without caution could potentially expose your system to malicious parties. Click the Rotate Secret button to change the URL’s secret if necessary.
Note
The code defined by default in the Target Record field works for webhooks coming from another Odoo database. It is used to determine the record(s) to be updated using the information in the payload.
If you wish to use the webhook’s content for a purpose other than to find the record(s) (e.g., create a record), your only option is to use an Exécuter le code action. In this case, the Target record field must contain any valid code, but its result doesn’t have any effect on the automated action itself.
The webhook content is available in the server action context as a
payloadvariable (i.e., a dictionary that contains the GET parameters or POST JSON body of the incoming request).
You can also choose to Log Calls to record the payloads received, e.g., to make sure 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, click the Logs smart button at the top of the Automation rules form.
Actions à effectuer¶
Once you have defined the automation rule’s trigger, click Add an action to define the action to be executed.
Astuce
You can define multiple actions for the same trigger/automation rule. The actions are executed in the order they are defined. This means, for example, that if you define an Update record action and then a Send email action, 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 update action is run.
Mettre à jour l’enregistrement¶
This action allows to update 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; click the right arrow next to the field name to access the list of related fields if needed.
Si vous avez sélectionné un champ many2many, choisir si le champ doit être mis à jour en Ajoutant, Supprimant, ou Le définissant à la valeur sélectionnée ou en le Vidant.
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.
Astuce
Alternativement, vous pouvez également définir dynamiquement le champ d’un enregistrement en utilisant du code Python. Pour ce faire, sélectionner Calculer au lieu d”Mettre à jour, puis saisir le code à utiliser pour calculer la valeur du champ. Par exemple, si vous souhaitez que la règle d’automatisation calcule un champ datetime personnalisé lorsque la priorité d’une tâche est définie sur High (en ajoutant une étoile à la tâche), vous pouvez définir le déclencheur La priorité est définie sur High et définir l’action Mettre à jour l’enregistrement comme suit :
Créer une activité¶
Cette action est utilisée pour planifier une nouvelle activité liée à l’enregistrement. Sélectionner un Type d’activité, saisir un Titre et une description, puis spécifier quand vous souhaitez que l’activité soit planifiée dans le champ Date d’échéance dans, et sélectionner un Type d’utilisateur :
To always assign the activity to the same user, select Specific User and add the user in the Responsible field;
Pour cibler dynamiquement un utilisateur lié à l’enregistrement, sélectionner Utilisateur dynamique (basé sur l’enregistrement) et modifier le Champ utilisateur si nécessaire.
Example
Après qu’une piste est transformée en opportunité, vous souhaitez que l’action automatisée configure un appel pour l’utilisateur responsable de la piste. Pour ce faire, définir le Type d’activité sur Appel et le Type d’utilisateur sur Utilisateur dynamique (basé sur l’enregistrement).
Envoyer un e-mail et Envoyer un SMS¶
Ces actions sont utilisées pour envoyer un e-mail ou un message texte à un contact lié à un enregistrement spécifique. Pour ce faire, sélectionner ou créer un Modèle d’e-mail ou un Modèle de SMS, puis, dans le champ Envoyer l’e-mail en tant que ou Envoyer le SMS en tant que, choisir comment vous souhaitez envoyer l’e-mail ou le message texte :
E-mail : pour envoyer le message par e-mail aux destinataires du Modèle d’e-mail.
Message : pour publier le message sur l’enregistrement et notifier les abonnés de l’enregistrement.
Note : pour envoyer le message comme note interne visible par les utilisateurs internes dans le fil de discussion.
SMS (sans note) : pour envoyer le message par SMS aux destinataires du Modèle SMS.
SMS (avec note) : pour envoyer le message par SMS aux destinataires du Modèle SMS et le publier comme note interne dans le fil de discussion.
Note uniquement : pour publier uniquement le message comme note interne dans le fil de discussion.
Ajouter des abonnés et Retirer des abonnés¶
Use these actions to (un)subscribe existing contacts to/from the record.
Créer un enregistrement¶
Cette action est utilisée pour créer un nouvel enregistrement sur n’importe quel modèle.
Sélectionner le modèle requis dans le champ Enregistrement à créer ; il contient le modèle actuel par défaut. Spécifier un Nom pour l’enregistrement, puis, si vous souhaitez créer l’enregistrement sur un autre modèle, sélectionner un champ dans le champ Champ de lien pour lier l’enregistrement qui a déclenché la création du nouvel enregistrement.
Note
La liste déroulante liée au champ Champ de lien ne contient que des champs one2many existant sur le modèle actuel qui sont liés à un champ many2one sur le modèle cible.
Astuce
You can create another automation rule with Mettre à jour l’enregistrement 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.
Exécuter le code¶
Cette action est utilisée pour exécuter du code Python. Vous pouvez écrire votre code dans l’onglet Code en utilisant les variables suivantes :
env: environnement sur lequel l’action est déclenchéemodel: modèle de l’enregistrement sur lequel l’action est déclenchée ; est un recordset viderecord: enregistrement sur lequel l’action est déclenchée ; peut être viderecords: recordset de tous les enregistrements sur lesquels l’action est déclenchée en mode multiple ; cela peut être laissé videtime,datetime,dateutil,timezone: bibliothèques Python utilesfloat_compare: fonction utilitaire pour comparer des nombres à virgule flottante en fonction d’une précision spécifiquelog(message, level='info'): fonction de journalisation pour enregistrer des informations de débogage dans la table ir.logging_logger.info(message): logger pour émettre des messages dans les journaux du serveurUserError: classe d’exception pour lever des messages d’avertissement destinés à l’utilisateurCommand: espace de noms des commandes x2manyaction = {...}: pour retourner une action
Astuce
Les variables disponibles sont décrites à la fois dans les onglets Code et Aide.
Envoyer une notification webhook¶
This action allows to send a POST request with the values of the Fields to the URL specified in the URL field.
L”Exemple de charge utile fournit un aperçu des données incluses dans la requête en utilisant les données d’un enregistrement aléatoire ou des données factices si aucun enregistrement n’est disponible.
Exécuter les actions existantes¶
L’action est utilisée pour déclencher plusieurs actions (liées au modèle actuel) en même temps. Pour ce faire, cliquer sur Ajouter une ligne, puis, dans la fenêtre contextuelle Ajouter : Actions enfants, sélectionner une action existante ou cliquer sur Nouveau pour en créer une nouvelle.