Automated Actions

Automated Actions (and their close cousin, Server Actions) are a powerful way to add functionality to Odoo without any programming (or with only a few lines of Python code).

Also, if you are using Odoo Online you cannot do development or install third-party add-ons but you can use Automated Actions (and Server Actions).

Automated Actions can be used to enhance and customize Odoo functionality in several ways:

Automated Actions can be triggered on Creation, Deletion or Update of a database record in the specified Odoo Model (database table), and can also be based on Form Modification or a Timed Condition.

Automated Actions can be conditioned on domains and / or “watched fields”, which makes it possible to define “business rules” (an action for one group of customers, or one type of product, etc.) and more complex logic can be added with Python code.

Actions

  1. Update fields on the selected model (database table)
    1. Set a fixed value (can be based on rules)
    2. Derive a new value:
    3. Clear a field
  2. Create new records on another table
  3. Send email (a useful feature, but email templates can be tricky to setup)
  4. Add followers (example on Odoo Help Forum)
  5. Create activities (so a user can follow-up)
  6. Validation (needs Python)
  7. Customize document numbering (needs Python)
  8. Other Python functions
    1. Copy Records
    2. Sort data
  9. It’s also possible to execute multiple server actions (for the same Model)

Getting started

Start by enabling developer mode and navigating to Settings / Technical / Automated Actions.

Note: Every Automated Action is also a Server Action, which enables it to be added as a “contextual action” (example).

If you cannot find this option, you may need to install the module “Automated Action Rules”.

First remove the “Apps” filter by clicking on the ‘X’:

Then search for “Automated”

If it’s not installed, click on ‘INSTALL’.

Now you might want to try one of the examples (links above). Or if you want to understand more about Automated Actions, read on:

Automated Action

Model

Select the Model (database table)

Action To Do

  • Execute Python Code (see below)                             
  • Create                                          
    • Create a new record in a specified model (db table). You specify the fields in the ‘Data to Write‘ tab.
  • Update the (current) Record                  
  • Execute several actions         
    • Trigger several other server actions
  • Send Email                                 
    • Automatically send an email (using a template)
  • Add Followers                           
  • Create Next Activity                                

Trigger Condition

This defines when the Automated Action can be triggered:

  1. On Creation [on_create]
  2. On Update [on_write]
  3. On Creation & Update [on_create_or_write]
  4. On Deletion [on_unlink]
  5. Based on Form Modification [on_change]
  6. Based on Timed Condition

Watched Fields

This was added in Odoo 13

This is optional, but if you specify any fields here the Automated Action will only be triggered if the value of these field(s) have changed.

Domains

For the first four trigger conditions, you can define the records to be selected using domains. Odoo will show you how many records meet the criteria and you can display a list of records to check whether your criteria is correct.

There are two domains:

  1. Before Update Domain (used for Updates only)
  2. Apply on

So it is possible to have “before” and “after” domains to trigger an action when a user makes a specific change (e.g. adding a salesperson to a customer – the field was blank before and now has a value).

Note that there are some limitations with domains if you create Automated Actions through the ‘front-end’ menu.

  • There is a pop-up dialog box which makes it easier to enter domains, but at the cost of limiting functionality.

Data to Write

The simplest way to update or write data is to select the fields from a list. This applies when the action is “Create” or “Update the Record”

Simple Python expressions can also be used

The first two lines are taking data from the record, the third line writes multiple (fixed) values to a many2many field, the last line takes data from the parent record. This is from the Add contacts to mailing lists example.

Python Code

Automated Actions can use a subset of Python. This is more powerful but requires a deeper understanding of Python. These are the commands that are available:

  • env: Odoo Environment
    • Information about current user and company, as per this example
  • model: Odoo Model (database table)
  • record: gives access to field values, e.g. record['company_id']
  • records: allows multiple records to be read / updated, as per this example
  • timedatetimedateutiltimezone: to retrieve date and time
  • log(message, level='info'): to record debug information in the ir.logging table
  • Warning: Display a Message (as per this example)
  • action = {...}
    • This allows you to call another Server Action for the same Model. The syntax is:
      • action = { "type": "ir.actions.server", "id": 372, }
        • 372 is the ID of the Server Action

But there’s no need to understand everything that can be done using Python. In fact, you can create Automated Actions without any Python at all.

Set customer lead time

  • Model = product.template
  • Trigger Condition = On Creation
  • Apply On (domain) = Can be Sold
    • Note that Odoo tells you that 94 records meet the criteria (and you can click here to view a list of those records)
  • Action To Do = Update the Record
  • Data to Write
    • Field = Customer Lead Time
    • Evaluation Type = Value
    • Value = 10

So we can see that using “Update the Record” is quite simple and requires only a basic knowledge of the Odoo database (but user-defined defaults can also be used to do something similar).

However, using simple Python expressions allows us to go beyond what can be done with user-defined defaults. Here we can use values from the current record, from a parent (e.g. update Sales Order Line with information from the Sales Order Header), from related Models (db tables) and environment variables.

Other Examples

This is quite powerful. It’s possible to create analytic accounts for sales orders, which replicates the standard functionality in Odoo to automatically create an Analytic Account for each project.

  • This example also contains some information about how to overcome a bug in Automated Actions.

There will be other business cases where this could be a good technique.

10 thoughts on “Automated Actions

  1. Can I set an automated action to automatically confirm a production order when I create it?
    I tried this Python code (I don´t know any python) but it doesn’t seem to do anything:
    model.action_confirm()

    What I need to do is to import several production orders in Confirmed stage so that it will trigger inventory rules. Would this be the better way to solve it?

    Like

  2. I’m not so familiar with Production Orders, but in theory this Python code should set orders to confirmed status:

    for rec in records:
    record[‘state’] = “confirmed”

    Like

    1. Hi Chris!
      I got an error message with that code, but I finally got it right (nearly by chance) with a server action and this code:

      records.action_confirm()

      “action_confirm” refers to the method associated to the confirmation button on the production order form.
      Thanks a lot for all the information and help, it was very usefull!!

      Like

  3. Hi Chris,

    Can I set an automated action to display a message which does not disrupt the process workflow on a delivery order? I tried using the raise a warning option but this stops the workflow. I just want to display a message after the delivery order is done.

    Thank you in Advance!

    Like

    1. I am not aware of any way to display a warning message “inline”, but there are some options:

      1. Add a message to the “chatter”, which means it will be visible to everyone,
      2. Send a message to the user (or to a group),
      3. Send an email to any specified email address (it’s probably best to create a group email address for this).

      I will try to add information on these options later.

      Like

  4. Hi, I noticed that for calculated fields, the trigger does not work.
    Eg. If a customer has a variable membership product and I want to use automated action to trigger a reminder email to be sent out 30 days before the membership expires.

    As a variable membership, the expiry date is calculated from the start date PLUS the membership duration.

    When I create an automated action using the “Based on Timed Condition” for Trigger Condition, it does not trigger.

    Is this a known limitation or am I just doing it wrong ?

    Thank you.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s