自动化规则¶
自动化规则用于根据用户操作(例如,将字段设置为特定值时应用修改)、电子邮件事件、时间条件(例如,在最后一次更新后 7 天存档记录)或外部事件触发自动更改。
使用 Studio 创建自动化规则的步骤如下:
开启 Studio 并点击 自动化,然后点击 新建。
选择 触发器 并根据所选触发器填写屏幕上出现的字段。
点击 添加操作,然后选择 操作 的 类型,并根据所选操作,填写屏幕上出现的字段。
点击 保存并关闭 或 保存并新建。
Example
触发器¶
触发器 用于定义何时应用自动化规则。可用的触发器取决于 模型。共有五个触发器类别:
值更新¶
该类别中可用的触发器取决于模型,并基于常见的字段更改,例如添加特定标记(如添加到任务)或设置 用户 字段。选择触发器,然后根据需要选择值。
电子邮件活动¶
接收或发送电子邮件时触发自动操作。
时间条件¶
根据日期字段触发自动操作。可使用以下触发器:
基于日期字段:选择要用于 延迟 字段旁边的字段。
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.
然后,您可以定义:
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.
注解
By default, the scheduler checks for trigger dates every 4 hours, meaning lower granularity in time-based automations may not always be honored.
自定义¶
触发自动操作:
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.
对于 :guilabel:`保存时`和 :guilabel:`当 UI 变更时`这两种触发器,您**必须**在 :guilabel:`更新时`字段中选择一个或多个用于触发此自动化规则的字段。
警告
如果在 :guilabel:`更新时`字段中没有选择任何字段,该自动化操作可能会对同一条记录执行多次。
(可选)您还可以在 :guilabel:`应用于`字段中定义额外的触发条件。
注解
The On UI change trigger can only be used with the 执行代码 action and only works when a modification is made manually. The action is not executed if the field is changed through another automation rule.
外部¶
基于 Webhook 触发自动化动作。Webhook 是一种跨系统通信机制,当源系统发生特定事件时,会向目标系统发送 HTTP(S) 请求,该请求通常携带事件相关数据载荷。
要配置 网络钩子 触发器,请将 Odoo 生成的 URL 复制到目标系统(即接收请求的系统)。然后,在 目标记录 字段中输入要运行的代码,以定义使用自动化规则更新的记录。
警告
URL 必须属于**机密**;在网络公开或随意分享可能导致系统遭受恶意攻击。如有必要,请点击 重置密钥 按钮更改 URL 的密文。
注解
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.
应采取的行动¶
定义自动化规则的 触发器 后,点击 添加操作 以定义要执行的操作。
小技巧
您可以为同一触发器/自动化规则定义多个操作。操作将按照定义的顺序执行。例如,如果您定义了 更新记录 操作,然后又定义了 发送电子邮件 操作,则电子邮件将使用更新后的值。但是,如果在 更新记录 操作之前定义了 发送电子邮件 操作,则电子邮件将使用更新操作运行**之前**设置的值。
更新记录¶
此操作允许更新记录的一个(相关)字段。点击 更新 字段,在打开的列表中选择或搜索要更新的字段;必要时点击字段名旁的向右箭头,访问相关字段列表。
如果您选择了 many2many 字段,请选择是否必须通过 添加、删除、设置为`选定值或 :guilabel: 清除`来更新该字段。
Example
如果您希望自动操作从客户记录中删除标签,请将 更新 字段设置为 客户 > 标签,选择 通过删除,然后选择标签。
创建活动¶
此操作用于安排与记录关联的新活动。选择 活动类型,输入 标题 和描述,然后在 到期日在 字段中指定要安排活动的时间,并选择 用户类型:
要始终将活动分配给同一用户,请选择 特定用户,并在 负责人 字段中添加用户;
要针对动态链接到记录的用户,请选择 动态用户(基于记录),并根据需要更改 用户字段。
Example
将潜在客户转化为商机后,您希望自动操作为负责该潜在客户的用户发起呼叫。要执行此操作,请将 活动类型 设为 呼叫,并将 用户类型 设为 动态用户(基于记录)。
发送电子邮件和发送短信¶
这些操作用于向链接到特定记录的联系人发送电子邮件或短信。为此,请选择或创建 电子邮件模板 或 短信模板,然后在 发送电子邮件为 或 发送短信为 字段中选择发送电子邮件或短信的方式:
电子邮件:将信息作为电子邮件发送给 电子邮件模板 的收件人。
消息:在记录上发布消息,并通知记录的关注者。
备注:将消息作为内部备注发送,内部用户可在沟通栏中看到。
短信(无备注):将信息作为文本信息发送给 :guilabel:`短信模板`的收件人。
短信(带备注):将短信作为文本消息发送给 短信模板 的收件人,并作为内部备注发布在沟通栏中。
仅限备注:只将消息作为内部备注发布在沟通栏中。
添加关注者和删除关注者¶
Use these actions to (un)subscribe existing contacts to/from the record.
创建记录¶
此操作用于在任何模型上创建新记录。
在 记录创建 字段中选择所需的模型;默认情况下它包含当前模型。为记录指定 名称,然后,如果要在其他模型上创建记录,请在 链接字段 字段中选择一个字段,以链接触发创建新记录的记录。
注解
与 链接字段 字段相关的下拉列表只包含当前模型上存在的 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.
执行代码¶
此操作用于执行 Python 代码。您可以使用以下变量将代码写入 代码 选项卡:
env:触发操作的环境模型:触发操作的记录的模型;是一个无效记录集记录:触发操作的记录;可能无效记录:在多模式下触发操作的所有记录的记录集;可留空time、datetime、dateutil、timezone:实用的Python时间处理库float_compare:根据特定精度比较浮点数的实用程序函数log(message, level='info'):在 ir.logging 表中记录调试信息的日志函数_logger.info(message):在服务器日志中发布消息的日志程序UserError:用于发出面向用户的警告信息的异常类指令:x2many 指令命名空间操作 = {...}:返回一个操作
小技巧
可用变量在 代码 和 帮助 选项卡中均有说明。
发送 Webhook 通知¶
This action allows to send a POST request with the values of the Fields to the URL specified in the URL field.
示例数据负载 可预览请求中包含的数据,这些数据来自随机记录(若存在记录)或虚拟数据(若无可用记录)。
执行现有行动¶
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.