From d9d2efb6e183f41ee5bef8dc4c248aabbb57b706 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Fri, 19 Jun 2015 22:02:15 +0200 Subject: [PATCH] Rename module to partner_external_maps Rename object map.url to map.website User can now choose a different map.website for routing Code and view cleanup Add translation files --- partner_address_on_map/__init__.py | 4 - .../partner_address_on_map.py | 165 --------------- .../security/ir.model.access.csv | 3 - partner_external_maps/README.rst | 52 +++++ partner_external_maps/__init__.py | 4 + .../__openerp__.py | 16 +- partner_external_maps/i18n/fr.po | 190 +++++++++++++++++ .../i18n/partner_external_maps.pot | 172 +++++++++++++++ .../map_website_data.xml | 10 +- .../map_website_view.xml | 24 +-- .../partner_external_maps.py | 197 ++++++++++++++++++ .../partner_view.xml | 0 .../post_install.py | 4 +- .../security/ir.model.access.csv | 3 + .../users_view.xml | 16 +- 15 files changed, 656 insertions(+), 204 deletions(-) delete mode 100644 partner_address_on_map/__init__.py delete mode 100644 partner_address_on_map/partner_address_on_map.py delete mode 100644 partner_address_on_map/security/ir.model.access.csv create mode 100644 partner_external_maps/README.rst create mode 100644 partner_external_maps/__init__.py rename {partner_address_on_map => partner_external_maps}/__openerp__.py (79%) create mode 100644 partner_external_maps/i18n/fr.po create mode 100644 partner_external_maps/i18n/partner_external_maps.pot rename partner_address_on_map/map_url_data.xml => partner_external_maps/map_website_data.xml (90%) rename partner_address_on_map/map_url_view.xml => partner_external_maps/map_website_view.xml (61%) create mode 100644 partner_external_maps/partner_external_maps.py rename {partner_address_on_map => partner_external_maps}/partner_view.xml (100%) rename {partner_address_on_map => partner_external_maps}/post_install.py (91%) create mode 100644 partner_external_maps/security/ir.model.access.csv rename {partner_address_on_map => partner_external_maps}/users_view.xml (60%) diff --git a/partner_address_on_map/__init__.py b/partner_address_on_map/__init__.py deleted file mode 100644 index 0b1bfe49d..000000000 --- a/partner_address_on_map/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -# -*- encoding: utf-8 -*- - -from . import partner_address_on_map -from .post_install import set_default_map_url diff --git a/partner_address_on_map/partner_address_on_map.py b/partner_address_on_map/partner_address_on_map.py deleted file mode 100644 index 3eeebbd45..000000000 --- a/partner_address_on_map/partner_address_on_map.py +++ /dev/null @@ -1,165 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# Partner Address on Map module for OpenERP -# Copyright (C) 2015 Akretion (http://www.akretion.com/) -# @author: Alexis de Lattre -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## - -from openerp import models, fields, api, _ -from openerp.exceptions import Warning - - -class MapUrl(models.Model): - _name = 'map.url' - _description = 'Map System' - - name = fields.Char(string='Map Provider', 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' - - # begin with context_ to allow user to change it by himself - context_map_url_id = fields.Many2one('map.url', string='Map Provider') - # IDEA : should we add the ability to have 1 map provider for map - # and another one for routing ? - context_route_start_partner_id = fields.Many2one( - 'res.partner', string='Start Address for Route Map') - - # called from post-install script - # I can't use a default method on the field, because it would be executed - # before loading map_url_data.xml, so it would not be able to set a value - @api.model - def _default_map_url(self): - users = self.env['res.users'].search([]) - map_url = self.env['map.url'].search([], limit=1) - users.write({'context_map_url_id': map_url.id}) - - -class ResPartner(models.Model): - _inherit = 'res.partner' - - @api.model - def address_as_string(self): - addr = u'' - if self.street: - addr += self.street - if self.street2: - addr += u' ' + self.street2 - if self.city: - addr += u' ' + self.city - if self.state_id: - addr += u' ' + self.state_id.name - if self.country_id: - addr += u' ' + self.country_id.name - return addr - - @api.multi - def open_map(self): - if not self.env.user.context_map_url_id: - raise Warning( - _('Missing map provider: ' - 'you should set it in your preferences.')) - map_url = self.env.user.context_map_url_id - if ( - map_url.lat_lon_url and - hasattr(self, 'partner_latitude') and - self.partner_latitude and self.partner_longitude): - url = map_url.lat_lon_url.replace( - '{LATITUDE}', unicode(self.partner_latitude)) - url = url.replace('{LONGITUDE}', unicode(self.partner_longitude)) - else: - if not map_url.address_url: - raise Warning( - _("Missing parameter 'URL that uses the address' " - "for map provider '%s'.") % map_url.name) - url = map_url.address_url.replace( - '{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_map_url_id: - raise Warning( - _('Missing map provider: ' - 'you should set it in your preferences.')) - map_url = self.env.user.context_map_url_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_url.route_address_url: - start_address = start_partner.address_as_string() - dest_address = self.address_as_string() - url = map_url.route_address_url - url = url.replace('{START_ADDRESS}', start_address) - url = url.replace('{DEST_ADDRESS}', dest_address) - else: - if not hasattr(self, 'partner_latitude'): - raise Warning( - _("Missing module 'base_geolocalize'")) - if not map_url.route_lat_lon_url: - raise Warning( - _("No route URL that uses latitude and longitude " - "on map provider '%s'.") % map_url.name) - url = map_url.route_lat_lon_url - if ( - not start_partner.partner_latitude or - not start_partner.partner_longitude): - raise Warning( - _("Missing geo-localization information on " - "start partner '%s'.")) - if not self.partner_latitude or not self.partner_longitude: - raise Warning( - _("Missing geo-localization information on destination " - "partner '%s'.") % self.name) - url = url.replace( - '{START_LATITUDE}', unicode(start_partner.partner_latitude)) - url = url.replace( - '{START_LONGITUDE}', unicode(start_partner.partner_longitude)) - url = url.replace( - '{DEST_LATITUDE}', unicode(self.partner_latitude)) - url = url.replace( - '{DEST_LONGITUDE}', unicode(self.partner_longitude)) - return { - 'type': 'ir.actions.act_url', - 'url': url, - 'target': 'new', - } diff --git a/partner_address_on_map/security/ir.model.access.csv b/partner_address_on_map/security/ir.model.access.csv deleted file mode 100644 index e7a521fcb..000000000 --- a/partner_address_on_map/security/ir.model.access.csv +++ /dev/null @@ -1,3 +0,0 @@ -id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink -access_map_url_read,Read access on map.url to everybody,model_map_url,,1,0,0,0 -access_map_url_full,Full access on map.url to System user,model_map_url,base.group_system,1,1,1,1 diff --git a/partner_external_maps/README.rst b/partner_external_maps/README.rst new file mode 100644 index 000000000..ba76971bf --- /dev/null +++ b/partner_external_maps/README.rst @@ -0,0 +1,52 @@ +Partner External Maps +===================== + +In the old days of Odoo/OpenERP, back in version 6.1, there was an official *google_map* module ; this module added a *Map* button on the partner form view and, when the user clicked on that button, it would open a new tab on its web browser and go to Google Map with a search on the address of the partner. + +This module aims at restoring this feature with several improvements: +* each user can select the map website he wants to use in its preferences +* there are now two buttons on the partner form view: one to open a regular map on the address of the partner, and another one to open an itinerary map from the start address configured in the preferences of the user to the address of the partner. + +This module supports several map websites: +* `Google Maps ` +* `OpenStreetMap ` +* `Bing Maps ` +* `Here Maps ` + +If the module *base_geolocalize* from the official addons is installed on the system, it will use the latitude and longitude to localize the partner (instead of the address) if this information is present on the partner. + +Configuration +============= + +If you want to create additionnal map websites, go to the menu *Sales > Configuration > Address Book > Localization > Map Websites*. You are invited to send the configuration information of your additionnal map websites to the author of the module, so that the module can be updated with more pre-configured map websites. + +Usage +===== + +First, you need to configure in your preferences: +* the map website to use for the regular maps, +* the map website to use for the route maps, +* the start address for the route maps. + +Then you can use the two new buttons on the partner form to open a regular map or a route map. + +Credits +======= + +Contributors +------------ + +* Alexis de Lattre + +Maintainer +---------- + +.. image:: http://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: http://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. + +To contribute to this module, please visit http://odoo-community.org. diff --git a/partner_external_maps/__init__.py b/partner_external_maps/__init__.py new file mode 100644 index 000000000..30f77e03d --- /dev/null +++ b/partner_external_maps/__init__.py @@ -0,0 +1,4 @@ +# -*- encoding: utf-8 -*- + +from . import partner_external_maps +from .post_install import set_default_map_settings diff --git a/partner_address_on_map/__openerp__.py b/partner_external_maps/__openerp__.py similarity index 79% rename from partner_address_on_map/__openerp__.py rename to partner_external_maps/__openerp__.py index 320395746..0d548a1b6 100644 --- a/partner_address_on_map/__openerp__.py +++ b/partner_external_maps/__openerp__.py @@ -1,7 +1,7 @@ # -*- encoding: utf-8 -*- ############################################################################## # -# Partner Address on Map module for Odoo +# Partner External Maps module for Odoo # Copyright (C) 2015 Akretion (http://www.akretion.com) # @author Alexis de Lattre # @@ -22,22 +22,22 @@ { - 'name': 'Partner Address on Map', + 'name': 'Partner External Maps', 'version': '0.1', - 'category': 'Contacts', + 'category': 'Extra Tools', 'license': 'AGPL-3', - 'summary': - 'Add Map button on partner form to open GMaps, OSM, Bing and others', + 'summary': 'Add Map and Map Routing buttons on partner form to ' + 'open GMaps, OSM, Bing and others', 'author': 'Akretion,Odoo Community Association (OCA)', 'website': 'http://www.akretion.com', 'depends': ['base'], 'data': [ 'partner_view.xml', - 'map_url_data.xml', - 'map_url_view.xml', + 'map_website_data.xml', + 'map_website_view.xml', 'users_view.xml', 'security/ir.model.access.csv', ], - 'post_init_hook': 'set_default_map_url', + 'post_init_hook': 'set_default_map_settings', 'installable': True, } diff --git a/partner_external_maps/i18n/fr.po b/partner_external_maps/i18n/fr.po new file mode 100644 index 000000000..0714d721c --- /dev/null +++ b/partner_external_maps/i18n/fr.po @@ -0,0 +1,190 @@ +# 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:42+0000\n" +"PO-Revision-Date: 2015-06-19 19:42+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:115 +#, python-format +msgid "Address missing on partner '%s'." +msgstr "Adresse manquante sur le partenaire '%s'." + +#. module: partner_external_maps +#: field:map.website,create_uid:0 +msgid "Created by" +msgstr "Créé par" + +#. module: partner_external_maps +#: field:map.website,create_date:0 +msgid "Created on" +msgstr "Créé le" + +#. module: partner_external_maps +#: field:map.website,id:0 +msgid "ID" +msgstr "ID" + +#. 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 "Carte" + +#. 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 "Site de carte" + +#. module: partner_external_maps +#: field:map.website,name:0 +msgid "Map Website Name" +msgstr "Nom du site de carte" + +#. 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 "Sites de carte" + +#. 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:191 +#, python-format +msgid "Missing geo-localization information on destination partner '%s'." +msgstr "" + +#. module: partner_external_maps +#: code:addons/partner_external_maps/partner_external_maps.py:187 +#, python-format +msgid "Missing geo-localization information on start partner '%s'." +msgstr "" + +#. module: partner_external_maps +#: code:addons/partner_external_maps/partner_external_maps.py:133 +#, 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:178 +#, python-format +msgid "Missing module 'base_geolocalize'" +msgstr "Module 'base_geolocalize' manquant" + +#. module: partner_external_maps +#: code:addons/partner_external_maps/partner_external_maps.py:147 +#, 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:162 +#, 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:167 +#, python-format +msgid "Missing start address for route map: you should set it in your preferences." +msgstr "" + +#. module: partner_external_maps +#: code:addons/partner_external_maps/partner_external_maps.py:181 +#, python-format +msgid "No route URL that uses latitude and longitude on map provider '%s'." +msgstr "" + +#. module: partner_external_maps +#: model:ir.model,name:partner_external_maps.model_res_partner +msgid "Partner" +msgstr "Partenaire" + +#. module: partner_external_maps +#: view:res.partner:partner_external_maps.view_partner_form +msgid "Route Map" +msgstr "Itinéraire" + +#. module: partner_external_maps +#: field:res.users,context_route_map_website_id:0 +msgid "Route Map Website" +msgstr "Site web pour les itinéraires" + +#. 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 "Adresse de départ pour les itinéraires" + +#. 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 "Utilisateurs" + diff --git a/partner_external_maps/i18n/partner_external_maps.pot b/partner_external_maps/i18n/partner_external_maps.pot new file mode 100644 index 000000000..c779a90e5 --- /dev/null +++ b/partner_external_maps/i18n/partner_external_maps.pot @@ -0,0 +1,172 @@ +# 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 "" + diff --git a/partner_address_on_map/map_url_data.xml b/partner_external_maps/map_website_data.xml similarity index 90% rename from partner_address_on_map/map_url_data.xml rename to partner_external_maps/map_website_data.xml index 891631c93..0b38c9b12 100644 --- a/partner_address_on_map/map_url_data.xml +++ b/partner_external_maps/map_website_data.xml @@ -8,7 +8,7 @@ - + Google Maps https://www.google.com/maps?ie=UTF8&q={ADDRESS} https://www.google.com/maps?z=15&q={LATITUDE},{LONGITUDE} @@ -16,26 +16,26 @@ https://www.google.com/maps?saddr={START_LATITUDE},{START_LONGITUDE}&daddr={DEST_LATITUDE},{DEST_LONGITUDE}&directionsmode=driving - + OpenStreetMap https://nominatim.openstreetmap.org/search?q={ADDRESS} https://www.openstreetmap.org/?zoom=15&mlat={LATITUDE}&mlon={LONGITUDE} https://www.openstreetmap.org/directions/?engine=orsm_car&route={START_LATITUDE},{START_LONGITUDE};{DEST_LATITUDE},{DEST_LONGITUDE} - + OpenStreetMap FR http://tile.openstreetmap.fr/?q={ADDRESS} http://tile.openstreetmap.fr/?zoom=15&lat={LATITUDE}&lon={LONGITUDE} - + Bing Maps https://www.bing.com/maps/default.aspx?where1={ADDRESS} https://www.bing.com/maps/default.aspx?cp={LATITUDE}~{LONGITUDE}&lvl=15 - + Here Maps https://here.com/search/{ADDRESS} https://www.here.com/?map={LATITUDE},{LONGITUDE},15,normal diff --git a/partner_address_on_map/map_url_view.xml b/partner_external_maps/map_website_view.xml similarity index 61% rename from partner_address_on_map/map_url_view.xml rename to partner_external_maps/map_website_view.xml index 75e529866..89079a825 100644 --- a/partner_address_on_map/map_url_view.xml +++ b/partner_external_maps/map_website_view.xml @@ -8,11 +8,11 @@ - - map.url.form - map.url + + map.website.form + map.website -
+ @@ -24,25 +24,25 @@ - - map.url.tree - map.url + + map.website.tree + map.website - + - - Map Providers - map.url + + Map Websites + map.website tree,form - diff --git a/partner_external_maps/partner_external_maps.py b/partner_external_maps/partner_external_maps.py new file mode 100644 index 000000000..6c5ec52e4 --- /dev/null +++ b/partner_external_maps/partner_external_maps.py @@ -0,0 +1,197 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Partner External Maps module for Odoo +# Copyright (C) 2015 Akretion (http://www.akretion.com/) +# @author: Alexis de Lattre +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +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' + + # begin with context_ to allow user to change it by himself + context_map_website_id = fields.Many2one( + 'map.website', string='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=[ + '|', ('address_url', '!=', False), ('lat_lon_url', '!=', False)], + 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', + domain=[ + '|', + ('route_address_url', '!=', False), + ('route_lat_lon_url', '!=', False)]) + + @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.env['map.website'].search([ + '|', ('address_url', '!=', False), ('lat_lon_url', '!=', False)], + limit=1) + map_route_website = self.env['map.website'].search([ + '|', + ('route_address_url', '!=', False), + ('route_lat_lon_url', '!=', False)], limit=1) + 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 = u'' + if self.street: + addr += self.street + if self.street2: + addr += u' ' + self.street2 + if self.city: + addr += u' ' + self.city + if self.state_id: + addr += u' ' + self.state_id.name + if self.country_id: + addr += u' ' + self.country_id.name + if not addr: + raise Warning( + _("Address missing on partner '%s'.") % self.name) + return 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): + 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', + } diff --git a/partner_address_on_map/partner_view.xml b/partner_external_maps/partner_view.xml similarity index 100% rename from partner_address_on_map/partner_view.xml rename to partner_external_maps/partner_view.xml diff --git a/partner_address_on_map/post_install.py b/partner_external_maps/post_install.py similarity index 91% rename from partner_address_on_map/post_install.py rename to partner_external_maps/post_install.py index 0772b7d29..ffc6354bd 100644 --- a/partner_address_on_map/post_install.py +++ b/partner_external_maps/post_install.py @@ -23,6 +23,6 @@ from openerp import SUPERUSER_ID -def set_default_map_url(cr, pool): - pool['res.users']._default_map_url(cr, SUPERUSER_ID) +def set_default_map_settings(cr, pool): + pool['res.users']._default_map_settings(cr, SUPERUSER_ID) return diff --git a/partner_external_maps/security/ir.model.access.csv b/partner_external_maps/security/ir.model.access.csv new file mode 100644 index 000000000..1f142ad3c --- /dev/null +++ b/partner_external_maps/security/ir.model.access.csv @@ -0,0 +1,3 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_map_website_read,Read access on map.website to everybody,model_map_website,,1,0,0,0 +access_map_website_full,Full access on map.website to System user,model_map_website,base.group_system,1,1,1,1 diff --git a/partner_address_on_map/users_view.xml b/partner_external_maps/users_view.xml similarity index 60% rename from partner_address_on_map/users_view.xml rename to partner_external_maps/users_view.xml index 65bb1e47f..38847127a 100644 --- a/partner_address_on_map/users_view.xml +++ b/partner_external_maps/users_view.xml @@ -9,13 +9,16 @@ - donation.res.users.form + map.res.users.form res.users - - - + + + + + + @@ -26,7 +29,10 @@ - + +