Hi,
You can add a button and bind it with the python method using JS.
Ex:
Create an XML (button_template.xml) file under "/static/src/xml" and add following code:
<t t-name="my_custom_button">
<button class="btn btn-primary btn-sm o_tree_custom_button" type="button">My Button</button>
</t>
Add above file in "__manifest__.py" in qweb section:
'qweb': [
'static/src/xml/*.xml',
]
Now, create a JS file under "/static/src/js (button_render.js)" and register this JS in web asset:
<template id="button_render_js" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/my_module/static/src/js/button_render.js"/>
</xpath>
</template>
Now, add following code in your JS file:
odoo.define('my_custom_module.my_custom_button', function (require) {
"use strict";
var core = require('web.core');
var ajax = require('web.ajax');
var ListView = require('web.ListView');
var Dialog = require('web.Dialog');
var web_client = require('web.web_client');
var _t = core._t;
var _lt = core._lt;
var QWeb = core.qweb;
ListView.include({
render_buttons: function($node) {
this._super($node)
var self = this;
if (this.$buttons && this.model == 'sale.order') {
this.$GetIdsbutton = $(QWeb.render("my_custom_button", {'widget': this}));
this.$GetIdsbutton.appendTo(this.$buttons);
$(this.$buttons).find('.o_tree_custom_button').on('click', function() {
// Following route / method will be called when button is clicked
ajax.jsonRpc('/web/my_custom_method', 'call', {}).done(function() {
self.reload_content()
})
});
}
},
})
});
Now, create a controller file (controllers/main.py) and add a route method using "/web/my_custom_method"
# -*- coding: utf-8 -*-
from odoo import http
from odoo.http import request
class CustomController(http.Controller):
@http.route('/web/my_custom_method', type='http', method='POST',
auth='user', csrf=False)
def custom_method(self, **kw):
# Your code goes here
return True
Hope this will help you.
Let me know for any guidance.