In Odoo, a client action denotes a set of tasks or operations performed on the client side of the application. Odoo is an open-source platform designed for ERP and business management that operates on a client-server architecture. Client-side actions are generally implemented using JavaScript and XML. While OWL is mainly utilized for encoding and reasoning about knowledge in a format suitable for machines, references to web frameworks, services, core components, and hooks imply a wider context, likely related to web development.
Basic XML menu items are linked to corresponding widget actions to facilitate client-side functionalities. Here, we will explore the process of adding a menu item to the sales order section, which includes selecting sales orders, displaying them, and utilizing them effectively.
Add a menu to the views/client_action_views.xml file in the directory of the view to continue.
Filename: client_action_views.xml
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<data>
<record id="dashboard_ir_actions_client" model="ir.actions.client">
<field name="name">Dashboards</field>
<field name="tag">event_dashboard.dashboard</field>
</record>
<menuitem name="Dashboards" id="advanced_dashboard_menu"
sequence="1" action="dashboard_ir_actions_client"/>
</data>
</odoo>
The parent parameter in menu items can be used to specify the appropriate menu ID based on the model when adding an action through a parent menu.
Js File: client_action.js
When creating a Dashboard action (name to be decided) within the ir.actions.client model, the advanced_dashboard tag is incorporated. This tag facilitates invoking or loading the specified action through the widget. By utilizing this tag, the designated action configured in the widget (through its associated JavaScript file) is activated or loaded upon clicking the menu.
To create the Dashboard, we are extending the Component class. A template has been defined to display during this activity.
/** @odoo-module */
import { registry} from '@web/core/registry';
import { Component } from "@odoo/owl";
export class AdvancedDashboard extends Component {
setup(){
}
}
AdvancedDashboard.template = "event_dashboard.advanced_dashboard"
registry.category("actions").add("event_dashboard.dashboard", AdvancedDashboard)
Some keywords used by the client actions:
* tag: It denotes a distinct identifier or key associated with a particular action or event on the client side of a software application. This identifier enables the client-side code to identify and manage various actions or events effectively.
* params (optional): In Python, dictionaries are an ideal data structure for organizing key-value pairs, providing a convenient way to handle structured data.
* target (optional):
1. Open in the main content area (current): This indicates that the client action is intended to appear within the application's main content area. This behavior is default unless a specific display mode is defined.
2. Open in full-screen mode (fullscreen): This indicates that the client action is meant to occupy the full screen upon execution.
3. Open in a dialog/popup (new): This signifies that the client action is intended to appear in a distinct dialog or popup window.
The use of "main" instead of "current" is mentioned as a way to reset breadcrumbs. Breadcrumbs are commonly utilized in navigation to show the user's position within the application's structure. Opting for "main" might imply that the action serves as a primary navigation point, potentially clearing previous navigation history or breadcrumb trails.
The template should be defined first (in static/src/xml).
Filename: client_action.xml
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="event_dashboard.advanced_dashboard">
<div>
<h1>Dashboard Rendered through client action</h1>
</div>
</t>
</templates>
And the last one, we can add those files in the __manifest__.py like this format
'data': [
'views/client_action_views.xml'
],
'assets': {
'web.assets_backend': [
'event_dashboard/static/src/js/client_action.js',
'event_dashboard/static/src/xml/client_action.xml',
],
},
This is one approach to defining a client action, which can lead to different types of activities. In Odoo 18, you can easily create a client action by following the guidance provided in the blog.
To read more about How to Configure Client Action in Odoo 17, refer to our blog How to Configure Client Action in Odoo 17.