Add Custom Button in Tree or Header of a Kanban in Odoo16
We all know that, in Odoo, we can customize and add buttons to different views to achieve different Functionality as per our requirements. The functionalities of buttons may include opening a new pop-up Or wizard, changing the states of the records, printing documents, and so on. In this blog, We will look into the steps involved in adding a custom button in the tree or Header of Kanban in Odoo. In this example, we will add a button in the tree and Kanban header to open a wizard.
Adding a button in the list view
1. We are extending the ‘ListController’ from the module ‘web’.
2. We have added the t-on-click function named as ‘OnTestClick’. This is the function that will be called when clicking on the button. ‘doAction’ is used to open the specific action window when clicked on the button.
3. We have also added a new class named ’SaleListController’
4. The view is then to be added to the registry, by specifying the controller name, i.e., ‘ButtonTemplate’.
Tree View in Custom Module
Adding a button in the Kanban view
- With the kanban view, create an XML (custom_kanban_button.xml) file wherein we will inherit the kanban view and add our custom button.
- This XML file is to be placed under the static → src →XML folder of the module.
- The image below shows the content of the above XML file.
The next step is to create a .js (custom_kanban_extend.js) file to add the functionality of the custom button.
Kanban in Odoo – View of the Model ‘sale. order’.
After the above customizations, our custom button will be visible in the list and Kanban view of the model sale. order as shown in the below images.
List / Tree View
Kanban in Odoo
For e.g.:
After that, While clicking the button ‘OPEN WIZARD’ from both the views, i.e., the list and kanban views, it will open the wizard which we have specified in the do Action function in the js files.
"Unlock the Full Potential of Your Business with Odoo ERP!"
"Get a Cost Estimate for Your ERP Project, Absolutely FREE!"
Get a Free Quote