Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
1 Răspunde
9101 Vizualizări

I want to call python function in java script. I tried but it's not working.

Here is the my  PY code: 

class CoustomModel(models.Model):
_name = 'custom.model'

new_field = fields.Char(string="test", required=False, )


@api.model
def my_function(self):
print("Hello Word");


Here is the JavaScript
odoo.define('visio_learn_javascript.SampleWork', function (require) {
"use strict";

var rpc = require("web.rpc")
var Model = require('web.Model');

var custom_model = new Model('custom.model');
custom_model.call('my_function');

});
Imagine profil
Abandonează
Cel mai bun răspuns

Hi,

To call a Python function in JavaScript, I suggest you to use JSONRPC (see the example in the below code)

ajax.jsonRpc('/web/dataset/call_kw', 'call', {
'model': 'custom.model',
'method': 'my_function',
'args': [],
'kwargs': {
'context': {},
}
}).then(function (data) {
// Do something here
});

Best regards!

Imagine profil
Abandonează
Autor

This is not working for me.

how about calling a python function from controllers in Javascript?

Can you give us examples?

Thanks

Related Posts Răspunsuri Vizualizări Activitate
1
dec. 22
3474
0
dec. 20
50
0
dec. 15
13008
2
aug. 24
6194
1
oct. 22
23923