diff --git a/partner_address_on_map/__init__.py b/partner_address_on_map/__init__.py index 792da988c..0b1bfe49d 100644 --- a/partner_address_on_map/__init__.py +++ b/partner_address_on_map/__init__.py @@ -1,3 +1,4 @@ # -*- encoding: utf-8 -*- from . import partner_address_on_map +from .post_install import set_default_map_url diff --git a/partner_address_on_map/__openerp__.py b/partner_address_on_map/__openerp__.py index 9efe28dad..eea25566b 100644 --- a/partner_address_on_map/__openerp__.py +++ b/partner_address_on_map/__openerp__.py @@ -26,7 +26,7 @@ 'version': '0.1', 'category': 'Contacts', 'license': 'AGPL-3', - 'summary': 'Add Map button on partner form view to open GMaps, OSM or others', + 'summary': 'Add Map button on partner form to open GMaps, OSM or others', 'author': 'Akretion,Odoo Community Association (OCA)', 'website': 'http://www.akretion.com', 'depends': ['base'], @@ -35,6 +35,8 @@ 'map_url_data.xml', 'map_url_view.xml', 'users_view.xml', + 'security/ir.model.access.csv', ], + 'post_init_hook': 'set_default_map_url', 'installable': True, } diff --git a/partner_address_on_map/map_url_data.xml b/partner_address_on_map/map_url_data.xml index 28456a4f5..26129b733 100644 --- a/partner_address_on_map/map_url_data.xml +++ b/partner_address_on_map/map_url_data.xml @@ -8,16 +8,16 @@ - - OpenStreetMap FR - http://tile.openstreetmap.fr/?q= - - Google Maps http://maps.google.com/maps?oi=map&q= + + OpenStreetMap FR + http://tile.openstreetmap.fr/?q= + + Bing Maps http://www.bing.com/maps/default.aspx?rtp=adr. diff --git a/partner_address_on_map/partner_address_on_map.py b/partner_address_on_map/partner_address_on_map.py index bbb144aa6..9936e3fcc 100644 --- a/partner_address_on_map/partner_address_on_map.py +++ b/partner_address_on_map/partner_address_on_map.py @@ -38,7 +38,15 @@ class ResUsers(models.Model): # begin with context_ to allow user to change it by himself context_map_url_id = fields.Many2one( 'map.url', string='Map Provider') - # TODO: Add default + + # 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): @@ -47,11 +55,14 @@ class ResPartner(models.Model): @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.')) + raise Warning( + _('Missing map provider: ' + 'you should set it in your preferences.')) url = self.env.user.context_map_url_id.url if self.street: url += self.street + if self.street2: + url += ' ' + self.street2 if self.city: url += ' ' + self.city if self.state_id: @@ -61,5 +72,5 @@ class ResPartner(models.Model): return { 'type': 'ir.actions.act_url', 'url': url, - 'targer': 'new', + 'target': 'new', } diff --git a/partner_address_on_map/post_install.py b/partner_address_on_map/post_install.py new file mode 100644 index 000000000..0772b7d29 --- /dev/null +++ b/partner_address_on_map/post_install.py @@ -0,0 +1,28 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Partner Address on Map 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 SUPERUSER_ID + + +def set_default_map_url(cr, pool): + pool['res.users']._default_map_url(cr, SUPERUSER_ID) + return diff --git a/partner_address_on_map/security/ir.model.access.csv b/partner_address_on_map/security/ir.model.access.csv new file mode 100644 index 000000000..e7a521fcb --- /dev/null +++ b/partner_address_on_map/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_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