自动化规则¶
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:
开启 Studio 并点击 自动化,然后点击 新建。
Give the automation rule a clear, meaningful name that identifies its purpose.
Select the trigger and, if necessary, fill in the fields that appear on the screen based on the chosen trigger.
点击 添加操作,然后选择 操作 的 类型,并根据所选操作,填写屏幕上出现的字段。
点击 保存并关闭 或 保存并新建。
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%.

小技巧
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.
触发器¶
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.
小技巧
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
andStatus = 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.

注解
The Before Update Domain is not checked upon the creation of a record.
值更新¶
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.
电子邮件活动¶
接收或发送电子邮件时触发自动操作。
时间条件¶
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.
然后,您可以定义:
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.
注解
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.
To view or manually edit the frequency of the scheduler, with developer mode activated, go to 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 Based on date
field
as the Trigger, then set the Delay to -30
Minutes
and select Start (Calendar Event) as the date field.

自定义¶
触发自动操作:
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.
对于 :guilabel:`保存时`和 :guilabel:`当 UI 变更时`这两种触发器,您**必须**在 :guilabel:`更新时`字段中选择一个或多个用于触发此自动化规则的字段。
警告
如果在 :guilabel:`更新时`字段中没有选择任何字段,该自动化操作可能会对同一条记录执行多次。
(可选)您还可以在 :guilabel:`应用于`字段中定义额外的触发条件。
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.

注解
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.
外部¶
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.
警告
It is highly recommended to consult with a developer, solution architect, or another technical role when deciding to use webhooks and throughout the implementation process. If not properly configured, webhooks may disrupt the Odoo database and can take time to revert.

注解
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.
操作¶
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.
The title of the action is automatically generated based on the action you define, but it can be updated manually.
小技巧
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.
更新记录¶
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.
如果您选择了 many2many 字段,请选择是否必须通过 添加、删除、设置为`选定值或 :guilabel: 清除`来更新该字段。
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 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. In the list, click the (right arrow) next to the field name to access related fields if needed.
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.

发送电子邮件和发送短信¶
这些操作用于向链接到特定记录的联系人发送电子邮件或短信。为此,请选择或创建 电子邮件模板 或 短信模板,然后在 发送电子邮件为 或 发送短信为 字段中选择发送电子邮件或短信的方式:
电子邮件:将信息作为电子邮件发送给 电子邮件模板 的收件人。
消息:在记录上发布消息,并通知记录的关注者。
备注:将消息作为内部备注发送,内部用户可在沟通栏中看到。
短信(无备注):将信息作为文本信息发送给 :guilabel:`短信模板`的收件人。
短信(带备注):将短信作为文本消息发送给 短信模板 的收件人,并作为内部备注发布在沟通栏中。
仅限备注:只将消息作为内部备注发布在沟通栏中。
发送 WhatsApp¶
重要
要自动发送 WhatsApp 消息,必须创建一个或多个 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.
添加关注者和删除关注者¶
This action is used to subscribe/unsubscribe existing contacts to/from the record. Followers can be added in two ways:
To always add the same, specific contact(s), select Specific Followers as Followers Type then choose the relevant contact from the dropdown. Repeat as many times as needed to add multiple contacts.
To add a contact linked to the record dynamically, select Dynamic Followers as Followers Type. 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. In the list, click the (right arrow) next to the field name 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.

创建记录¶
此操作用于在任何模型上创建新记录。
在 记录创建 字段中选择所需的模型;默认情况下它包含当前模型。为记录指定 名称,然后,如果要在其他模型上创建记录,请在 链接字段 字段中选择一个字段,以链接触发创建新记录的记录。
注解
与 链接字段 字段相关的下拉列表只包含当前模型上存在的 one2many 字段 字段,这些字段与目标模型上的 many2one 字段 字段链接。
小技巧
You can create another automation rule with 更新记录 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.
执行代码¶
重要
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.
此操作用于执行 Python 代码。您可以使用以下变量将代码写入 代码 选项卡:
env
:触发操作的环境模型
:触发操作的记录的模型;是一个无效记录集记录
:触发操作的记录;可能无效记录
:在多模式下触发操作的所有记录的记录集;可留空time
、datetime
、dateutil
、timezone
:实用的Python时间处理库float_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
小技巧
The available variables are described both in the Code and Help tabs.
发送 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.
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.
注解
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.
执行现有行动¶
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.