Hello everybody ! I hope someone will can help me.
I want to execute a python function by clicking on a button in xml template, using JavaScript but it does not work.
Here is my test_js.js file:
try {
console.log(">>TRY");
odoo.define('reference.js', function(require) {
'use strict';
console.log('>>>>>FINE');
var form_widget = require("web.form_widget");
var core = require("web.core");
var _t = core._t;
var QWeb = core.qweb;
var Model = require('web.Model');
form_widget.WidgetButton.include({
on_click: function() {
if(this.node.attrs.custom === "click"){
var model = new Model("test.activity").get_func("do_something")();
console.log(">>>>OK: " + model);
return;
}
this._super();
},
});
});
}
catch(err) {
console.log(">>ERR: " + err.message);
}
And here is my qweb xml template:
<?xml version="1.0" encoding="UTF-8"?>
<templates>
<t t-extend="mail.ChatThread.Message">
<t t-jquery=".o_mail_info" t-operation="append">
<script type="text/javascript" src="/new_module/static/src/js/test_js.js"></script>
<button class="btn btn-primary" name="button" custom="click">TEST</button>
</t>
</t>
</templates>
But I don't understand. I can see "TRY" in my JS console, but everything else doesn't work. I have no error in catch, no other output in JS console, nothing, seem has no effect. What's go wrong with my code ? can anyone explain me or, better, solve this ?
Thank you so much in advance.
Bye.
UPDATE: