First Create button where ever you want to create with some modifications.
<button string="Click" custom="click"/>
Then create one JS file that will contain following code.
odoo.define('YOUR_MODULE.FILENAME', function (require) {
"use strict";
var form_widget = require('web.form_widgets');
var core = require('web.core');
var _t = core._t;
var QWeb = core.qweb;
form_widget.WidgetButton.include({
on_click: function() {
if(this.node.attrs.custom === "click"){
// YOUR CODE
return;
}
this._super();
},
});
});
i have posed this type of question, i got this solution this answer working partially. please refer this link how to write events for formview inside header buttons? odoo 10