From fa0bbc0f0539ffaad30e3485539ec97f8a7e25b8 Mon Sep 17 00:00:00 2001 From: Benjamin Willig Date: Mon, 2 Oct 2017 12:04:12 +0200 Subject: [PATCH] [MIG] geoengine_base_geolocalize migration --- geoengine_base_geolocalize/__manifest__.py | 67 +++++-------- geoengine_base_geolocalize/models/__init__.py | 20 ---- .../models/res_partner.py | 95 +++++++------------ .../tests/test_geoengine_partner.py | 25 +---- .../views/res_partner_view.xml | 28 +++--- .../.eggs/README.txt | 6 ++ .../odoo/__init__.py | 1 + .../odoo/addons/__init__.py | 1 + .../odoo/addons/geoengine_base_geolocalize | 1 + setup/geoengine_base_geolocalize/setup.py | 6 ++ 10 files changed, 90 insertions(+), 160 deletions(-) create mode 100644 setup/geoengine_base_geolocalize/.eggs/README.txt create mode 100644 setup/geoengine_base_geolocalize/odoo/__init__.py create mode 100644 setup/geoengine_base_geolocalize/odoo/addons/__init__.py create mode 120000 setup/geoengine_base_geolocalize/odoo/addons/geoengine_base_geolocalize create mode 100644 setup/geoengine_base_geolocalize/setup.py diff --git a/geoengine_base_geolocalize/__manifest__.py b/geoengine_base_geolocalize/__manifest__.py index e079e53607..68db218ade 100644 --- a/geoengine_base_geolocalize/__manifest__.py +++ b/geoengine_base_geolocalize/__manifest__.py @@ -1,42 +1,27 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Author: Laurent Mignon -# Copyright (c) 2015 Acsone SA/NV (http://www.acsone.eu) -# -# 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': 'Geospatial support for base_geolocalize', - 'version': '8.0.0.1.0', - 'category': 'GeoBI', - 'author': "ACSONE SA/NV, Odoo Community Association (OCA)", - 'license': 'AGPL-3', - 'website': 'http://www.acsone.eu', - 'depends': [ - 'base', - 'geoengine_partner', - 'base_geolocalize', - ], - 'external_dependencies': { - 'python': ['requests'], - }, - 'data': [ - 'views/res_partner_view.xml' - ], - 'installable': False, - 'application': True, - 'autoinstall': True, - 'active': False, - } +# Copyright 2015-2017 ACSONE SA/NV () +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +{ + 'name': 'Geospatial support for base_geolocalize', + 'version': '10.0.1.0.0', + 'category': 'GeoBI', + 'author': "ACSONE SA/NV, Odoo Community Association (OCA)", + 'license': 'AGPL-3', + 'website': 'https://github.com/OCA/geospatial', + 'depends': [ + 'base', + 'geoengine_partner', + 'base_geolocalize', + 'base_geolocalize_openstreetmap', + ], + 'external_dependencies': { + 'python': [ + 'requests' + ], + }, + 'data': [ + 'views/res_partner_view.xml' + ], + 'application': True, + 'autoinstall': True, +} diff --git a/geoengine_base_geolocalize/models/__init__.py b/geoengine_base_geolocalize/models/__init__.py index fcb3548e65..91fed54d40 100644 --- a/geoengine_base_geolocalize/models/__init__.py +++ b/geoengine_base_geolocalize/models/__init__.py @@ -1,21 +1 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# Author: Laurent Mignon -# Copyright (c) 2015 Acsone SA/NV (http://www.acsone.eu) -# -# 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 . import res_partner diff --git a/geoengine_base_geolocalize/models/res_partner.py b/geoengine_base_geolocalize/models/res_partner.py index 87fc2384ea..01d99e5da9 100644 --- a/geoengine_base_geolocalize/models/res_partner.py +++ b/geoengine_base_geolocalize/models/res_partner.py @@ -1,36 +1,11 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Author: Laurent Mignon -# Copyright (c) 2015 Acsone SA/NV (http://www.acsone.eu) -# -# 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 . -# -############################################################################## +# Copyright 2015 ACSONE SA/NV () +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). import logging -from openerp import api, fields -from openerp import exceptions -from openerp.tools.translate import _ -from openerp.addons.base_geoengine import geo_model -from openerp.addons.base_geoengine import fields as geo_fields - -try: - import requests -except ImportError: - logger = logging.getLogger(__name__) - logger.warning('requests is not available in the sys path') +from odoo import api, fields +from odoo.addons.base_geoengine import geo_model +from odoo.addons.base_geoengine import fields as geo_fields _logger = logging.getLogger(__name__) @@ -39,44 +14,37 @@ class ResPartner(geo_model.GeoModel): """Add geo_point to partner using a function field""" _inherit = "res.partner" - @api.one + @api.multi def geocode_address(self): """Get the latitude and longitude by requesting "mapquestapi" see http://open.mapquestapi.com/geocoding/ """ - url = 'http://nominatim.openstreetmap.org/search' - pay_load = { - 'limit': 1, - 'format': 'json', - 'street': self.street or '', - 'postalCode': self.zip or '', - 'city': self.city or '', - 'state': self.state_id and self.state_id.name or '', - 'country': self.country_id and self.country_id.name or '', - 'countryCodes': self.country_id and self.country_id.code or ''} - - request_result = requests.get(url, params=pay_load) - try: - request_result.raise_for_status() - except Exception as e: - _logger.exception('Geocoding error') - raise exceptions.Warning(_( - 'Geocoding error. \n %s') % e.message) - vals = request_result.json() - vals = vals and vals[0] or {} + self.ensure_one() + values = self.env[ + 'geoengine.geolocalize.openstreetmap' + ].geocode_address( + self.street or '', + self.zip or '', + self.city or '', + self.state_id and self.state_id.name or '', + self.country_id and self.country_id.name or '', + self.country_id and self.country_id.code or '', + ) self.write({ - 'partner_latitude': vals.get('lat'), - 'partner_longitude': vals.get('lon'), - 'date_localization': fields.Date.today()}) + 'partner_latitude': values.get('lat'), + 'partner_longitude': values.get('lon'), + 'date_localization': fields.Date.today() + }) - @api.one + @api.multi def geo_localize(self): + self.ensure_one() self.geocode_address() return True - @api.one + @api.multi @api.depends('partner_latitude', 'partner_longitude') - def _get_geo_point(self): + def _compute_geo_point(self): """ Set the `geo_point` of the partner depending of its `partner_latitude` and its `partner_longitude` @@ -84,11 +52,12 @@ def _get_geo_point(self): If one of those parameters is not set then reset the partner's geo_point and do not recompute it """ - if not self.partner_latitude or not self.partner_longitude: - self.geo_point = False - else: - self.geo_point = geo_fields.GeoPoint.from_latlon( - self.env.cr, self.partner_latitude, self.partner_longitude) + for rec in self: + if not rec.partner_latitude or not rec.partner_longitude: + rec.geo_point = False + else: + rec.geo_point = geo_fields.GeoPoint.from_latlon( + rec.env.cr, rec.partner_latitude, rec.partner_longitude) geo_point = geo_fields.GeoPoint( - readonly=True, store=True, compute='_get_geo_point') + readonly=True, store=True, compute='_compute_geo_point') diff --git a/geoengine_base_geolocalize/tests/test_geoengine_partner.py b/geoengine_base_geolocalize/tests/test_geoengine_partner.py index bdebff2b9b..75fdef1884 100644 --- a/geoengine_base_geolocalize/tests/test_geoengine_partner.py +++ b/geoengine_base_geolocalize/tests/test_geoengine_partner.py @@ -1,30 +1,11 @@ # -*- coding: utf-8 -*- -# -# -# Authors: Jonathan Nemry -# Copyright (c) 2015 Acsone SA/NV (http://www.acsone.eu) -# -# 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 . -# -import openerp.tests.common as common +# Copyright 2015-2017 ACSONE SA/NV () +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +import odoo.tests.common as common class TestGeoenginePartner(common.TransactionCase): - def setUp(self): - common.TransactionCase.setUp(self) - def test_get_geo_point(self): partner_id = self.env.ref('base.user_root').partner_id partner_id.partner_longitude = False diff --git a/geoengine_base_geolocalize/views/res_partner_view.xml b/geoengine_base_geolocalize/views/res_partner_view.xml index 29d4190613..fcba4ec1d2 100644 --- a/geoengine_base_geolocalize/views/res_partner_view.xml +++ b/geoengine_base_geolocalize/views/res_partner_view.xml @@ -1,16 +1,16 @@ - - - - geo_partner_form - res.partner - - - - - + + + + geo_partner_form + res.partner + + + + - - - + + + + diff --git a/setup/geoengine_base_geolocalize/.eggs/README.txt b/setup/geoengine_base_geolocalize/.eggs/README.txt new file mode 100644 index 0000000000..5d01668824 --- /dev/null +++ b/setup/geoengine_base_geolocalize/.eggs/README.txt @@ -0,0 +1,6 @@ +This directory contains eggs that were downloaded by setuptools to build, test, and run plug-ins. + +This directory caches those eggs to prevent repeated downloads. + +However, it is safe to delete this directory. + diff --git a/setup/geoengine_base_geolocalize/odoo/__init__.py b/setup/geoengine_base_geolocalize/odoo/__init__.py new file mode 100644 index 0000000000..de40ea7ca0 --- /dev/null +++ b/setup/geoengine_base_geolocalize/odoo/__init__.py @@ -0,0 +1 @@ +__import__('pkg_resources').declare_namespace(__name__) diff --git a/setup/geoengine_base_geolocalize/odoo/addons/__init__.py b/setup/geoengine_base_geolocalize/odoo/addons/__init__.py new file mode 100644 index 0000000000..de40ea7ca0 --- /dev/null +++ b/setup/geoengine_base_geolocalize/odoo/addons/__init__.py @@ -0,0 +1 @@ +__import__('pkg_resources').declare_namespace(__name__) diff --git a/setup/geoengine_base_geolocalize/odoo/addons/geoengine_base_geolocalize b/setup/geoengine_base_geolocalize/odoo/addons/geoengine_base_geolocalize new file mode 120000 index 0000000000..01e6adc904 --- /dev/null +++ b/setup/geoengine_base_geolocalize/odoo/addons/geoengine_base_geolocalize @@ -0,0 +1 @@ +../../../../geoengine_base_geolocalize/ \ No newline at end of file diff --git a/setup/geoengine_base_geolocalize/setup.py b/setup/geoengine_base_geolocalize/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/geoengine_base_geolocalize/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)