Enable Dark Mode!
how-to-configure-client-action-in-odoo-17.jpg
By: Risvana AR

How to Configure Client Action in Odoo 17

Technical Odoo 17

In Odoo, a client action refers to a set of actions or operations that are executed on the client side of the application. Odoo is an open-source ERP (Enterprise Resource Planning) and business management software, and it uses a client-server architecture. The client-side actions in Odoo are typically defined using JavaScript and XML. OWL is primarily used for representing and reasoning about knowledge in a machine-readable way. However, the mention of web frameworks, services, core components, and hooks suggests a broader context, possibly related to web development.
Basic XML menu items use matching widget actions to make up for client activities. Here, we'll look at how to add a menu to the sales order's menu. selecting the sales orders, displaying them, and putting them to use.
Add a menu to the views/views.xml file in the directory of the view to continue.
Filename: client_action_views.xml
<?xml version="1.0" encoding="utf-8"?>
<odoo>
	<!--	Action to show the Dashboard-->
	<record id="advanced_dashboard_action" model="ir.actions.client">
    	<field name="name">Advanced Dashboard</field>
    	<field name="tag">advanced_dashboard</field>
	</record>
	<!--	Menu Item to show the dashboard menu in the module-->
	<menuitem name="Dashboards" id="advanced_dashboard_menu"
          	sequence="1" action="advanced_dashboard_action"/>
</odoo>
We can use the parent parameter in the menu items, and you can provide the correct menu id based on the model if you add the action using the parent menu.
Js File: client_action.js 
when we create a Dashboard action (name to be determined) to the ir.actions.client model. When the menu was clicked, the advanced_dashboard tag—which is utilized in the widget to load or call the action stated in the widget—was also added. With the aid of this tag, the widget's suggested action (JS file) will be loaded or called.
/** @odoo-module */
import { registry} from '@web/core/registry';
import { useService } from "@web/core/utils/hooks";
const { Component, mount} = owl
export class AdvancedDashboard extends Component {
	setup(){
    	this.action = useService("action");
    	this.rpc = this.env.services.rpc
	}
	loadData(){
    	let self = this;
     	rpc.query({
        	model: 'partner.dashboard',
        	method: 'get_values',
        	args:[]
        	}).then(function(data){
            	console.log(data, 'dataaaa')
            	self.AdvancedDashboard.data = data;
    	});
	}
}
AdvancedDashboard.template = "client_action.advanced_dashboard"
registry.category("actions").add("advanced_dashboard", AdvancedDashboard)
We are extending the Component class to create the widget. I have specified a template (AdvancedDashboard) that will be displayed when this activity is carried out.
The template (advanced_dashboard), which is subsequently added to the main Template's table view class (AdvancedDashboard), receives the data by using the load data method from the start function to retrieve it from the Python code.
It is now necessary to specify the Python function file and the qweb template that the RPC will use. Thus, I'm going to begin by generating a models/filename.py Python file.
from odoo import api, fields, models
class EmployeeDashboard(models.Model):
	_name = 'partner.dashboard'
	_description = 'Partner Dashboard'
	user_id = fields.Many2one('res.users', string='Users')
	name = fields.Char(string='Partner Name')
	@api.model
	def get_values(self):
    	data = self.env['partner.dashboard'].search([])
    	# we can add the values to the dashboard
    	return data.read()
In this instance, we can build a new model and put in place a function that runs a short query and appends each record to the list that's finally produced.
This will make this list accessible over RPC, and the data will be received by the qweb template.
Some keywords used by the client actions: 
tag: it refers to a unique identifier or key assigned to a specific action or event on the client side of a software application. This identifier serves as a way for the client-side code to recognize and handle different actions or events appropriately. 
params (optional): In Python, a dictionary is a suitable data structure for representing key-value pairs, making it convenient for sending structured data
target (optional):
1. Open in the main content area (current): This implies that the client action should be displayed within the main content area of the application. It's the default behavior if the display mode is not explicitly specified.
2. Open in full-screen mode (fullscreen): This suggests that the client action should take up the entire screen when executed.
3. Open in a dialog/popup (new): This indicates that the client action should be displayed in a separate dialog or popup window.
Additionally, there's a mention of using "main" instead of "current" to clear the breadcrumbs. Breadcrumbs are often used in navigation to show the user's location within the application's hierarchy. If "main" is used, it might indicate that the action should be treated as a top-level navigation, potentially clearing any existing navigation history or breadcrumbs.
The template should be defined first (in static/src/xml).
Filename: client_action.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- Template for the Advanced Dashboard -->
<templates id="template" xml:space="preserve">
<t t-name="client_action.advanced_dashboard">
    	<div>
        	<span>Test Case</span>
        	<h1><center><span>Partner Details</span></center></h1>
    	</div>
<!--	You can add the templates here-->
	</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': [
        	'client_action/static/src/js/client_action.js',
        	'client_action/static/src/xml/client_action.xml',
    	],
},
This is one method of defining a client's activity. This method can result in various kinds of activity. You can simply create client action in Odoo 17 by referring to the blog.


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



1
Comments

Ayman

Hello, When I use the rpc.query, it always triggers an error 404 not found, even though the model is registered, Should I enable something in the settings for the rpc? Thank you

28/12/2023

-

11:18PM



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