diff --git a/geoengine_base_geolocalize/README.rst b/geoengine_base_geolocalize/README.rst new file mode 100644 index 000000000..3a11e09ed --- /dev/null +++ b/geoengine_base_geolocalize/README.rst @@ -0,0 +1,98 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +======================================= +Geospatial support for base_geolocalize +======================================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:d92cfbfb144aae040e97197cbecac7c6f4b663c59edb459339126e67473a5711 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fgeospatial-lightgray.png?logo=github + :target: https://github.com/OCA/geospatial/tree/19.0/geoengine_base_geolocalize + :alt: OCA/geospatial +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/geospatial-19-0/geospatial-19-0-geoengine_base_geolocalize + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/geospatial&target_branch=19.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Geolocalise your partner based on longitude and latitude provided by +`OpenStreetMap via its Nominatim +service `__. Please read +carefully the `usage +policy `__ +before using the module. + +**Table of contents** + +.. contents:: + :local: + +Installation +============ + +Take a look at the installation section in the description of the module +'base_geoengine'. + +The module also requires one additional python libs: + +- `requests `__ + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* ACSONE SA/NV + +Contributors +------------ + +- Laurent Mignon +- `APSL-Nagarro `__: + + - Antoni Marroig + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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. + +This module is part of the `OCA/geospatial `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/geoengine_base_geolocalize/__init__.py b/geoengine_base_geolocalize/__init__.py new file mode 100644 index 000000000..19b92ca2b --- /dev/null +++ b/geoengine_base_geolocalize/__init__.py @@ -0,0 +1,20 @@ +############################################################################## +# +# 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 models diff --git a/geoengine_base_geolocalize/__manifest__.py b/geoengine_base_geolocalize/__manifest__.py new file mode 100644 index 000000000..456c29126 --- /dev/null +++ b/geoengine_base_geolocalize/__manifest__.py @@ -0,0 +1,15 @@ +# 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": "19.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"], + "external_dependencies": {"python": ["requests"]}, + "data": ["views/res_partner_view.xml"], + "application": True, + "autoinstall": True, +} diff --git a/geoengine_base_geolocalize/i18n/geoengine_base_geolocalize.pot b/geoengine_base_geolocalize/i18n/geoengine_base_geolocalize.pot new file mode 100644 index 000000000..d474910cf --- /dev/null +++ b/geoengine_base_geolocalize/i18n/geoengine_base_geolocalize.pot @@ -0,0 +1,25 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * geoengine_base_geolocalize +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \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: geoengine_base_geolocalize +#: model:ir.model.fields,field_description:geoengine_base_geolocalize.field_res_partner__geo_point +#: model:ir.model.fields,field_description:geoengine_base_geolocalize.field_res_users__geo_point +msgid "Address coordinates" +msgstr "" + +#. module: geoengine_base_geolocalize +#: model:ir.model,name:geoengine_base_geolocalize.model_res_partner +msgid "Contact" +msgstr "" diff --git a/geoengine_base_geolocalize/i18n/it.po b/geoengine_base_geolocalize/i18n/it.po new file mode 100644 index 000000000..d0a37026f --- /dev/null +++ b/geoengine_base_geolocalize/i18n/it.po @@ -0,0 +1,28 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * geoengine_base_geolocalize +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-01-26 08:36+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: geoengine_base_geolocalize +#: model:ir.model.fields,field_description:geoengine_base_geolocalize.field_res_partner__geo_point +#: model:ir.model.fields,field_description:geoengine_base_geolocalize.field_res_users__geo_point +msgid "Address coordinates" +msgstr "Coordinate indirizzo" + +#. module: geoengine_base_geolocalize +#: model:ir.model,name:geoengine_base_geolocalize.model_res_partner +msgid "Contact" +msgstr "Contatto" diff --git a/geoengine_base_geolocalize/i18n/zh_CN.po b/geoengine_base_geolocalize/i18n/zh_CN.po new file mode 100644 index 000000000..e9fad85b1 --- /dev/null +++ b/geoengine_base_geolocalize/i18n/zh_CN.po @@ -0,0 +1,28 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * geoengine_base_geolocalize +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-11-25 09:06+0000\n" +"Last-Translator: xtanuiha \n" +"Language-Team: none\n" +"Language: zh_CN\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=1; plural=0;\n" +"X-Generator: Weblate 5.6.2\n" + +#. module: geoengine_base_geolocalize +#: model:ir.model.fields,field_description:geoengine_base_geolocalize.field_res_partner__geo_point +#: model:ir.model.fields,field_description:geoengine_base_geolocalize.field_res_users__geo_point +msgid "Address coordinates" +msgstr "地址坐标" + +#. module: geoengine_base_geolocalize +#: model:ir.model,name:geoengine_base_geolocalize.model_res_partner +msgid "Contact" +msgstr "联系人" diff --git a/geoengine_base_geolocalize/models/__init__.py b/geoengine_base_geolocalize/models/__init__.py new file mode 100644 index 000000000..91fed54d4 --- /dev/null +++ b/geoengine_base_geolocalize/models/__init__.py @@ -0,0 +1 @@ +from . import res_partner diff --git a/geoengine_base_geolocalize/models/res_partner.py b/geoengine_base_geolocalize/models/res_partner.py new file mode 100644 index 000000000..366397236 --- /dev/null +++ b/geoengine_base_geolocalize/models/res_partner.py @@ -0,0 +1,41 @@ +# Copyright 2015 ACSONE SA/NV () +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import api, fields, models + + +class ResPartner(models.Model): + """Add geo_point to partner using a function field""" + + _inherit = "res.partner" + + @api.depends("partner_latitude", "partner_longitude") + def _compute_geo_point(self): + """ + Set the `geo_point` of the partner depending of its `partner_latitude` + and its `partner_longitude` + **Notes** + If one of those parameters is not set then reset the partner's + geo_point and do not recompute it + """ + for rec in self: + if not rec.partner_latitude or not rec.partner_longitude: + rec.geo_point = False + else: + rec.geo_point = fields.GeoPoint.from_latlon( + rec.env.cr, rec.partner_latitude, rec.partner_longitude + ) + + geo_point = fields.GeoPoint( + store=True, compute="_compute_geo_point", inverse="_inverse_geo_point" + ) + + def _inverse_geo_point(self): + for rec in self: + if not rec.geo_point: + rec.partner_longitude, rec.partner_latitude = False, False + else: + ( + rec.partner_longitude, + rec.partner_latitude, + ) = fields.GeoPoint.to_latlon(rec.env.cr, rec.geo_point) diff --git a/geoengine_base_geolocalize/pyproject.toml b/geoengine_base_geolocalize/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/geoengine_base_geolocalize/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/geoengine_base_geolocalize/readme/CONTRIBUTORS.md b/geoengine_base_geolocalize/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..ec5970f4b --- /dev/null +++ b/geoengine_base_geolocalize/readme/CONTRIBUTORS.md @@ -0,0 +1,3 @@ +- Laurent Mignon \<\> +- [APSL-Nagarro](https://www.apsl.tech): + - Antoni Marroig \<\> \ No newline at end of file diff --git a/geoengine_base_geolocalize/readme/DESCRIPTION.md b/geoengine_base_geolocalize/readme/DESCRIPTION.md new file mode 100644 index 000000000..455235eb1 --- /dev/null +++ b/geoengine_base_geolocalize/readme/DESCRIPTION.md @@ -0,0 +1,3 @@ +Geolocalise your partner based on longitude and latitude provided by +[OpenStreetMap via its Nominatim service](http://wiki.openstreetmap.org/wiki/Nominatim). Please read carefully the +[usage policy](https://operations.osmfoundation.org/policies/nominatim/) before using the module. \ No newline at end of file diff --git a/geoengine_base_geolocalize/readme/INSTALL.md b/geoengine_base_geolocalize/readme/INSTALL.md new file mode 100644 index 000000000..19c77a886 --- /dev/null +++ b/geoengine_base_geolocalize/readme/INSTALL.md @@ -0,0 +1,6 @@ +Take a look at the installation section in the description of the module +'base_geoengine'. + +The module also requires one additional python libs: + +- [requests](https://pypi.python.org/pypi/requests) \ No newline at end of file diff --git a/geoengine_base_geolocalize/static/description/icon.png b/geoengine_base_geolocalize/static/description/icon.png new file mode 100644 index 000000000..b698310ee Binary files /dev/null and b/geoengine_base_geolocalize/static/description/icon.png differ diff --git a/geoengine_base_geolocalize/static/description/index.html b/geoengine_base_geolocalize/static/description/index.html new file mode 100644 index 000000000..28fca0ef2 --- /dev/null +++ b/geoengine_base_geolocalize/static/description/index.html @@ -0,0 +1,448 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

