Type Of Actions In Odoo 16 ERP

Type Of Actions In Odoo 16 ERP

This blog describes different types of actions in Odoo 16. The user performs actions, and the system reacts based on the user’s actions. These responses are also called actions.

Odoo 16 has six actions

1. Server Actions (ir.actions.server)

2. Client Actions (ir.actions.client)

3. Automatic Actions (ir.cron)

4. URL Actions (ir.actions.act_url)

5. Report Actions (ir.actions.report)

6. Window Actions ( ir.actions.act_window )

These actions are stored in the database and are returned directly as a dictionary when you call the methods associated with them, such as button methods.

type-of-actions-in-odoo-16-erp-cybrosys

The action creation form has two required fields.
1 . Name: The action name displayed on the client interface.
2. Type: The action type defines the type or category of the current action.
Now we can discuss about the different types of action,

1. Server Action(ir.actions.server)

Server Actions work on the base model and provide different types of actions that can be executed automatically.
For example, if you want to add actions to the More context menu and use basic action rules. 
Available server actions are: 
1. Python code execution: – A block of Python code is executed.
2. Create New Record: – Create a new record with new values.
3. Write to the record: – update the value of the record. 
4. Perform some actions: – Define actions that trigger other server actions.
Allows launching complex server code from a valid action location. There are only two fields related to customers.
Id:-  the in-database identifier of the server action to run.
Model_id :- The Odoo model linked to the action.
context :- It’s an optional part, and it’s used when running the server action .
State options are-
1. code: Execute the python code given in the argument of code.
2. object_create: It is used to create a new record of the model crud_model_id and  following field_line specification.
3. object_write: it is used to update the current record of the following field_lines specifications.
4. multi: Performs some action specified by the child_ids argument.
Code: Used to write Python code, execute that code, and execute that code when an action is executed.
Example: 
XML : –
<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>
A code segment can define a variable called action that is returned to the client as the next action to execute.
<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">        if record.some_condition():            action = {                "type": "ir.actions.act_window",                "view_mode": "form",                "res_model": record._name,                "res_id": record.id,            }    </field></record>

2. Client Action( ir.actions.client)

Client actions are used to trigger actions that are fully implemented on the client.
tag: client-side identifier for the action, an arbitrary string that the client needs to know how to respond.
params: A Python dictionary containing additional data to be sent to the client along with the client action tag
target:
Target options are,
current: Used to open the main content area.
new: it is used to open the window like a popup.
full screen: it is used to open a window in fullscreen mode.
main: It is used to open the main content area without breadcrumbs.
{
    "type": "ir.actions.client",
    "tag": "pos.ui"
}

3. Automated Action( ir.cron)

Automated action is triggered automatically on a predefined frequency.
1. name
2. interval_number
3. interval_type
4. numbercall
5. doall
6. model_id
name: Name of the automated action (Mainly used in log display)
interval_number: Number of interval_type uom between two executions of the action
interval_type: Unit of measure of frequency interval (minutes, hours, days, weeks, months)
numbercall: How often this action should be performed. Set to -1 to run the action indefinitely.
doall: A Boolean value that indicates whether the failed action should be executed when the server is restarted.
model_id: Model on which this action will be called model_id .
Code : Code content of the action. It can be a simple call to the model’s method:
model.<method_name>()

4. URL Action(ir.actions.act_url)

The URL action is used to allow opening a website or webpage(URL) via an Odoo action. It can be customized via two fields, the first one is URL, and the other one is the target.
url: It is the address to open when activating the action
target: There are two types of target windows in url action , the first one is self and other one is the target.
self: It opens the current window with current content.
new: It redirects an address with a new window or new page.
{
    "type": "ir.actions.act_url",
    "url": "https://odoo.com",
    "target": "self",
}
xml :
<record id="action_website" model="ir.actions.act_url">
    <field name="name">Website</field>
    <field name="url">https://odoo.com</field>
    <field name="target">self</field>
</record>

5. Report Action( ir.actions.report)

Report actions used to trigger the printing of a report. 
xml:
<record id="pos_invoice_report" model="ir.actions.report">
    <field name="name">Invoice</field>
    <field name="model">pos.order</field>
    <field name="report_type">qweb-pdf</field>
    <field name="report_name">point_of_sale.report_invoice</field>
    <field name="print_report_name">'Invoice - %s' % (object.name)</field>
</record>
name – The name of the report action, and it is the mandatory field.
model – It is a mandatory field, and it’s the model your report will be about.
report_type – qweb-html and qweb-pdf.
report_name  – It is a mandatory field, and it is the name of the qweb template used to render the report.
print_report_name – It uses the  python expression defining the name of the report.
group_id –  group allows for the current report.
papperformat_id – field to the paper format you wish to use for this report
attachment – python expression that defines the name of the report.
attachment_use – If the value is set to True, the report will be generated only once the first time it is requested and will be reprinted from the saved report instead of being regenerated each time.

6. Window Action(ir.actions.act_window)

Window actions are the most common actions and trigger different views of the model. i.e., it is used to visualize the model in different types of views.
Its fields are: –
1. res_model 
2. views
3. search_view_id
4. context
5. target
6. domain
7. limit
res_model :- Res model for representing this action window.
views :- It is the list of view_type and view_id pairs.The second element of each pair is the view category [tree, form, graph, etc.], and the first element is an optional database ID or false.
search_view_id :- It is the optional part, and also it is an id, name pair, id is the database identifier of a specific search view to load for the action. Defaults to fetching the default search view for the model.
context :- It is not required, and additional context data to pass to the views.
target :- we can define a different option for target windows
a) new : It opens a window with new edit modes
b) current : It opens the regular form views
c) fullscreen : It will open the window in fullscreen mode
d) main : without breadcrumbs it will open the main content area
Limit :- number of records to display in lists by default. Defaults to 80 in the web client.
domain :- It is used to filter the domain to implicitly add to all view search queries.
to open the form view of a specific product in a new dialog:
Example:
{
    "type": "ir.actions.act_window",
    "res_model": "product.product",
    "views": [[False, "form"]],
    "res_id": a_product_id,
    "target": "new",
}
 If you plan to allow multiple views for your model, prefer using ir.actions.act_window.view instead of the action view_ids .
<record model="ir.actions.act_window.view" id="test_action_tree">
   <field name="sequence" eval="1"/>
   <field name="view_mode">tree</field>
   <field name="view_id" ref="view_test_tree"/>
   <field name="act_window_id" ref="test_action"/>
</record>

Thisis all about the type of actions in Odoo 16.

Similar Posts

Leave a Reply

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