Odoo Help


using Javascript to execute python function

Tarik Tourougui
on 3/8/16, 6:25 PM 1,952 views


i have a python function that returns a string that i will be using in a JS function (google maps)

i have the below python code


def tt_js_return_url(self): return self.latitude + "," + self.longitude

Do you have an idea of how to get the function return in the JS code?

Asmita Chavan
On 9/19/16, 3:56 AM

You can call your python method through your .js file using .call method.

for example,

I assume, your class name is 'my.module', then you can call your method, using following way.

var MyModel = new Model('my.module')

MyModel.call('tt_js_return_url', []).then(function(result){

// your code , in result you will get value returned by python method.


Thanh Loyal
On 3/8/16, 11:56 PM


I am not sure that I understand you correctly. What i am imagining :

In your front end html site:

<script src="odoo_js_files.js"/>
<script src="your_file.js"/>
<script src="google_map.js"/>

If that is true, please read https://www.odoo.com/documentation/8.0/howtos/web.html too know how to insert your js files when Odoo render the page, and call your tt_js_return_url as describled in  Communication with the Odoo Server section.

After your call to server, you'll get long+lat, assign it to a global variable to make it available in your google_map.js.

Hope this helps.


I can think of 2 ways to do this:


If your html page is in a separated application from Odoo, you may write kind of webservice in Odoo and call it from your maps application.

Odoo                                                                                                           Maps application

end point:                                                      

http://yourodoo.com/get_vehicle_cordinates        <--------------->              Javascript client

At odoo side, you should write a method in a controller like this:

@http.route(route='/get_vehicle_cordinates', auth='public') # consider authorization check
def get_vehicle_cordinate(self, **kwargs):
# And calculate cordinates to return

And at Maps side, you should use JavaScript to call that service, use something like $.post('http://yourodoo.com/get_vehicle_cordinates', {vehicle_id: v_id}, function(){

    // Handle your long, lat value.


2. The second way, if your html page is a part of Odoo, you may put your map in a Odoo widget.

Define html code in a template,  use call method (please read Communication with the Odoo Server which I mentioned above) to call tt_js_return_url and handle the result


Hell Thanh, i hope that you're doing fine ... what have is: my_model.py which contains a function that returns the coordinates of a vehicle, those coordinates must be transfered to a google_maps.html file which contains the script that will locate the vehicle on the map snippet of the map then will be shown later in the XML file using

Tarik Tourougui
on 3/9/16, 1:03 PM

Please have a look at my updated answer.

Thanh Loyal
on 3/9/16, 10:34 PM

by putting my googlemap.html into a widget, will i be able to pass to it the long/lat variables so i can locate the vehicle on the map? please check another related question that i have posted : https://www.odoo.com/forum/help-1/question/costume-widget-odoo-v8-99306

Tarik Tourougui
on 3/15/16, 1:18 PM

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 3/8/16, 6:25 PM
Seen: 1952 times
Last updated: 9/19/16, 3:56 AM