Geospatial support for base_geolocalize

+ +

Beta License: AGPL-3 OCA/geospatial Translate me on Weblate Try me on Runboat

+

Geolocalise your partner based on longitude and latitude provided by +OpenStreetMap via its Nominatim +service. Please read +carefully the usage +policy +before using the module.

+

Table of contents

+ +
+

Installation

+

Take a look at the installation section in the description of the module +‘base_geoengine’.

+

The module also requires one additional python libs:

+ +
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • ACSONE SA/NV
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

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.

+

This module is part of the OCA/geospatial project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+
+ + diff --git a/geoengine_base_geolocalize/tests/__init__.py b/geoengine_base_geolocalize/tests/__init__.py new file mode 100644 index 000000000..f16f53569 --- /dev/null +++ b/geoengine_base_geolocalize/tests/__init__.py @@ -0,0 +1 @@ +from . import test_geoengine_partner diff --git a/geoengine_base_geolocalize/tests/test_geoengine_partner.py b/geoengine_base_geolocalize/tests/test_geoengine_partner.py new file mode 100644 index 000000000..7b03c4d13 --- /dev/null +++ b/geoengine_base_geolocalize/tests/test_geoengine_partner.py @@ -0,0 +1,89 @@ +# Copyright 2015-2017 ACSONE SA/NV () +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +import re + +from requests import PreparedRequest, Response, Session + +from odoo.tests.common import TransactionCase + +PAYLOAD = [ + { + "place_id": 108312997, + "licence": "Data © OpenStreetMap contributors, ODbL 1.0. http://osm.org/copyright", + "osm_type": "way", + "osm_id": 318222295, + "lat": "49.9549071", + "lon": "5.4085830", + "class": "highway", + "type": "unclassified", + "place_rank": 26, + "importance": 0.053386585030899485, + "addresstype": "road", + "name": "Rue Au Bois la Dame", + "display_name": ( + "Rue Au Bois la Dame, Séviscourt, Bras, Libramont-Chevigny," + "Neufchâteau, Luxembourg, Wallonia, 6800, Belgium" + ), + "boundingbox": ["49.9535323", "49.9566288", "5.4053940", "5.4115772"], + } +] + + +class TestGeoenginePartner(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + + cls.nominatim_osm_request_re = re.compile( + r"https://nominatim.openstreetmap.org/search\?format=json&q=(.*)" + ) + + @classmethod + def _request_handler(cls, session: Session, request: PreparedRequest, /, **kwargs): + url = request.url.lower() + matching = cls.nominatim_osm_request_re.match(url) + if matching: + response = Response() + response.status_code = 200 + query = matching.group(1) + if query == "rue+au+bois+la+dame%2c+6800%2c+belgium": + response.json = lambda: PAYLOAD + return response + return super()._request_handler(session, request, **kwargs) + + def test_get_geo_point(self): + partner_id = self.env.ref("base.user_root").partner_id + partner_id.partner_longitude = False + partner_id.partner_latitude = False + self.assertFalse( + partner_id.geo_point, "Should not have geo_point with no latlon" + ) + partner_id.partner_latitude = 20 + self.assertFalse( + partner_id.geo_point, "Should not have geo_point with no latlon" + ) + partner_id.partner_longitude = 20 + self.assertTrue(partner_id.geo_point, "Should have geo_point") + + def test_geo_localize(self): + vals = { + "name": "Partner Project", + "street": "Rue au bois la dame", + "country_id": self.env.ref("base.be").id, + "zip": "6800", + } + partner_id = self.env["res.partner"].create(vals) + partner_id.name = "Other Partner" + partner_id.with_context(force_geo_localize=True).geo_localize() + self.assertAlmostEqual( + partner_id.partner_latitude, 49.9535323, 2, "Latitude Should be equals" + ) + self.assertAlmostEqual( + partner_id.partner_longitude, 5.4119073, 2, "Longitude Should be equals" + ) + domain = [("id", "=", partner_id.id)] + partner_id.unlink() + self.assertFalse( + self.env["res.partner"].search(domain), + "Should not have this partner anymore", + ) diff --git a/geoengine_base_geolocalize/views/res_partner_view.xml b/geoengine_base_geolocalize/views/res_partner_view.xml new file mode 100644 index 000000000..4194dff5f --- /dev/null +++ b/geoengine_base_geolocalize/views/res_partner_view.xml @@ -0,0 +1,19 @@ + + + + geo_partner_form + res.partner + + + + 1 + + + + + + + diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 000000000..b4d39fb9e --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +# generated from manifests external_dependencies +requests diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 000000000..dab3d0e78 --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1,2 @@ +odoo-addon-base_geoengine @ git+https://github.com/OCA/geospatial.git@refs/pull/414/head#subdirectory=base_geoengine +odoo-addon-geoengine_partner @ git+https://github.com/OCA/geospatial.git@refs/pull/450/head#subdirectory=geoengine_partner