This question has been flagged
1 Reply
16548 Views

Hi, 

I receive following error when I try to call my function to update some fields "Private methods (such as _get_coords_from_address) cannot be called remotely."  Any ideas ? Thanks

@api.one
def _get_coords_from_address(self):
if self.full_address != None:
lat_long = geocoder.google(self.full_address)
# self.lat_long = lat_long.latlng
    self.write({'lat_long': lat_long.latlng}) 
<button string="Map Coordinates" type="object" name="_get_coords_from_address"  class="oe_stat_button" />
Avatar
Discard
Best Answer

Hi Sylwester,

By default Python functions starting with _ are considered private methods. For more information have a look at https://stackoverflow.com/questions/1547145/defining-private-module-functions-in-python
In your case you can simply change the button name from _get_coords_from_address to get_coords_from_address (remove the _). If you do the same on the Python side it will work fine.
By removing the underscore Odoo will no longer see it as a private method, which caused your initial error.
On a sidenote, you're using the @api.one decorator which is pretty much deprecated. It is better to use @api.multi in combination with self.ensure_one. Your code shoud look like this in XML:

<button string="Map Coordinates" type="object" name="get_coords_from_address" class="oe_stat_button"/>

The Python:

@api.multi
def get_coords_from_address(self):
# This will make sure that you have one record instead of multiple (singleton) self.ensure_one()
if self.full_address != None:
lat_long = geocoder.google(self.full_address)
# self.lat_long = lat_long.latlng
    self.write({'lat_long': lat_long.latlng}) 

Regards,
Yenthe

Avatar
Discard
Author

Perfect! Thanks

You're welcome - best of luck!