콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
11540 화면

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?

아바타
취소
관련 게시물 답글 화면 활동
1
6월 25
3973
1
9월 19
10806
3
12월 23
46003
0
3월 15
3836
0
3월 15
3930