Browse Source
Merge pull request #2 from pedrobaeza/9-port-external-maps
Merge pull request #2 from pedrobaeza/9-port-external-maps
9 port external mapspull/237/head
Alexis de Lattre
9 years ago
29 changed files with 3581 additions and 744 deletions
-
48partner_external_map/README.rst
-
4partner_external_map/__init__.py
-
16partner_external_map/__openerp__.py
-
14partner_external_map/data/map_website_data.xml
-
33partner_external_map/hooks.py
-
94partner_external_map/i18n/da.po
-
94partner_external_map/i18n/de.po
-
94partner_external_map/i18n/en.po
-
94partner_external_map/i18n/es.po
-
94partner_external_map/i18n/fr.po
-
94partner_external_map/i18n/nl.po
-
94partner_external_map/i18n/sl.po
-
5partner_external_map/models/__init__.py
-
30partner_external_map/models/map_website.py
-
111partner_external_map/models/res_partner.py
-
52partner_external_map/models/res_users.py
-
0partner_external_map/security/ir.model.access.csv
-
BINpartner_external_map/static/description/icon.png
-
2887partner_external_map/static/description/icon.svg
-
3partner_external_map/tests/__init__.py
-
84partner_external_map/tests/test_partner_external_map.py
-
0partner_external_map/views/map_website_view.xml
-
0partner_external_map/views/res_partner_view.xml
-
0partner_external_map/views/res_users_view.xml
-
4partner_external_maps/__init__.py
-
172partner_external_maps/i18n/partner_external_maps.pot
-
193partner_external_maps/partner_external_maps.py
-
11partner_external_maps/post_install.py
-
BINpartner_external_maps/static/description/icon.png
@ -0,0 +1,4 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
|
||||
|
from . import models |
||||
|
from .hooks import set_default_map_settings |
@ -0,0 +1,33 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
# © 2015 Alexis de Lattre <alexis.delattre@akretion.com> |
||||
|
# © 2016 Pedro M. Baeza <pedro.baeza@tecnativa.com> |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
||||
|
|
||||
|
from openerp import api, SUPERUSER_ID |
||||
|
import logging |
||||
|
|
||||
|
|
||||
|
logger = logging.getLogger(__name__) |
||||
|
|
||||
|
|
||||
|
def set_default_map_settings(cr, registry): |
||||
|
"""Method called as post-install script |
||||
|
The default method on the field can't be used, because it would be executed |
||||
|
before loading map_website_data.xml, so it would not be able to set a |
||||
|
value""" |
||||
|
with api.Environment.manage(): |
||||
|
env = api.Environment(cr, SUPERUSER_ID, {}) |
||||
|
user_model = env['res.users'] |
||||
|
users = user_model.search([('context_map_website_id', '=', False)]) |
||||
|
logger.info('Updating user settings for maps...') |
||||
|
users.write({ |
||||
|
'context_map_website_id': user_model._default_map_website().id, |
||||
|
'context_route_map_website_id': ( |
||||
|
user_model._default_route_map_website().id), |
||||
|
}) |
||||
|
# Update the starting partner this way that is faster |
||||
|
cr.execute(""" |
||||
|
UPDATE res_users |
||||
|
SET context_route_start_partner_id = partner_id |
||||
|
WHERE context_route_start_partner_id IS NULL; |
||||
|
""") |
@ -0,0 +1,5 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
|
||||
|
from . import map_website |
||||
|
from . import res_partner |
||||
|
from . import res_users |
@ -0,0 +1,30 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
# © 2015 Alexis de Lattre <alexis.delattre@akretion.com> |
||||
|
# © 2016 Pedro M. Baeza <pedro.baeza@tecnativa.com> |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
||||
|
|
||||
|
from openerp import models, fields, api, _ |
||||
|
|
||||
|
|
||||
|
class MapWebsite(models.Model): |
||||
|
_name = 'map.website' |
||||
|
_description = 'Map Website' |
||||
|
|
||||
|
name = fields.Char(string='Map Website Name', required=True) |
||||
|
address_url = fields.Char( |
||||
|
string='URL that uses the address', |
||||
|
help="In this URL, {ADDRESS} will be replaced by the address.") |
||||
|
lat_lon_url = fields.Char( |
||||
|
string='URL that uses latitude and longitude', |
||||
|
help="In this URL, {LATITUDE} and {LONGITUDE} will be replaced by " |
||||
|
"the latitude and longitude (requires the module 'base_geolocalize')") |
||||
|
route_address_url = fields.Char( |
||||
|
string='Route URL that uses the addresses', |
||||
|
help="In this URL, {START_ADDRESS} and {DEST_ADDRESS} will be " |
||||
|
"replaced by the start and destination addresses.") |
||||
|
route_lat_lon_url = fields.Char( |
||||
|
string='Route URL that uses latitude and longitude', |
||||
|
help="In this URL, {START_LATITUDE}, {START_LONGITUDE}, " |
||||
|
"{DEST_LATITUDE} and {DEST_LONGITUDE} will be replaced by the " |
||||
|
"latitude and longitude of the start and destination adresses " |
||||
|
"(requires the module 'base_geolocalize').") |
@ -0,0 +1,111 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
# © 2015 Alexis de Lattre <alexis.delattre@akretion.com> |
||||
|
# © 2016 Pedro M. Baeza <pedro.baeza@tecnativa.com> |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
||||
|
|
||||
|
from openerp import models, fields, api, _ |
||||
|
from openerp.exceptions import Warning as UserError |
||||
|
import logging |
||||
|
|
||||
|
|
||||
|
logger = logging.getLogger(__name__) |
||||
|
|
||||
|
|
||||
|
class ResPartner(models.Model): |
||||
|
_inherit = 'res.partner' |
||||
|
|
||||
|
@api.multi |
||||
|
def _address_as_string(self): |
||||
|
self.ensure_one() |
||||
|
addr = [] |
||||
|
if self.street: |
||||
|
addr.append(self.street) |
||||
|
if self.street2: |
||||
|
addr.append(self.street2) |
||||
|
if self.city: |
||||
|
addr.append(self.city) |
||||
|
if self.state_id: |
||||
|
addr.append(self.state_id.name) |
||||
|
if self.country_id: |
||||
|
addr.append(self.country_id.name) |
||||
|
if not addr: |
||||
|
raise UserError(_("Address missing on partner '%s'.") % self.name) |
||||
|
return ' '.join(addr) |
||||
|
|
||||
|
@api.model |
||||
|
def _prepare_url(self, url, replace): |
||||
|
assert url, 'Missing URL' |
||||
|
for key, value in replace.iteritems(): |
||||
|
if not isinstance(value, (str, unicode)): |
||||
|
# for latitude and longitude which are floats |
||||
|
value = unicode(value) |
||||
|
url = url.replace(key, value) |
||||
|
logger.debug('Final URL: %s', url) |
||||
|
return url |
||||
|
|
||||
|
@api.multi |
||||
|
def open_map(self): |
||||
|
self.ensure_one() |
||||
|
map_website = self.env.user.context_map_website_id |
||||
|
if not map_website: |
||||
|
raise UserError( |
||||
|
_('Missing map provider: ' |
||||
|
'you should set it in your preferences.')) |
||||
|
if (map_website.lat_lon_url and hasattr(self, 'partner_latitude') and |
||||
|
self.partner_latitude and self.partner_longitude): |
||||
|
url = self._prepare_url( |
||||
|
map_website.lat_lon_url, { |
||||
|
'{LATITUDE}': self.partner_latitude, |
||||
|
'{LONGITUDE}': self.partner_longitude}) |
||||
|
else: |
||||
|
if not map_website.address_url: |
||||
|
raise UserError( |
||||
|
_("Missing parameter 'URL that uses the address' " |
||||
|
"for map website '%s'.") % map_website.name) |
||||
|
url = self._prepare_url( |
||||
|
map_website.address_url, |
||||
|
{'{ADDRESS}': self._address_as_string()}) |
||||
|
return { |
||||
|
'type': 'ir.actions.act_url', |
||||
|
'url': url, |
||||
|
'target': 'new', |
||||
|
} |
||||
|
|
||||
|
@api.multi |
||||
|
def open_route_map(self): |
||||
|
self.ensure_one() |
||||
|
if not self.env.user.context_route_map_website_id: |
||||
|
raise UserError( |
||||
|
_('Missing route map website: ' |
||||
|
'you should set it in your preferences.')) |
||||
|
map_website = self.env.user.context_route_map_website_id |
||||
|
if not self.env.user.context_route_start_partner_id: |
||||
|
raise UserError( |
||||
|
_('Missing start address for route map: ' |
||||
|
'you should set it in your preferences.')) |
||||
|
start_partner = self.env.user.context_route_start_partner_id |
||||
|
if (map_website.route_lat_lon_url and |
||||
|
hasattr(self, 'partner_latitude') and |
||||
|
self.partner_latitude and self.partner_longitude and |
||||
|
start_partner.partner_latitude and |
||||
|
start_partner.partner_longitude): |
||||
|
url = self._prepare_url( # pragma: no cover |
||||
|
map_website.route_lat_lon_url, { |
||||
|
'{START_LATITUDE}': start_partner.partner_latitude, |
||||
|
'{START_LONGITUDE}': start_partner.partner_longitude, |
||||
|
'{DEST_LATITUDE}': self.partner_latitude, |
||||
|
'{DEST_LONGITUDE}': self.partner_longitude}) |
||||
|
else: |
||||
|
if not map_website.route_address_url: |
||||
|
raise UserError( |
||||
|
_("Missing route URL that uses the addresses " |
||||
|
"for the map website '%s'") % map_website.name) |
||||
|
url = self._prepare_url( |
||||
|
map_website.route_address_url, { |
||||
|
'{START_ADDRESS}': start_partner._address_as_string(), |
||||
|
'{DEST_ADDRESS}': self._address_as_string()}) |
||||
|
return { |
||||
|
'type': 'ir.actions.act_url', |
||||
|
'url': url, |
||||
|
'target': 'new', |
||||
|
} |
@ -0,0 +1,52 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
# © 2015 Alexis de Lattre <alexis.delattre@akretion.com> |
||||
|
# © 2016 Pedro M. Baeza <pedro.baeza@tecnativa.com> |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
||||
|
|
||||
|
from openerp import models, fields, api, _ |
||||
|
import logging |
||||
|
|
||||
|
logger = logging.getLogger(__name__) |
||||
|
|
||||
|
|
||||
|
class ResUsers(models.Model): |
||||
|
_inherit = 'res.users' |
||||
|
|
||||
|
@api.model |
||||
|
def _default_map_website(self): |
||||
|
return self.env['map.website'].search([ |
||||
|
'|', ('address_url', '!=', False), ('lat_lon_url', '!=', False)], |
||||
|
limit=1) |
||||
|
|
||||
|
@api.model |
||||
|
def _default_route_map_website(self): |
||||
|
return self.env['map.website'].search([ |
||||
|
'|', ('route_address_url', '!=', False), |
||||
|
('route_lat_lon_url', '!=', False)], limit=1) |
||||
|
|
||||
|
# begin with context_ to allow user to change it by himself |
||||
|
context_map_website_id = fields.Many2one( |
||||
|
'map.website', string='Map Website', default=_default_map_website, |
||||
|
domain=['|', ('address_url', '!=', False), |
||||
|
('lat_lon_url', '!=', False)]) |
||||
|
# We want to give the possibility to the user to have one map provider for |
||||
|
# regular maps and another one for routing |
||||
|
context_route_map_website_id = fields.Many2one( |
||||
|
'map.website', string='Route Map Website', |
||||
|
domain=['|', ('route_address_url', '!=', False), |
||||
|
('route_lat_lon_url', '!=', False)], |
||||
|
default=_default_route_map_website, |
||||
|
help="Map provided used when you click on the car icon on the partner " |
||||
|
"form to display an itinerary.") |
||||
|
context_route_start_partner_id = fields.Many2one( |
||||
|
'res.partner', string='Start Address for Route Map') |
||||
|
|
||||
|
@api.model |
||||
|
def create(self, vals): |
||||
|
"""On creation, if no starting partner is provided, assign the current |
||||
|
created one. |
||||
|
""" |
||||
|
user = super(ResUsers, self).create(vals) |
||||
|
if not vals.get('context_route_start_partner_id'): |
||||
|
user.context_route_start_partner_id = user.partner_id.id |
||||
|
return user |
After Width: 128 | Height: 128 | Size: 16 KiB |
2887
partner_external_map/static/description/icon.svg
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,3 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
|
||||
|
from . import test_partner_external_map |
@ -0,0 +1,84 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
# © 2016 Pedro M. Baeza <pedro.baeza@tecnativa.com> |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
||||
|
|
||||
|
from openerp.tests import common |
||||
|
from openerp.exceptions import Warning as UserError |
||||
|
from ..hooks import set_default_map_settings |
||||
|
|
||||
|
|
||||
|
class TestPartnerExternalMap(common.TransactionCase): |
||||
|
def setUp(self): |
||||
|
super(TestPartnerExternalMap, self).setUp() |
||||
|
self.user = self.env['res.users'].create({ |
||||
|
'name': 'Test user', |
||||
|
'login': 'test_login', |
||||
|
'context_map_website_id': self.ref( |
||||
|
'partner_external_map.google_maps'), |
||||
|
'context_route_map_website_id': self.ref( |
||||
|
'partner_external_map.google_maps'), |
||||
|
}) |
||||
|
self.user.partner_id.city = 'Tomelloso' |
||||
|
self.partner = self.env['res.partner'].create({ |
||||
|
'name': 'Test partner', |
||||
|
'city': 'Madrid', |
||||
|
}) |
||||
|
|
||||
|
def test_post_init_hook(self): |
||||
|
# Call this again for coverage purposes, but it has been already run |
||||
|
set_default_map_settings(self.cr, self.registry) |
||||
|
self.assertTrue(self.env.user.context_map_website_id) |
||||
|
self.assertTrue(self.env.user.context_route_map_website_id) |
||||
|
self.assertEqual(self.env.user.partner_id, |
||||
|
self.env.user.context_route_start_partner_id) |
||||
|
|
||||
|
def test_create_user(self): |
||||
|
self.assertEqual( |
||||
|
self.user.partner_id, self.user.context_route_start_partner_id) |
||||
|
|
||||
|
def test_open_map(self): |
||||
|
action = self.partner.sudo(self.user.id).open_map() |
||||
|
self.assertEqual( |
||||
|
action['url'], "https://www.google.com/maps?ie=UTF8&q=Madrid") |
||||
|
|
||||
|
def test_open_route_map(self): |
||||
|
action = self.partner.sudo(self.user.id).open_route_map() |
||||
|
self.assertEqual( |
||||
|
action['url'], "https://www.google.com/maps?saddr=Tomelloso&daddr=" |
||||
|
"Madrid&directionsmode=driving") |
||||
|
|
||||
|
def test_open_map_with_coordinates(self): |
||||
|
# Simulate that we have the base_geolocalize module installed creating |
||||
|
# by hand the variables - This can't be done with routes |
||||
|
partner = self.partner.sudo(self.user.id) |
||||
|
partner.partner_latitude = 39.15837 |
||||
|
partner.partner_longitude = -3.02145 |
||||
|
action = partner.open_map() |
||||
|
self.assertEqual( |
||||
|
action['url'], |
||||
|
"https://www.google.com/maps?z=15&q=39.15837,-3.02145") |
||||
|
|
||||
|
def test_exception_no_map_website(self): |
||||
|
self.user.context_map_website_id = False |
||||
|
with self.assertRaises(UserError): |
||||
|
self.partner.sudo(self.user.id).open_map() |
||||
|
|
||||
|
def test_exception_no_map_route_website(self): |
||||
|
self.user.context_route_start_partner_id = False |
||||
|
with self.assertRaises(UserError): |
||||
|
self.partner.sudo(self.user.id).open_route_map() |
||||
|
|
||||
|
def test_exception_no_starting_partner(self): |
||||
|
self.user.context_route_map_website_id = False |
||||
|
with self.assertRaises(UserError): |
||||
|
self.partner.sudo(self.user.id).open_route_map() |
||||
|
|
||||
|
def test_exception_no_address_url(self): |
||||
|
self.user.context_map_website_id.address_url = False |
||||
|
with self.assertRaises(UserError): |
||||
|
self.partner.sudo(self.user.id).open_map() |
||||
|
|
||||
|
def test_exception_no_route_address_url(self): |
||||
|
self.user.context_map_website_id.route_address_url = False |
||||
|
with self.assertRaises(UserError): |
||||
|
self.partner.sudo(self.user.id).open_route_map() |
@ -1,4 +0,0 @@ |
|||||
# -*- coding: utf-8 -*- |
|
||||
|
|
||||
from . import partner_external_maps |
|
||||
from .post_install import set_default_map_settings |
|
@ -1,172 +0,0 @@ |
|||||
# Translation of Odoo Server. |
|
||||
# This file contains the translation of the following modules: |
|
||||
# * partner_external_maps |
|
||||
# |
|
||||
msgid "" |
|
||||
msgstr "" |
|
||||
"Project-Id-Version: Odoo Server 8.0\n" |
|
||||
"Report-Msgid-Bugs-To: \n" |
|
||||
"POT-Creation-Date: 2015-06-19 19:55+0000\n" |
|
||||
"PO-Revision-Date: 2015-06-19 19:55+0000\n" |
|
||||
"Last-Translator: <>\n" |
|
||||
"Language-Team: \n" |
|
||||
"MIME-Version: 1.0\n" |
|
||||
"Content-Type: text/plain; charset=UTF-8\n" |
|
||||
"Content-Transfer-Encoding: \n" |
|
||||
"Plural-Forms: \n" |
|
||||
|
|
||||
#. module: partner_external_maps |
|
||||
#: code:addons/partner_external_maps/partner_external_maps.py:116 |
|
||||
#, python-format |
|
||||
msgid "Address missing on partner '%s'." |
|
||||
msgstr "" |
|
||||
|
|
||||
#. module: partner_external_maps |
|
||||
#: field:map.website,create_uid:0 |
|
||||
msgid "Created by" |
|
||||
msgstr "" |
|
||||
|
|
||||
#. module: partner_external_maps |
|
||||
#: field:map.website,create_date:0 |
|
||||
msgid "Created on" |
|
||||
msgstr "" |
|
||||
|
|
||||
#. module: partner_external_maps |
|
||||
#: field:map.website,id:0 |
|
||||
msgid "ID" |
|
||||
msgstr "" |
|
||||
|
|
||||
#. module: partner_external_maps |
|
||||
#: help:map.website,address_url:0 |
|
||||
msgid "In this URL, {ADDRESS} will be replaced by the address." |
|
||||
msgstr "" |
|
||||
|
|
||||
#. module: partner_external_maps |
|
||||
#: help:map.website,lat_lon_url:0 |
|
||||
msgid "In this URL, {LATITUDE} and {LONGITUDE} will be replaced by the latitude and longitude (requires the module 'base_geolocalize')" |
|
||||
msgstr "" |
|
||||
|
|
||||
#. module: partner_external_maps |
|
||||
#: help:map.website,route_address_url:0 |
|
||||
msgid "In this URL, {START_ADDRESS} and {DEST_ADDRESS} will be replaced by the start and destination addresses." |
|
||||
msgstr "" |
|
||||
|
|
||||
#. module: partner_external_maps |
|
||||
#: help:map.website,route_lat_lon_url:0 |
|
||||
msgid "In this URL, {START_LATITUDE}, {START_LONGITUDE}, {DEST_LATITUDE} and {DEST_LONGITUDE} will be replaced by the latitude and longitude of the start and destination adresses (requires the module 'base_geolocalize')." |
|
||||
msgstr "" |
|
||||
|
|
||||
#. module: partner_external_maps |
|
||||
#: field:map.website,write_uid:0 |
|
||||
msgid "Last Updated by" |
|
||||
msgstr "" |
|
||||
|
|
||||
#. module: partner_external_maps |
|
||||
#: field:map.website,write_date:0 |
|
||||
msgid "Last Updated on" |
|
||||
msgstr "" |
|
||||
|
|
||||
#. module: partner_external_maps |
|
||||
#: view:res.partner:partner_external_maps.view_partner_form |
|
||||
msgid "Map" |
|
||||
msgstr "" |
|
||||
|
|
||||
#. module: partner_external_maps |
|
||||
#: model:ir.model,name:partner_external_maps.model_map_website |
|
||||
#: view:map.website:partner_external_maps.map_website_form |
|
||||
#: field:res.users,context_map_website_id:0 |
|
||||
msgid "Map Website" |
|
||||
msgstr "" |
|
||||
|
|
||||
#. module: partner_external_maps |
|
||||
#: field:map.website,name:0 |
|
||||
msgid "Map Website Name" |
|
||||
msgstr "" |
|
||||
|
|
||||
#. module: partner_external_maps |
|
||||
#: model:ir.actions.act_window,name:partner_external_maps.map_website_action |
|
||||
#: model:ir.ui.menu,name:partner_external_maps.map_website_menu |
|
||||
#: view:map.website:partner_external_maps.map_website_tree |
|
||||
msgid "Map Websites" |
|
||||
msgstr "" |
|
||||
|
|
||||
#. module: partner_external_maps |
|
||||
#: help:res.users,context_route_map_website_id:0 |
|
||||
msgid "Map provided used when you click on the car icon on the partner form to display an itinerary." |
|
||||
msgstr "" |
|
||||
|
|
||||
#. module: partner_external_maps |
|
||||
#: code:addons/partner_external_maps/partner_external_maps.py:134 |
|
||||
#, python-format |
|
||||
msgid "Missing map provider: you should set it in your preferences." |
|
||||
msgstr "" |
|
||||
|
|
||||
#. module: partner_external_maps |
|
||||
#: code:addons/partner_external_maps/partner_external_maps.py:148 |
|
||||
#, python-format |
|
||||
msgid "Missing parameter 'URL that uses the address' for map website '%s'." |
|
||||
msgstr "" |
|
||||
|
|
||||
#. module: partner_external_maps |
|
||||
#: code:addons/partner_external_maps/partner_external_maps.py:187 |
|
||||
#, python-format |
|
||||
msgid "Missing route URL that uses the addresses for the map website '%s'" |
|
||||
msgstr "" |
|
||||
|
|
||||
#. module: partner_external_maps |
|
||||
#: code:addons/partner_external_maps/partner_external_maps.py:163 |
|
||||
#, python-format |
|
||||
msgid "Missing route map website: you should set it in your preferences." |
|
||||
msgstr "" |
|
||||
|
|
||||
#. module: partner_external_maps |
|
||||
#: code:addons/partner_external_maps/partner_external_maps.py:168 |
|
||||
#, python-format |
|
||||
msgid "Missing start address for route map: you should set it in your preferences." |
|
||||
msgstr "" |
|
||||
|
|
||||
#. module: partner_external_maps |
|
||||
#: model:ir.model,name:partner_external_maps.model_res_partner |
|
||||
msgid "Partner" |
|
||||
msgstr "" |
|
||||
|
|
||||
#. module: partner_external_maps |
|
||||
#: view:res.partner:partner_external_maps.view_partner_form |
|
||||
msgid "Route Map" |
|
||||
msgstr "" |
|
||||
|
|
||||
#. module: partner_external_maps |
|
||||
#: field:res.users,context_route_map_website_id:0 |
|
||||
msgid "Route Map Website" |
|
||||
msgstr "" |
|
||||
|
|
||||
#. module: partner_external_maps |
|
||||
#: field:map.website,route_lat_lon_url:0 |
|
||||
msgid "Route URL that uses latitude and longitude" |
|
||||
msgstr "" |
|
||||
|
|
||||
#. module: partner_external_maps |
|
||||
#: field:map.website,route_address_url:0 |
|
||||
msgid "Route URL that uses the addresses" |
|
||||
msgstr "" |
|
||||
|
|
||||
#. module: partner_external_maps |
|
||||
#: field:res.users,context_route_start_partner_id:0 |
|
||||
msgid "Start Address for Route Map" |
|
||||
msgstr "" |
|
||||
|
|
||||
#. module: partner_external_maps |
|
||||
#: field:map.website,lat_lon_url:0 |
|
||||
msgid "URL that uses latitude and longitude" |
|
||||
msgstr "" |
|
||||
|
|
||||
#. module: partner_external_maps |
|
||||
#: field:map.website,address_url:0 |
|
||||
msgid "URL that uses the address" |
|
||||
msgstr "" |
|
||||
|
|
||||
#. module: partner_external_maps |
|
||||
#: model:ir.model,name:partner_external_maps.model_res_users |
|
||||
msgid "Users" |
|
||||
msgstr "" |
|
||||
|
|
@ -1,193 +0,0 @@ |
|||||
# -*- coding: utf-8 -*- |
|
||||
# © 2015 Akretion (http://www.akretion.com/) |
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
|
||||
# @author: Alexis de Lattre <alexis.delattre@akretion.com> |
|
||||
|
|
||||
from openerp import models, fields, api, _ |
|
||||
from openerp.exceptions import Warning |
|
||||
import logging |
|
||||
|
|
||||
logger = logging.getLogger(__name__) |
|
||||
|
|
||||
|
|
||||
class MapWebsite(models.Model): |
|
||||
_name = 'map.website' |
|
||||
_description = 'Map Website' |
|
||||
|
|
||||
name = fields.Char(string='Map Website Name', required=True) |
|
||||
address_url = fields.Char( |
|
||||
string='URL that uses the address', |
|
||||
help="In this URL, {ADDRESS} will be replaced by the address.") |
|
||||
lat_lon_url = fields.Char( |
|
||||
string='URL that uses latitude and longitude', |
|
||||
help="In this URL, {LATITUDE} and {LONGITUDE} will be replaced by " |
|
||||
"the latitude and longitude (requires the module 'base_geolocalize')") |
|
||||
route_address_url = fields.Char( |
|
||||
string='Route URL that uses the addresses', |
|
||||
help="In this URL, {START_ADDRESS} and {DEST_ADDRESS} will be " |
|
||||
"replaced by the start and destination addresses.") |
|
||||
route_lat_lon_url = fields.Char( |
|
||||
string='Route URL that uses latitude and longitude', |
|
||||
help="In this URL, {START_LATITUDE}, {START_LONGITUDE}, " |
|
||||
"{DEST_LATITUDE} and {DEST_LONGITUDE} will be replaced by the " |
|
||||
"latitude and longitude of the start and destination adresses " |
|
||||
"(requires the module 'base_geolocalize').") |
|
||||
|
|
||||
|
|
||||
class ResUsers(models.Model): |
|
||||
_inherit = 'res.users' |
|
||||
|
|
||||
@api.model |
|
||||
def _default_map_website(self): |
|
||||
map_website = self.env['map.website'].search([ |
|
||||
'|', ('address_url', '!=', False), ('lat_lon_url', '!=', False)], |
|
||||
limit=1) |
|
||||
return map_website |
|
||||
|
|
||||
@api.model |
|
||||
def _default_route_map_website(self): |
|
||||
map_route_website = self.env['map.website'].search([ |
|
||||
'|', |
|
||||
('route_address_url', '!=', False), |
|
||||
('route_lat_lon_url', '!=', False)], limit=1) |
|
||||
return map_route_website |
|
||||
|
|
||||
# begin with context_ to allow user to change it by himself |
|
||||
context_map_website_id = fields.Many2one( |
|
||||
'map.website', string='Map Website', |
|
||||
domain=[ |
|
||||
'|', ('address_url', '!=', False), ('lat_lon_url', '!=', False)], |
|
||||
default=_default_map_website) |
|
||||
# We want to give the possibility to the user to have one map provider for |
|
||||
# regular maps and another one for routing |
|
||||
context_route_map_website_id = fields.Many2one( |
|
||||
'map.website', string='Route Map Website', |
|
||||
domain=[ |
|
||||
'|', |
|
||||
('route_address_url', '!=', False), |
|
||||
('route_lat_lon_url', '!=', False)], |
|
||||
default=_default_route_map_website, |
|
||||
help="Map provided used when you click on the car icon on the partner " |
|
||||
"form to display an itinerary.") |
|
||||
context_route_start_partner_id = fields.Many2one( |
|
||||
'res.partner', string='Start Address for Route Map') |
|
||||
|
|
||||
@api.model |
|
||||
def _default_map_settings(self): |
|
||||
"""Method called from post-install script |
|
||||
I can't use a default method on the field, because it would be executed |
|
||||
before loading map_website_data.xml, so it would not be able to set a |
|
||||
value""" |
|
||||
users = self.env['res.users'].search([]) |
|
||||
map_website = self._default_map_website() |
|
||||
map_route_website = self._default_route_map_website() |
|
||||
logger.info('Updating user settings for maps...') |
|
||||
for user in users: |
|
||||
user.write({ |
|
||||
'context_map_website_id': map_website.id or False, |
|
||||
'context_route_map_website_id': map_route_website.id or False, |
|
||||
'context_route_start_partner_id': user.partner_id.id or False, |
|
||||
}) |
|
||||
|
|
||||
|
|
||||
class ResPartner(models.Model): |
|
||||
_inherit = 'res.partner' |
|
||||
|
|
||||
@api.model |
|
||||
def _address_as_string(self): |
|
||||
addr = [] |
|
||||
if self.street: |
|
||||
addr.append(self.street) |
|
||||
if self.street2: |
|
||||
addr.append(self.street2) |
|
||||
if self.city: |
|
||||
addr.append(self.city) |
|
||||
if self.state_id: |
|
||||
addr.append(self.state_id.name) |
|
||||
if self.country_id: |
|
||||
addr.append(self.country_id.name) |
|
||||
if not addr: |
|
||||
raise Warning( |
|
||||
_("Address missing on partner '%s'.") % self.name) |
|
||||
address = ' '.join(addr) |
|
||||
return address |
|
||||
|
|
||||
@api.model |
|
||||
def _prepare_url(self, url, replace): |
|
||||
assert url, 'Missing URL' |
|
||||
for key, value in replace.iteritems(): |
|
||||
if not isinstance(value, (str, unicode)): |
|
||||
# for latitude and longitude which are floats |
|
||||
value = unicode(value) |
|
||||
url = url.replace(key, value) |
|
||||
logger.debug('Final URL: %s', url) |
|
||||
return url |
|
||||
|
|
||||
@api.multi |
|
||||
def open_map(self): |
|
||||
if not self.env.user.context_map_website_id: |
|
||||
raise Warning( |
|
||||
_('Missing map provider: ' |
|
||||
'you should set it in your preferences.')) |
|
||||
map_website = self.env.user.context_map_website_id |
|
||||
if ( |
|
||||
map_website.lat_lon_url and |
|
||||
hasattr(self, 'partner_latitude') and |
|
||||
self.partner_latitude and self.partner_longitude): |
|
||||
url = self._prepare_url( |
|
||||
map_website.lat_lon_url, { |
|
||||
'{LATITUDE}': self.partner_latitude, |
|
||||
'{LONGITUDE}': self.partner_longitude}) |
|
||||
else: |
|
||||
if not map_website.address_url: |
|
||||
raise Warning( |
|
||||
_("Missing parameter 'URL that uses the address' " |
|
||||
"for map website '%s'.") % map_website.name) |
|
||||
url = self._prepare_url( |
|
||||
map_website.address_url, |
|
||||
{'{ADDRESS}': self._address_as_string()}) |
|
||||
return { |
|
||||
'type': 'ir.actions.act_url', |
|
||||
'url': url, |
|
||||
'target': 'new', |
|
||||
} |
|
||||
|
|
||||
@api.multi |
|
||||
def open_route_map(self): |
|
||||
if not self.env.user.context_route_map_website_id: |
|
||||
raise Warning( |
|
||||
_('Missing route map website: ' |
|
||||
'you should set it in your preferences.')) |
|
||||
map_website = self.env.user.context_route_map_website_id |
|
||||
if not self.env.user.context_route_start_partner_id: |
|
||||
raise Warning( |
|
||||
_('Missing start address for route map: ' |
|
||||
'you should set it in your preferences.')) |
|
||||
start_partner = self.env.user.context_route_start_partner_id |
|
||||
if ( |
|
||||
map_website.route_lat_lon_url and |
|
||||
hasattr(self, 'partner_latitude') and |
|
||||
self.partner_latitude and |
|
||||
self.partner_longitude and |
|
||||
start_partner.partner_latitude and |
|
||||
start_partner.partner_longitude): |
|
||||
url = self._prepare_url( |
|
||||
map_website.route_lat_lon_url, { |
|
||||
'{START_LATITUDE}': start_partner.partner_latitude, |
|
||||
'{START_LONGITUDE}': start_partner.partner_longitude, |
|
||||
'{DEST_LATITUDE}': self.partner_latitude, |
|
||||
'{DEST_LONGITUDE}': self.partner_longitude}) |
|
||||
else: |
|
||||
if not map_website.route_address_url: |
|
||||
raise Warning( |
|
||||
_("Missing route URL that uses the addresses " |
|
||||
"for the map website '%s'") % map_website.name) |
|
||||
url = self._prepare_url( |
|
||||
map_website.route_address_url, { |
|
||||
'{START_ADDRESS}': start_partner._address_as_string(), |
|
||||
'{DEST_ADDRESS}': self._address_as_string()}) |
|
||||
return { |
|
||||
'type': 'ir.actions.act_url', |
|
||||
'url': url, |
|
||||
'target': 'new', |
|
||||
} |
|
@ -1,11 +0,0 @@ |
|||||
# -*- coding: utf-8 -*- |
|
||||
# © 2015 Akretion (http://www.akretion.com) |
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
|
||||
# @author: Alexis de Lattre <alexis.delattre@akretion.com> |
|
||||
|
|
||||
from openerp import SUPERUSER_ID |
|
||||
|
|
||||
|
|
||||
def set_default_map_settings(cr, pool): |
|
||||
pool['res.users']._default_map_settings(cr, SUPERUSER_ID) |
|
||||
return |
|
Before Width: 128 | Height: 128 | Size: 9.2 KiB |
Write
Preview
Loading…
Cancel
Save
Reference in new issue