Hi,
Is it possible to execute a JavaScript function while clicking on a menu item?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
Hi,
Yes it is possible by creating a client action for the menuitem.
For live examples you can refer the apps below
https://apps.odoo.com/apps/modules/13.0/hrms_dashboard/
https://apps.odoo.com/apps/modules/13.0/base_accounting_kit/
For example you can refer the code below.
Create a js file
odoo.define('model_name.action_name', function (require){
"use strict";
var core = require('web.core');
var AbstractAction = require('web.AbstractAction');
var NewAction = AbstractAction.extend({
init: function(){
this.function_name();
},
function_name: function(){
//Write the code here to preform menu item click.
});
core.action_registry.add('client_action_tag', NewAction);
});
});
Create a record with model ir.actions.client and specify the record id on menu item action.
<record id="action_menu" model="ir.actions.client">
<field name="name">Render Template</field>
<field name="tag">client_action_tag</field>
</record>
<menuitem id="menu_client_action"
name="Client action Menu"
action="action_menu"
parent="model_name.parent_menu"/>
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!
Đăng ký
1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.