Files
tryton/modules/google_maps/address.py
T

23 lines
806 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
2025-04-27 17:29:24 +02:00
@fields.depends('full_address')
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]
2025-04-27 17:29:24 +02:00
url = ' '.join((self.full_address or '').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 ''