Many small businesses use Odoo but still copy data between records by hand: assign a follow-up, notify a colleague, set a field after a status change. Automation rules (formerly "automated actions") do this for you. This article is for business owners and Odoo administrators who want rules that stay predictable. It refers to Odoo 19.0 and its Studio documentation.
1. How an automation rule is built
Every rule answers three questions: when should it run (the trigger), for which records (conditions) and what should happen (the actions). In Studio, open Automations, click New, give the rule a descriptive name, select the Trigger, then click Add an action in the Actions To Do tab. The Notes tab is a good place to document why the rule exists. To work on a different model, switch the model before opening Automations or select the Model in the rule form in developer mode.
Note: Try new rules on a test database or a staging copy first. A rule that writes to many records cannot be undone with one click.
2. Choosing the trigger
The Odoo 19 documentation groups triggers into categories:
- Values Updated – reacts to common changes such as a tag being added or a field being set to a value. The available triggers depend on the model.
- Email Events – reacts to emails being received or sent.
- Timing Conditions – relative to a date field or to record creation or last update ("Based on date field", "After creation", "After last update").
- Custom – "On create", "On create and edit", "On deletion" and "On UI change".
- External – a webhook generated in Odoo starts the rule when something happens in another system.
Prefer the most specific trigger. "Values Updated" with a concrete value is easier to reason about than "On create and edit" on a whole model.
"On create and edit": always select the fields
For "On create and edit" and "On UI change" you must select fields in the When updating field. Otherwise, according to the documentation, the action may run several times per record. "On UI change" works only with the Execute Code action, only for manual changes, and does not fire when another rule changes the field.
3. Conditions: Before Update Domain and Apply on
Two domains narrow down the records:
- Before Update Domain – conditions the record must meet before the change. It is not checked when a record is created.
- Apply on – conditions the record must meet after the trigger.
Developer mode gives the most flexibility: use Edit Domain and New Rule. Typical example: "run only when the stage changed from a certain stage (Before Update Domain) and the expected revenue is at least a threshold (Apply on)".
4. Time-based rules
With Timing Conditions you set a Delay in minutes, hours, days or months; for "Based on date field" the action can fire before or after the chosen date. Two details matter in practice:
- Time-based rules are checked by the scheduled action Automation Rules: check and execute. By default it runs every 4 hours; if a time-based rule has a delay of less than the equivalent of 40 hours, Odoo increases the frequency automatically.
- An action only runs when its execution time falls between the scheduled action's last run and its current run. The documentation therefore recommends, in developer mode, to save the rule, open the scheduled action and click Run manually once. This sets the last-run timestamp and avoids retroactive execution on historical records.
5. Choosing the action
Odoo 19 offers, among others:
- Update Record (Update, Update with AI, Sequence, Compute), Create Record, Duplicate Record
- Create Activity, Send Email, Send SMS, Send WhatsApp
- Add Followers, Remove Followers
- Send Webhook Notification (a POST request with selected field values to a URL you specify; the Sample Payload shows a preview)
- Execute Code and Multi Actions
Use the built-in actions whenever possible. They need no Python, can be maintained by non-developers and survive upgrades more easily. Use Execute Code only when the standard actions cannot express the logic. Note that Odoo states that maintenance of custom code is not included in the Standard or Custom pricing plans.
6. Execute Code: a minimal, safe example
Under the hood, rule actions are server actions (ir.actions.server). In an Execute Code action the following names are available: env, model, record, records, time, datetime, dateutil, timezone, float_compare, log(), _logger, UserError, Command and action. The function log(message, level='info') writes to the ir.logging table; _logger.info() writes to the server log.
Example for a CRM rule: set large leads to the priority Very High (three stars, stored as '3') and leave a trace for later debugging. Adapt model, fields and threshold to your own setup and test it first.
for lead in records:
if lead.expected_revenue >= 10000 and lead.priority != '3':
lead.write({'priority': '3'})
log("Lead %s set to Very High priority" % lead.id)
Assign this to a rule on the Lead/Opportunity model with a specific trigger (for example a Values Updated trigger or "On create and edit" with the When updating field set to the revenue field). Because the code only writes when the priority is not yet set, running it twice does no harm.
7. Avoiding loops and surprises
The official page does not discuss recursion, so treat the following as our practical advice:
- Do not write to the field that triggers the same rule unless a condition stops the second run.
- Make actions idempotent: check the current value before writing, as in the example above.
- Be careful with several rules on one model; one rule's write can trigger another.
- Test with one record first and check the result in the chatter, the activities or the
ir.loggingentries. - Test webhooks with a developer. Odoo warns that a misconfigured webhook can disrupt the database and take time to revert.
8. Documentation and ownership
Name rules after their purpose ("CRM: flag leads over 10k"), write the reason into the Notes tab and keep a list of active rules. Before an upgrade, review every rule that uses Execute Code, because model and field names may change between versions.
Checklist
- Pick the most specific trigger available.
- For "On create and edit", always set the When updating field.
- Narrow records with Before Update Domain and Apply on.
- For time-based rules, run the scheduled action manually once after saving.
- Prefer built-in actions over Execute Code.
- Make code idempotent and log what it does.
- Test on a copy with a single record first.
- Document every rule in its Notes tab.
Our take
At JZ Webservices we see automation rules as the cheapest way to remove repetitive work in Odoo, as long as each rule is small, named clearly and tested on a copy first. Complex logic usually belongs in a proper module rather than in code snippets stored in the database.