Understanding Actions in Odoo

Muhammad Abdullah Arif
4 min readJun 5, 2024

--

In Odoo, actions are pivotal in defining the system’s response to user activities, such as logging in, clicking a button, or selecting an invoice. These actions can either be stored in the database or returned as dictionaries in methods like button actions.

All actions share two essential attributes:

  • Type: This attribute categorizes the action and determines how it is interpreted and which fields are applicable.
  • Name: A brief, user-readable description of the action, often displayed in the client interface.

Forms of Actions

Actions in Odoo can be represented in four forms:

  1. False: Closes any currently open action dialog.
  2. String: If it matches a client action tag, it is interpreted as such; otherwise, it is treated as a number.
  3. Number: Reads the corresponding action record from the database, which can be a database identifier or an external ID.
  4. Dictionary: Executed as a client action descriptor.

Bindings

Actions also have optional attributes to integrate them into a model’s contextual menu:

  • binding_model_id: Specifies the model the action is bound to.
  • binding_type: Determines the contextual menu where the action appears (e.g., action or report).
  • binding_view_types: A list of view types (e.g., list, form) where the action is available.

Window Actions (ir.actions.act_window)

Window actions are the most common and are used to present a model’s views. Key fields include:

  • res_model: The model to present views for.
  • views: A list of (view_id, view_type) pairs specifying the views to use.
  • res_id (optional): Specifies a particular record to load.
  • search_view_id (optional): Specifies a particular search view.
  • target (optional): Determines where the views open (e.g., current, fullscreen, new).
  • context (optional): Additional context data for the views.
  • domain (optional): Filters to apply to view search queries.
  • limit (optional): Number of records to display by default.

Examples:

# Open customers with list and form views
{
"type": "ir.actions.act_window",
"res_model": "res.partner",
"views": [[False, "tree"], [False, "form"]],
"domain": [["customer", "=", true]],
}

# Open a specific product's form view in a new dialog
{
"type": "ir.actions.act_window",
"res_model": "product.product",
"views": [[False, "form"]],
"res_id": a_product_id,
"target": "new",
}
<record id="action_product_product" model="ir.actions.act_window">
<field name="name">Product</field>
<field name="res_model">product.product</field>
<field name="view_mode">tree,form</field>
<field name="domain">[]</field>
<field name="context">{}</field>
<field name="help" type="html">
<p class="o_view_nocontent_smiling_face">
Add a new Product
</p>
</field>
</record>

URL Actions (ir.actions.act_url)

URL actions open a specified URL via an Odoo action. Key fields include:

  • url: The address to open.
  • target (default=new): Determines how the URL opens (e.g., new window, same window, download).

Example:

# Open Odoo's homepage in the current window
{
"type": "ir.actions.act_url",
"url": "https://odoo.com",
"target": "self",
}

Server Actions (ir.actions.server)

Server actions execute various operations, such as running Python code or creating/updating records. Key fields include:

  • id: The database identifier of the server action.
  • context (optional): Context data for the action.

Example:

# Server action to raise a warning with a partner's name
<record model="ir.actions.server" id="print_instance">
<field name="name">Res Partner Server Action</field>
<field name="model_id" ref="model_res_partner"/>
<field name="state">code</field>
<field name="code">
raise Warning(record.name)
</field>
</record>

Report Actions (ir.actions.report)

Report actions trigger the generation and printing of reports. Key fields include:

  • name: The report’s file name.
  • model: The model the report is about.
  • report_type (default=qweb-pdf): The type of report (PDF or HTML).
  • report_name: The QWeb template for rendering the report.

Client Actions (ir.actions.client)

Client actions are implemented entirely on the client side and triggered by a tag. Key fields include:

  • tag: The identifier of the client action.
  • params (optional): Additional data for the client action.
  • target (optional): Determines where the action opens (e.g., current, fullscreen, new).

Example:

# Start the Point of Sale interface
{
"type": "ir.actions.client",
"tag": "pos.ui"
}

Automated Actions (ir.cron)

Automated actions run on a predefined schedule. Key fields include:

  • name: The name of the automated action.
  • interval_number: The frequency of execution.
  • interval_type: The unit of measure for the frequency (e.g., minutes, hours).
  • numbercall: Number of times to run the action (-1 for indefinitely).
  • model_id: The model on which the action is called.
  • code: The code content of the action.

Example:

# Automated action to call a method on the model
model.<method_name>()

By understanding these various types of actions and their configurations, you can effectively harness the power of Odoo to automate and streamline your business processes.

Click on the link below to discover a wealth of knowledge and explore a variety of engaging topics.

Medium Profile: Muhammad Abdullah Arif — Medium

Stay Up-to-Date with Muhammad Abdullah Arif’s Latest Publications — Subscribe Now! (medium.com)

If you wish to offer your support, kindly click on the link below to treat me to a coffee! ☕️😊

https://www.buymeacoffee.com/smuhabdullah

I wish you all the best in your future endeavours.

--

--

Muhammad Abdullah Arif
Muhammad Abdullah Arif

Written by Muhammad Abdullah Arif

Python developer. The facts are the facts but opinions are my own.

No responses yet