Skip to Content
Menu
This question has been flagged
5 Replies
16441 Views

Hello

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

@api.one

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?

Avatar
Discard
Best Answer

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.

});

Avatar
Discard
Best Answer

Hi,


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.


UPDATE:

I can think of 2 ways to do this:

1.

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


---

Avatar
Discard
Author

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

Please have a look at my updated answer.

Author

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