Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to call Javacript function from Python?

By
Shawn Varghese
on 3/23/15, 5:13 AM 1,082 views

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.

1

Vasanth

--Vasanth--
3458
| 5 3 8
Pondicherry, India
--Vasanth--
Vasanth
On 3/23/15, 5:32 AM


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

0
Shawn Varghese
On 3/23/15, 6:07 AM

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?

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 3/23/15, 5:13 AM
Seen: 1082 times
Last updated: 3/23/15, 6:07 AM