What are the Types of Actions in Odoo 18

What are the Types of Actions in Odoo 18

In Odoo, actions determine how the system responds to user activities, such as clicking a button, navigating a menu, or selecting a record. These actions can either be stored in the database or directly returned as Python dictionaries in method calls. Odoo provides various types of actions, each with distinct functionalities tailored to specific use cases. Below is a detailed explanation of these action types.

1. Window Actions (ir.actions.act_window)

Window actions are the most commonly used type, enabling the display of views (e.g., list, form, kanban) for a particular model. They allow navigation to model-specific views with optional filters or predefined behaviors.

Key Fields
  • type: Specifies the action type, always set to “ir.actions.act_window”.
  • res_model: The model to which the action applies.
  • views: A list of views to display, specified as pairs of view IDs (or False for defaults) and view types (e.g., “list”, “form”).
  • domain: Filters the records displayed by the action.
  • context (optional): Adds default values or parameters for the action.
  • name (optional): The label for the action in the UI.
  • target (optional): Specifies where the action opens:
    • current: Opens in the same window (default).
    • new: Opens in a new window.
    • inline: Opens within the current view.

Example: Displaying Customers in List and Form Views

python

Copy code

{

“type”: “ir.actions.act_window”,

“res_model”: “res.partner”,

“views”: [[False, “list”], [False, “form”]],

“domain”: [[“customer”, “=”, True]],

}

This action displays customers in a list and form view, filtered to show only customer records.

2. URL Actions (ir.actions.act_url)

URL actions are used to open external or internal URLs in a browser. These actions can be triggered to navigate to external websites, download files, or open resources in a new tab or the current page.

Key Fields
  • url: The URL to open.
  • target (default=new): Determines how the URL opens:
    • new: Opens in a new window or tab.
    • self: Opens in the current window/tab, replacing content.
    • download: Triggers a file download.

Example: Opening a Website URL

python

Copy code

{

“type”: “ir.actions.act_url”,

“url”: “https://odoo.com”,

“target”: “self”,

}

This action replaces the current page content with the Odoo homepage.

3. Server Actions (ir.actions.server)

Server actions are used to execute Python code or perform server-side operations. They enable dynamic actions like record creation, updates, or method execution on models.

Key Fields
  • name: Name of the action (appears in logs or menus).
  • model_id: The model on which the action executes.
  • state: Defines the state of the action, typically set to “code” for Python execution.
  • code: Python logic or method calls executed when the action is triggered.
Common Use Cases
  1. Execute Python Code: Custom logic execution.
  2. Create New Records: Automatically add new records with predefined values.
  3. Update Existing Records: Modify record fields based on specific conditions.
  4. Trigger Multiple Actions: Execute a sequence of server actions.

Example: Raising a Warning with the Partner’s Name

xml

Copy code

<record model=”ir.actions.server” id=”print_instance”>

<field name=”name”>Partner Warning</field>

<field name=”model_id” ref=”model_res_partner”/>

<field name=”state”>code</field>

<field name=”code”>

raise Warning(record.name)

</field>

</record>

4. Client Actions (ir.actions.client)

Client actions handle client-side functionality, such as navigation, user interface updates, or launching specific client modules. These actions rely on the client for execution and are typically associated with JavaScript components.

Key Fields
  • type: Always set to “ir.actions.client”.
  • tag: A client-side identifier for the action (e.g., starting POS or other modules).
  • params (optional): Additional data passed to the client.
  • target (optional): Determines the display behavior:
    • current: Opens in the main content area.
    • fullscreen: Opens in full-screen mode.
    • new: Opens in a popup or dialog.

Example: Launching the Point of Sale (POS) Interface

python

Copy code

{

“type”: “ir.actions.client”,

“tag”: “pos.ui”,

}

This action launches the POS interface.

5. Report Actions (ir.actions.report)

Report actions allow the generation of reports in formats like PDF or HTML. These actions are commonly found under the “Print” menu and are linked to a specific model.

Key Fields
  • name: The name of the report file.
  • model: The model the report relates to.
  • report_type (default=qweb-pdf): Specifies the report format.
  • report_name: The external ID of the QWeb template used for rendering.
  • print_report_name (optional): Python expression for dynamic file naming.
  • attachment_use: If True, stores the report to reuse without regeneration.

Example: Project Report

xml

Copy code

<record id=”action_report_project” model=”ir.actions.report”>

<field name=”name”>Project Report</field>

<field name=”model”>project.project</field>

<field name=”report_type”>qweb-pdf</field>

<field name=”report_name”>module_name.project_report_template</field>

<field name=”binding_model_id” ref=”model_project_project”/>

</record>

This action generates a PDF report for project records.

6. Scheduled Actions (ir.cron)

Scheduled actions, also known as automated actions, execute tasks at defined intervals. They are used for background operations such as sending emails, updating records, or performing routine checks.

Key Fields
  • name: Name of the scheduled action.
  • interval_number: The frequency of execution.
  • interval_type: Time unit (e.g., minutes, hours, days).
  • model_id: The model on which the action operates.
  • code: Python logic or method calls executed automatically.

Example: Monthly Sales Report Automation

xml

Copy code

<record id=”ir_cron_send_report” model=”ir.cron”>

<field name=”name”>Send Monthly Sales Report</field>

<field name=”model_id” ref=”model_sale_order”/>

<field name=”state”>code</field>

<field name=”code”>

model.send_monthly_sales_report()

</field>

<field name=”interval_number”>1</field>

<field name=”interval_type”>months</field>

<field name=”user_id” ref=”base.user_root”/>

<field name=”active” eval=”True”/>

</record>

This action automatically sends a sales report every month.

Conclusion

Odoo’s action framework is versatile, enabling developers to design responsive and customizable applications. From simple window actions to complex server-side automation, each action type plays a specific role in enhancing business workflows.


Follow me on LinkedIn for more latest updates

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *