File: address.py

package info (click to toggle)
tryton-modules-google-maps 7.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 348 kB
  • sloc: python: 237; xml: 22; makefile: 11; sh: 3
file content (24 lines) | stat: -rw-r--r-- 878 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# This file is part of Tryton.  The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
import urllib.parse

from trytond.model import fields
from trytond.pool import PoolMeta
from trytond.transaction import Transaction


class Address(metaclass=PoolMeta):
    __name__ = 'party.address'

    google_maps_url = fields.Function(fields.Char('Google Maps'),
        'on_change_with_google_maps_url')

    @fields.depends(
        'name', 'street', 'postal_code', 'city', 'country', 'subdivision')
    def on_change_with_google_maps_url(self, name=None):
        lang = Transaction().language[:2]
        url = ' '.join(self.get_full_address('full_address').splitlines())
        if url.strip():
            return 'http://maps.google.com/maps?hl=%s&q=%s' % \
                (lang, urllib.parse.quote(url))
        return ''