Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
11517 มุมมอง

Is there any way to call a javascript function from python or any workaround to achieve a similar result?

I basically want to call a certain javascript function when a scheduler runs.

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด


you have to use the RPC:

https://doc.odoo.com/trunk/web/rpc/  

Use 'this', single quotes and the done function and it should work:

this._model = ...;

var x = this._model.call('my_method',[]).done(function(results){

whatever;

});


You can use get_func from JS to call py function :

new instance.web.Model("<model>").get_func("<py function>")(<args>)

This is a sample code from module.PosWidget (point_of_sales/static/src/js/widget.js) :

new instance.web.Model("ir.model.data").get_func("search_read")([['name', '=', 'action_pos_session_opening']], ['res_id'])

อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด

Thanks Vasanth, but could you please explain a little more:

  1. A scheduler calls a python function "my_function"

  2. "my_function" is defined similar to:

def my_function(self,cr,uid,ids,context=None):

call some javascript function()

return True


Is this possible?

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
มิ.ย. 25
3944
1
ก.ย. 19
10790
3
ธ.ค. 23
45969
0
มี.ค. 15
3810
0
มี.ค. 15
3917