Odoo Help

0

0
1 Answer
4
Avatar

Yenthe Van Ginneken

--Yenthe Van Ginneken--
22640
| 9 9 12
Turnhout, België
--Yenthe Van Ginneken--

My Odoo training platform: https://www.oocademy.com
My Odoo blog: http://www.odoo.yenthevg.com/
My Twitter: https://twitter.com/Yenthe666

Yenthe Van Ginneken
27-07-17 09:21

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

2 Comments
Sylwester Zalewski
27-07-17 09:24

Perfect! Thanks

Yenthe Van Ginneken
27-07-17 09:27

You're welcome - best of luck!

Stel een vraag
Keep Informed
1 volger(s)
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.

Register
Odoo Training Center

Access to our eLearning platform and experience all Odoo Apps through learning videos, use cases and quizzes.

Test it now