Browse Source

Add ACL

Add post-install script to set a default value in the users's preferences
Take street2 into account
pull/134/head
Alexis de Lattre 10 years ago
parent
commit
0cbcc32968
  1. 1
      partner_address_on_map/__init__.py
  2. 4
      partner_address_on_map/__openerp__.py
  3. 10
      partner_address_on_map/map_url_data.xml
  4. 19
      partner_address_on_map/partner_address_on_map.py
  5. 28
      partner_address_on_map/post_install.py
  6. 3
      partner_address_on_map/security/ir.model.access.csv

1
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

4
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,
}

10
partner_address_on_map/map_url_data.xml

@ -8,16 +8,16 @@
<openerp>
<data>
<record id="openstreetmap_fr" model="map.url">
<field name="name">OpenStreetMap FR</field>
<field name="url">http://tile.openstreetmap.fr/?q=</field>
</record>
<record id="google_maps" model="map.url">
<field name="name">Google Maps</field>
<field name="url">http://maps.google.com/maps?oi=map&amp;q=</field>
</record>
<record id="openstreetmap_fr" model="map.url">
<field name="name">OpenStreetMap FR</field>
<field name="url">http://tile.openstreetmap.fr/?q=</field>
</record>
<record id="bing_maps" model="map.url">
<field name="name">Bing Maps</field>
<field name="url">http://www.bing.com/maps/default.aspx?rtp=adr.</field>

19
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',
}

28
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 <alexis.delattre@akretion.com>
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp import SUPERUSER_ID
def set_default_map_url(cr, pool):
pool['res.users']._default_map_url(cr, SUPERUSER_ID)
return

3
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
Loading…
Cancel
Save