Skip to Content
Menu
This question has been flagged
1 Reply
7150 Views

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:



Avatar
Discard
Best Answer

Hi,

Please try like this,

var model = new Model("test.activity").call("get_func",["do_something"]);

you can refer this, https://www.odoo.com/documentation/12.0/howtos/web.html#communication-with-the-odoo-server

Thanks

Avatar
Discard
Related Posts Replies Views Activity
0
Aug 22
1050
1
Jul 22
7886
0
Jul 20
2387
1
Sep 19
9689
3
Dec 23
44230