تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
9056 أدوات العرض

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');

});
الصورة الرمزية
إهمال
أفضل إجابة

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!

الصورة الرمزية
إهمال
الكاتب

This is not working for me.

how about calling a python function from controllers in Javascript?

Can you give us examples?

Thanks

المنشورات ذات الصلة الردود أدوات العرض النشاط
1
ديسمبر 22
3458
0
ديسمبر 20
50
0
ديسمبر 15
12982
2
أغسطس 24
6158
1
أكتوبر 22
23878