From 4e478e91852e9da3122dbf32b8fbb41f24ffb708 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Thu, 18 Jun 2015 00:19:30 +0200 Subject: [PATCH 01/13] Add module partner_address_on_map --- partner_address_on_map/__init__.py | 3 + partner_address_on_map/__openerp__.py | 40 ++++++++++++ partner_address_on_map/map_url_data.xml | 27 ++++++++ partner_address_on_map/map_url_view.xml | 46 +++++++++++++ .../partner_address_on_map.py | 65 +++++++++++++++++++ partner_address_on_map/partner_view.xml | 27 ++++++++ partner_address_on_map/users_view.xml | 34 ++++++++++ 7 files changed, 242 insertions(+) create mode 100644 partner_address_on_map/__init__.py create mode 100644 partner_address_on_map/__openerp__.py create mode 100644 partner_address_on_map/map_url_data.xml create mode 100644 partner_address_on_map/map_url_view.xml create mode 100644 partner_address_on_map/partner_address_on_map.py create mode 100644 partner_address_on_map/partner_view.xml create mode 100644 partner_address_on_map/users_view.xml diff --git a/partner_address_on_map/__init__.py b/partner_address_on_map/__init__.py new file mode 100644 index 000000000..792da988c --- /dev/null +++ b/partner_address_on_map/__init__.py @@ -0,0 +1,3 @@ +# -*- encoding: utf-8 -*- + +from . import partner_address_on_map diff --git a/partner_address_on_map/__openerp__.py b/partner_address_on_map/__openerp__.py new file mode 100644 index 000000000..9efe28dad --- /dev/null +++ b/partner_address_on_map/__openerp__.py @@ -0,0 +1,40 @@ +# -*- 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 . +# +############################################################################## + + +{ + 'name': 'Partner Address on Map', + 'version': '0.1', + 'category': 'Contacts', + 'license': 'AGPL-3', + 'summary': 'Add Map button on partner form view to open GMaps, OSM or 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', + 'users_view.xml', + ], + 'installable': True, +} diff --git a/partner_address_on_map/map_url_data.xml b/partner_address_on_map/map_url_data.xml new file mode 100644 index 000000000..28456a4f5 --- /dev/null +++ b/partner_address_on_map/map_url_data.xml @@ -0,0 +1,27 @@ + + + + + + + + OpenStreetMap FR + http://tile.openstreetmap.fr/?q= + + + + Google Maps + http://maps.google.com/maps?oi=map&q= + + + + Bing Maps + http://www.bing.com/maps/default.aspx?rtp=adr. + + + + diff --git a/partner_address_on_map/map_url_view.xml b/partner_address_on_map/map_url_view.xml new file mode 100644 index 000000000..88fb69c87 --- /dev/null +++ b/partner_address_on_map/map_url_view.xml @@ -0,0 +1,46 @@ + + + + + + + + map.url.form + map.url + +
+ + + + +
+
+
+ + + map.url.tree + map.url + + + + + + + + + + Map Providers + map.url + tree,form + + + + + +
+
diff --git a/partner_address_on_map/partner_address_on_map.py b/partner_address_on_map/partner_address_on_map.py new file mode 100644 index 000000000..bbb144aa6 --- /dev/null +++ b/partner_address_on_map/partner_address_on_map.py @@ -0,0 +1,65 @@ +# -*- 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) + url = fields.Char(string='URL', required=True) + + +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') + # TODO: Add default + + +class ResPartner(models.Model): + _inherit = 'res.partner' + + @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.')) + url = self.env.user.context_map_url_id.url + if self.street: + url += self.street + if self.city: + url += ' ' + self.city + if self.state_id: + url += ' ' + self.state_id.name + if self.country_id: + url += ' ' + self.country_id.name + return { + 'type': 'ir.actions.act_url', + 'url': url, + 'targer': 'new', + } diff --git a/partner_address_on_map/partner_view.xml b/partner_address_on_map/partner_view.xml new file mode 100644 index 000000000..2884473cd --- /dev/null +++ b/partner_address_on_map/partner_view.xml @@ -0,0 +1,27 @@ + + + + + + + + + map.button.res.partner.form + res.partner + + + +