Enable Dark Mode!
types-of-actions-in-odoo.png
By: Ajmal JK

Types of Actions in Odoo

Technical

Actions refer to the behavior of the system in response to user actions. Different types of actions in odoo are,

1. Server Actions
2. Client Actions
3. Window Actions
4. URL Actions
5. Report Actions
6. Automated Actions

Server Actions (ir.actions.server)
Ir.actions.server represents the server actions model. Server action works on a base model and offers various types of actions that can be executed automatically.

Important fields:
usage: Boolean field to find out if it is a Server action or Scheduled action.

state: Selection field to find out the type of action. Options are,
    > code: Executes python code.
    > object_create: Create a new Record
    > object_write: Update the record
    > multi: Executes several actions.

model_id: Model on which the server actions run.
(It can be represented as module_name.model_<model_name>
Example: purchase.model_purchase_order)

crud_model_id: Model for record creation or updation.

code: Field to write python code which the action will execute.
some predefined variables can be used in this field while writing the python code.
    > env: odoo environment variable
    > model: model object linked to the action 
    > record: record on which the action is triggered, can be void.
    > records: recordset of all records which the action is triggered in multi-mode, can be void.
    > Also available DateTime, dateutil, time, timezone like python modules.
    > log for logging function and  Warning for raise warning.

The server action can perform several types of actions like, 
1. ‘Execute Python Code’: a block of python code that will be executed
2. ‘Create a new Record’: create a new record with new values
3. ‘Write on a Record’: update the values of a record
4. ‘Execute several actions’: define an action that triggers several other server actions.

For example, if one needs to print a report by clicking a menu item he can use the server action to do it. The action of the menu item should be set as the server action, like

<record id="ir_actions_server_print_report" model="ir.actions.server">
     <field name="name">Print Sale Report</field>
     <field name="type">ir.actions.server</field>
     <field name="model_id" ref="sale.model_sale_order"/>
     <field name="state">code</field>
     <field name="code">
             action = model.get_sale_report()
     </field>
</record>

This will execute the method get_sale_report() in the model sale order. In this method, one can define the action to display the report.

Client Actions (ir.actions.client)
Ir.actions.client represents the client action model. Client actions basically trigger the actions implemented by the client. These are basically menu-items defined in XML and the corresponding actions are mapped to a widget.

Important fields:
tag: An arbitrary string, interpreted by the client according to its own needs and Wishes.
Example: ‘reload’, ‘reload_context’, ‘change_password’, 
‘bank_statement_reconciliation_view’

target: Selection field refers to the type of Target window. Options are,
    > current: Client action will open in the main content  area
    > new: will open in a dialog/popup window.
    > fullscreen: will open in fullscreen mode.
    > main: open in the main content area (without breadcrumbs)

res_model: Refers to the destination model, optional field.
For example, a simple client action to reload the whole interface is 

return {
    'type': 'ir.actions.client',
    'tag': 'reload',
}

One can also create custom client actions according to their need. For this, we have to define an action and need to map this action to a widget.
Example:
<record id="custom_client_action" model="ir.actions.client">
         <field name="name">Custom Action</field>
         <field name="tag">my_custom_tag</field>
</record>

 Here defined custom tag ‘my_custom_tag’ to represent the new client action.Now we have to map this tag to a widget.

odoo.define('my_module.MyCustomAction',  function (require) {
"use strict";
var AbstractAction = require('web.AbstractAction');
var core = require('web.core');
var  MyCustomAction = AbstractAction.extend({
        template: "MyCustomAction",
         start: function () {
                // Actions to do
          },   
  // Functions according to the working of the widget.        
}):
  // Following code will attach the above widget to the defined client action

core.action_registry.add("my_custom_tag", MyCustomAction);
}):

URL Actions (ir.actions.act_url)
Ir.actions.act_url represents the url action model.These type of actions allows to open a URL (website/web page) via an Odoo action.

Important fields: 
url: The action URL 
target: Selection field to represent the action target.
    > new: opens the given URL in a new window/page.
    > Self: replaces the current content with the URL page.
For example if one needs to redirect to a website in a button click, then have to  return the URL action on the button click method, like

return {
   'type': 'ir.actions.act_url',
   'target': 'self',
   'url': 'https://cybrosys.com',
}

Also one can redirect to the controller routes (web pages) by using the URL action.

For example, if one needs to redirect to the shop in the website from the product master, can use the URL action as, 

return {
   'type': 'ir.actions.act_url',
   'target': 'self',
   'url': '/shop/product/%s' % product.id,
}

Above action will return to the shop page of the specified product.

Window actions (ir.actions.act_window) are the most common action types. It is used to present the visualization of the data models through different types of views.

Report actions (ir.actions.report) are the actions which trigger the printing actions of a report. By using different fields one can represent the type, name, paper format, etc of the report.Field ‘report_type’ represents the type of the report whether it is a PDF report (qweb-pdf) or HTML report (qweb-html).

Automated Actions (ir.cron) refers to the action that triggered automatically on a predefined time interval. Visit the Blog Automated Actions In Odoo to know more about the automated actions.


If you need any assistance in odoo, we are online, please chat with us.



0
Comments



Leave a comment

 


whatsapp
location

Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635

location

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

location

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message