Skip to content

Commit 86bcf79

Browse files
committed
[IMP] studio: clarifying logic for time-triggered automation rules
task-5335209 closes #15520 X-original-commit: bd0025e Signed-off-by: Siobhan McGonigle (mcsi) <mcsi@odoo.com>
1 parent b9a1be8 commit 86bcf79

File tree

1 file changed

+85
-43
lines changed

1 file changed

+85
-43
lines changed

content/applications/studio/automated_actions.rst

Lines changed: 85 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,10 @@ To create an automation rule with **Odoo Studio**:
1818
#. Give the automation rule a clear, meaningful name that identifies its purpose.
1919
#. Select the :ref:`Trigger <studio/automated-actions/trigger>` and, if necessary, fill in the
2020
fields that appear on the screen based on the chosen trigger.
21-
#. Click :guilabel:`Add an action` in the :guilabel:`Actions To Do` tab.
22-
23-
.. tip::
24-
If no explicit name is entered, the name of the action will be automatically generated based
25-
on the action you define; the name can be updated at any time.
26-
27-
#. Select the :guilabel:`Type` of :ref:`action <studio/automated-actions/action>` and complete the
28-
relevant fields based on the chosen action.
21+
#. Click :ref:`Add an action <studio/automated-actions/action>` in the :guilabel:`Actions To Do`
22+
tab.
23+
#. Select the :guilabel:`Type` of action and complete the relevant fields based on the chosen
24+
action.
2925
#. Click :guilabel:`Save & Close` or, to define additional actions, :guilabel:`Save & New`.
3026

3127
.. example::
@@ -142,44 +138,88 @@ Timing Conditions
142138
Trigger automated actions at a point in time relative to a date field or to the creation or update
143139
of a record. The following triggers are available:
144140

145-
- :guilabel:`Based on date field`: The action is triggered a defined period of time before or after
146-
the date of the selected date field.
141+
- :guilabel:`Based on date field`: The action is triggered a defined period of time *before or
142+
after* the date of the selected date field, e.g., 30 days before the contract end date.
147143
- :guilabel:`After creation`: The action is triggered a defined period of time after a record is
148144
created and saved.
149145
- :guilabel:`After last update`: The action is triggered a defined period of time after an existing
150146
record is edited and saved.
151147

152-
You can then define:
148+
To configure a :guilabel:`Timing Conditions` trigger, with :ref:`developer mode activated
149+
<developer-mode>`:
150+
151+
#. Select the appropriate :guilabel:`Trigger` from the :guilabel:`Timing Conditions` category.
152+
If you select the :guilabel:`Based on date field` trigger, select the relevant date field.
153+
#. Configure the :guilabel:`Delay` to determine the *execution date time* of the action(s). To
154+
do so, enter the number of :guilabel:`Minutes`, :guilabel:`Hours`, :guilabel:`Days`, or
155+
:guilabel:`Months` after which the action should be triggered. If you selected the
156+
:guilabel:`Based on date field` trigger, the action can be triggered :guilabel:`After` or
157+
:guilabel:`Before` the selected date field.
158+
#. Optionally, :ref:`add conditions <studio/automated-actions/conditions>` that the record must meet
159+
before and/or after the rule is triggered.
160+
#. Click :icon:`fa-cloud-upload` :guilabel:`Save manually`.
161+
#. Click :icon:`fa-arrow-right` :guilabel:`Scheduled action` to open the :guilabel:`Automation
162+
Rules: check and execute` scheduled action.
153163

154-
- a :guilabel:`Delay`: Specify the number of :guilabel:`Minutes`, :guilabel:`Hours`,
155-
:guilabel:`Days`, or :guilabel:`Months` after which the action should be triggered. If you
156-
selected the :guilabel:`Based on date field` trigger, the action can be triggered
157-
:guilabel:`After` or :guilabel:`Before` the selected date field.
164+
.. note::
165+
This scheduled action checks for execution date times that have been reached since its
166+
previous run, and executes the related action(s), if relevant. By default, the scheduled
167+
action is set to :guilabel:`Execute Every` 4 hours, which is generally sufficient for delays
168+
such as 3 months after the order date or 7 days after the last update.
158169

159-
.. note::
160-
By default, the scheduler checks for time-triggered automation rules every 240 minutes, or 4
161-
hours. This frequency is generally sufficient for delays such as 3 months after the order date
162-
or 7 days after the last update.
170+
If any automation rule has a time-based trigger with a delay of less than the equivalent of 40
171+
hours, e.g., 3 hours before the event start date time, the frequency of the scheduled action
172+
is automatically increased, e.g., to :guilabel:`Execute Every` 18 minutes. This allows the
173+
action to be executed closer to its scheduled execution date time.
163174

164-
For delays of less than the equivalent of 2400 minutes, or 40 hours, the system recalculates
165-
the frequency of this check to ensure that more granular delays, e.g., 1 hour before the event
166-
start date and time, or 30 minutes after creation, can be respected as closely as possible.
175+
#. Click :guilabel:`Run manually` at the top left.
167176

168-
To view or manually edit the frequency of the scheduler for a time-triggered automation rule,
169-
with :ref:`developer mode activated <developer-mode>`, click :guilabel:`Scheduled action`.
177+
.. warning::
178+
This step is critical to prevent the rule from running retroactively on historical records.
179+
Running the scheduled action manually initializes the timestamp of its *last run* in the
180+
automation rule, which is a key element of the rule's :ref:`execution logic
181+
<studio/automated-actions/trigger-timing-conditions-logic>`.
170182

171-
.. image:: automated_actions/trigger-delay-scheduled-action.png
172-
:alt: Direct link to scheduled action for automations
183+
#. Click the automation rule name in the breadcrumbs to return to the automation rule setup.
184+
#. Add the :ref:`action(s) to be executed <studio/automated-actions/action>` then, when all actions
185+
have been defined, click :icon:`fa-cloud-upload` :guilabel:`Save manually`.
173186

174-
In the :guilabel:`Automation Rules: check and execute` scheduled action that opens, update the
175-
value of the :guilabel:`Execute Every` field, if desired. Clicking :guilabel:`Run Manually`
176-
triggers the scheduled action to run immediately. To return to the automation rule setup, click
177-
the automation rule name in the breadcrumbs.
187+
The action is executed the first time the :guilabel:`Automation Rules: check and execute` scheduled
188+
action runs after the execution date time is reached, and when the conditions are met.
178189

179-
- :guilabel:`Extra Conditions`: Click :guilabel:`Add condition`, then specify the conditions to be
180-
met for the automation rule to run. Click :guilabel:`New Rule` to add another condition.
190+
.. _studio/automated-actions/trigger-timing-conditions-logic:
181191

182-
The action is executed when the delay is reached and the conditions are met.
192+
Execution logic
193+
~~~~~~~~~~~~~~~
194+
195+
When using a time-based trigger, an action is only executed when the execution date time falls
196+
*between* the last run of the scheduled action and the current run (whether scheduled or run
197+
manually), i.e.:
198+
199+
**last run --> execution date and time --> current run**
200+
201+
.. note::
202+
Running the :guilabel:`Automation Rules: check and execute` scheduled action manually does not
203+
necessarily result in a rule's action being executed. When testing an automation rule with a
204+
time-based trigger, ensure that this sequence is true, then check if the action has been
205+
executed.
206+
207+
.. example::
208+
On the morning of October 15, you create an automation rule that triggers the sending of an email
209+
30 days before the :guilabel:`Contract end date`; contracts end at 11:59 pm on their contract end
210+
date. During the creating of the rule, the :guilabel:`Automation Rules: check and execute`
211+
scheduled action was run manually at 11:00 am and is set to run every four hours thereafter.
212+
213+
This new automation rule will apply for contracts whose end date is at least 30 days *after* the
214+
creation of the rule, i.e., an end date of November 14 or later.
215+
216+
For a contract with an end date of November 14, the execution date time of the action is 11:59 pm
217+
on October 15. The action will therefore be executed the first time the :guilabel:`Automation
218+
Rules: check and execute` scheduled action runs after that date and time has passed, i.e.,:
219+
220+
- last run of the scheduled action: 11:00 pm on October 15
221+
- execution date time: 11:59 pm on October 15
222+
- current run of the scheduled action: 3:00 am on October 16
183223

184224
.. _studio/automated-actions/trigger-custom:
185225

@@ -247,16 +287,18 @@ click :guilabel:`Add an action` in the :guilabel:`Actions To Do` tab to define t
247287
executed.
248288

249289
.. tip::
250-
You can define multiple actions for the same automation rule. By default, actions are executed in
251-
the order in which they were defined.
252-
253-
This means, for example, that if you define an :guilabel:`Update record` action and then a
254-
:guilabel:`Send email` action where the email references the field that was updated, the email
255-
uses the updated values. However, if the :guilabel:`Send email` action is defined before the
256-
:guilabel:`Update record` action, the email uses the values set *before* the record is updated.
257-
258-
To change the order of defined actions, click the :icon:`oi-draggable` :guilabel:`(drag handle)`
259-
icon beside an action and drag it to the desired position.
290+
- If no explicit name is entered, the name of the action will be automatically generated based
291+
on the action you define; the name can be updated at any time.
292+
- You can define multiple actions for the same automation rule. By default, actions are executed
293+
in the order in which they were defined.
294+
295+
This means, for example, that if you define an :guilabel:`Update record` action and then a
296+
:guilabel:`Send email` action where the email references the field that was updated, the email
297+
uses the updated values. However, if the :guilabel:`Send email` action is defined before the
298+
:guilabel:`Update record` action, the email uses the values set *before* the record is updated.
299+
300+
To change the order of defined actions, click the :icon:`oi-draggable` :guilabel:`(drag handle)`
301+
icon beside an action and drag it to the desired position.
260302

261303
.. _studio/automated-actions/action-update-record:
262304

0 commit comments

Comments
 (0)