Files
tryton/modules/google_maps/address.py
T

25 lines
878 B
Python
Raw Normal View History

2014-12-02 12:55:20 +01:00
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
2018-06-26 19:11:47 +02:00
import urllib.parse
2016-08-19 21:25:16 +02:00
2012-09-24 22:17:55 +02:00
from trytond.model import fields
from trytond.pool import PoolMeta
2021-12-11 17:58:42 +01:00
from trytond.transaction import Transaction
2012-09-24 22:17:55 +02:00
2008-06-05 10:21:33 +02:00
2018-06-26 19:11:47 +02:00
class Address(metaclass=PoolMeta):
2012-09-24 22:17:55 +02:00
__name__ = 'party.address'
2008-06-05 10:21:33 +02:00
2014-01-26 14:29:13 +01:00
google_maps_url = fields.Function(fields.Char('Google Maps'),
'on_change_with_google_maps_url')
2008-06-05 10:21:33 +02:00
2021-03-31 23:59:33 +02:00
@fields.depends(
'name', 'street', 'postal_code', 'city', 'country', 'subdivision')
2012-09-24 22:17:55 +02:00
def on_change_with_google_maps_url(self, name=None):
2010-08-19 22:12:44 +02:00
lang = Transaction().language[:2]
2016-11-27 22:15:35 +01:00
url = ' '.join(self.get_full_address('full_address').splitlines())
2016-09-06 09:22:08 +02:00
if url.strip():
2012-09-24 22:17:55 +02:00
return 'http://maps.google.com/maps?hl=%s&q=%s' % \
2018-06-26 19:11:47 +02:00
(lang, urllib.parse.quote(url))
2012-09-24 22:17:55 +02:00
return ''