Quy tắc tự động hoá¶
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:
Open Studio and click Automations, then New.
Select the Kích hoạt and, if necessary, fill in the fields that appear on the screen based on the chosen trigger.
Click Add an action, then select the Type of action and fill in the fields that appear on the screen based on your selected action.
Click Save & Close or Save & New.
Example

Mẹo
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.
Kích hoạt¶
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:
Mẹo
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.

Giá trị đã được cập nhật¶
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.

Sự kiện email¶
Trigger automated actions upon receiving or sending emails.
Điều kiện thời gian¶
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.
You can then define:
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.

Ghi chú
By default, the scheduler checks for trigger dates every 4 hours, meaning lower granularity in time-based automations may not always be honored.
Tùy chỉnh¶
Trigger automated actions:
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.
For the On save 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.
Cảnh báo
If no field is selected in the When updating field, the automated action may be executed multiple times per record.
Optionally, you can also define additional conditions to be met to trigger the automation rule in the Apply on field.
Ghi chú
The On UI change trigger can only be used with the Thực thi mã action and only works when a modification is made manually. The action is not executed if the field is changed through another automation rule.
Bên ngoài¶
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.
Cảnh báo
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.
Ghi chú
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.
Nếu bạn muốn sử dụng nội dung của webhook cho mục đích khác ngoài việc tìm (các) bản ghi (ví dụ như tạo bản ghi mới), thì lựa chọn duy nhất là dùng tác vụ Thực thi mã. Trong trường hợp này, trường Bản ghi mục tiêu có thể chứa bất kỳ đoạn mã hợp lệ nào, nhưng kết quả của đoạn mã đó sẽ không ảnh hưởng đến tác vụ tự động.
The webhook content is available in the server action context as a
payload
variable (i.e., a dictionary that contains the GET parameters or POST JSON body of the incoming request).
Bạn cũng có thể chọn :guilabel:'Ghi nhật ký cuộc gọi' để ghi lại các payload đã nhận, ví dụ như để đảm bảo rằng dữ liệu được gửi từ hệ thống nguồn khớp với định dạng và nội dung mong đợi. Điều này cũng giúp xác định và chẩn đoán bất kỳ sự cố nào có thể phát sinh. Để truy cập nhật ký, hãy nhấp vào nút thông minh Nhật ký ở phía trên biểu mẫu Quy tắc tự động hóa.
Tác vụ cần thực hiện¶
Once you have defined the automation rule's trigger, click Add an action to define the action to be executed.
Mẹo
Bạn có thể xác định nhiều hành động cho cùng một quy tắc tự động/kích hoạt. Các hành động sẽ được thực thi theo thứ tự chúng được xác định. Điều này có nghĩa là nếu bạn xác định tác vụ Cập nhật bản ghi trước rồi đến tác vụ Gửi email, thì email sẽ sử dụng các giá trị đã được cập nhật. Tuy nhiên, nếu tác vụ Gửi email được xác định trước tác vụ Cập nhật bản ghi, thì email sẽ sử dụng các giá trị được đặt trước khi tác vụ cập nhật được thực thi.
Cập nhật tập dữ liệu¶
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.
If you selected a many2many field, 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.

Mẹo
Ngoài ra, bạn cũng có thể thiết lập trường của bản ghi một cách linh hoạt bằng mã Python. Để thực hiện, chọn Tính toán thay vì Cập nhật, sau đó nhập mã sẽ được sử dụng để tính giá trị của trường. Ví dụ, nếu bạn muốn quy tắc tự động tính toán trường ngày giờ tùy chỉnh khi mức độ ưu tiên của nhiệm vụ được đặt thành Cao
(bằng cách đánh dấu sao cho nhiệm vụ), bạn có thể xác định trình kích hoạt Mức độ ưu tiên được đặt thành thành Cao
và xác định hành động Cập nhật bản ghi như sau:

Tạo hoạt động¶
This action is used to schedule a new activity linked to the record. Select an Activity Type, enter a Title and description, then specify when you want the activity to be scheduled in the Due Date In field, and select a User type:
To always assign the activity to the same user, select Specific User and add the user in the Responsible field;
To target a user linked to the record dynamically, select Dynamic User (based on record) and change the User Field if necessary.
Example
After a lead is turned into an opportunity, you want the automated action to set up a call for the user responsible for the lead. To do so, set the Activity Type to Call and the User Type to Dynamic User (based on record).

Send Email and Send SMS¶
Những tác vụ này được sử dụng để gửi email hoặc tin nhắn văn bản đến một liên hệ được liên kết với một bản ghi cụ thể. Để thực hiện, hãy chọn hoặc tạo một Mẫu email hoặc Mẫu SMS. Sau đó, trong trường Gửi email dưới dạng hoặc Gửi SMS dưới dạng, chọn cách bạn muốn gửi email hoặc tin nhắn văn bản:
Email: to send the message as an email to the recipients of the Email Template.
Message: to post the message on the record and notify the record's followers.
Note: to send the message as an internal note visible to internal users in the chatter.
SMS (without note): to send the message as a text message to the recipients of the SMS template.
SMS (with note): to send the message as a text message to the recipients of the SMS template and post it as an internal note in the chatter.
Note only: to only post the message as an internal note in the chatter.
Add Followers and Remove Followers¶
Use these actions to (un)subscribe existing contacts to/from the record.
Tạo tập dữ liệu¶
This action is used to create a new record on any model.
Chọn mô hình cần thiết trong trường Bản ghi cần tạo; mặc định trường này chứa mô hình hiện tại. Chỉ định Tên cho bản ghi, sau đó nếu muốn tạo bản ghi trên mô hình khác, hãy chọn một trường trong trường Trường liên kết để liên kết bản ghi đã kích hoạt việc tạo bản ghi mới.
Ghi chú
The dropdown list related to the Link Field field only contains one2many fields existing on the current model that are linked to a many2one field on the target model.
Mẹo
You can create another automation rule with Cập nhật tập dữ liệu 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.
Thực thi mã¶
This action is used to execute Python code. You can write your code into the Code tab using the following variables:
env
: environment on which the action is triggeredmodel
: model of the record on which the action is triggered; is a void recordsetrecord
: record on which the action is triggered; may be voidrecords
: recordset of all records on which the action is triggered in multi-mode; this may be left emptytime
,datetime
,dateutil
,timezone
: useful Python librariesfloat_compare
: utility function to compare floats based on specific precisionlog(message, level='info')
: logging function to record debug information in ir.logging table_logger.info(message)
: logger to emit messages in server logsUserError
: exception class for raising user-facing warning messagesCommand
: x2many commands namespaceaction = {...}
: to return an action
Mẹo
The available variables are described both in the Code and Help tabs.
Gửi thông báo webhook¶
This action allows to send a POST request with the values of the Fields 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.
Thực thi tác vụ hiện có¶
The action is used to trigger multiple actions (linked to the current model) at the same time. To do so, click on Add a line, then, in the Add: Child Actions pop-up, select an existing action or click New to create a new one.