diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6101a2b02..a1c5d6843 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -42,7 +42,7 @@ jobs: makepot: "true" services: postgres: - image: postgres:13 + image: postgis/postgis:13-3.4 env: POSTGRES_USER: odoo POSTGRES_PASSWORD: odoo diff --git a/base_geoengine_demo/UPGRADE.md b/base_geoengine_demo/UPGRADE.md deleted file mode 100644 index 680931b57..000000000 --- a/base_geoengine_demo/UPGRADE.md +++ /dev/null @@ -1,34 +0,0 @@ -# base_geoengine_demo: 17.0 -> 18.0 migration log - -## Changes - -- Manifest version bumped `17.0.1.0.1` -> `18.0.1.0.0`. -- `README.rst` / `static/description/index.html` regenerated by the OCA - `oca-gen-addon-readme` pre-commit hook (branch references updated 17.0 -> 18.0). -- XML views (`views/zip.xml`, `views/retail_machine.xml`): `` -> `` tag - rename and `view_mode="tree,..."` -> `view_mode="list,..."`, applied automatically via - Odoo's native `upgrade_code` tool (`odoo/upgrade_code/17.5-01-tree-to-list.py`, part - of the 17.0 -> 18.0 core rename of the tree/list view type). No `attrs`/`states` usage - was found in this module, so no attribute-syntax migration was needed. -- No Python API breakage found: `models/geo_npa.py` and `models/retail_machine.py` - needed no changes. - -## Dependency - -`base_geoengine` (this module's only dependency) was already fully migrated to 18.0 -(`18.0.1.2.1`) prior to this work. - -## Testing - -- Clean install verified on a fresh 18.0 database (`base_geoengine_demo` + - `base_geoengine` both installed successfully, no errors/tracebacks). -- Demo data loads correctly: 455 `dummy.zip` records, 37 - `geoengine.demo.automatic.retailing.machine` records. -- `odev test -i base_geoengine_demo` was attempted but is not meaningful here: this - module ships no tests of its own, and the command re-installs+tests the full - dependency graph including Odoo core `base`/`web`, which surfaced failures unrelated - to this migration (missing `rlPyCairo` render backend for a `base` QWeb barcode test, - headless-browser HOOT JS test failures, and log-level-dependent `base` test - assertions). None of these touch `base_geoengine`, `base_geoengine_demo`, or any - geospatial code. -- `ruff check --select F821,F822,F405` and `xmllint --noout` pass on all files. diff --git a/base_geoengine_demo/__manifest__.py b/base_geoengine_demo/__manifest__.py index 92dc19d88..be7199aa8 100644 --- a/base_geoengine_demo/__manifest__.py +++ b/base_geoengine_demo/__manifest__.py @@ -2,7 +2,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { "name": "Geo spatial support Demo", - "version": "18.0.1.0.0", + "version": "19.0.1.0.0", "category": "GeoBI", "author": "Camptocamp,Odoo Community Association (OCA)", "license": "AGPL-3", diff --git a/base_geoengine_demo/i18n/base_geoengine_demo.pot b/base_geoengine_demo/i18n/base_geoengine_demo.pot index 16fb76ac6..d182f997f 100644 --- a/base_geoengine_demo/i18n/base_geoengine_demo.pot +++ b/base_geoengine_demo/i18n/base_geoengine_demo.pot @@ -266,7 +266,7 @@ msgstr "" #: code:addons/base_geoengine_demo/models/retail_machine.py:0 #, python-format msgid "" -"The point must be placed in the corresponding area. (serial number: %s)." +"The point must be placed in the corresponding area. (serial number: %(name)s)." msgstr "" #. module: base_geoengine_demo diff --git a/base_geoengine_demo/i18n/es.po b/base_geoengine_demo/i18n/es.po index 7ea0d08ee..924d63a8f 100644 --- a/base_geoengine_demo/i18n/es.po +++ b/base_geoengine_demo/i18n/es.po @@ -269,9 +269,9 @@ msgstr "El punto" #: code:addons/base_geoengine_demo/models/retail_machine.py:0 #, python-format msgid "" -"The point must be placed in the corresponding area. (serial number: %s)." +"The point must be placed in the corresponding area. (serial number: %(name)s)." msgstr "" -"El punto debe colocarse en la zona correspondiente. (número de serie: %s)." +"El punto debe colocarse en la zona correspondiente. (número de serie: %(name)s)." #. module: base_geoengine_demo #: model_terms:ir.ui.view,arch_db:base_geoengine_demo.ir_ui_view_resbetterzipgeoview0 diff --git a/base_geoengine_demo/i18n/it.po b/base_geoengine_demo/i18n/it.po index af22180b3..1e9495d44 100644 --- a/base_geoengine_demo/i18n/it.po +++ b/base_geoengine_demo/i18n/it.po @@ -269,10 +269,10 @@ msgstr "Il punto" #: code:addons/base_geoengine_demo/models/retail_machine.py:0 #, python-format msgid "" -"The point must be placed in the corresponding area. (serial number: %s)." +"The point must be placed in the corresponding area. (serial number: %(name)s)." msgstr "" "Il punto deve essere posizionato nell'area corrispondente. (numero seriale: " -"%s)." +"%(name)s)." #. module: base_geoengine_demo #: model_terms:ir.ui.view,arch_db:base_geoengine_demo.ir_ui_view_resbetterzipgeoview0 diff --git a/base_geoengine_demo/i18n/zh_CN.po b/base_geoengine_demo/i18n/zh_CN.po index 04065f35c..f8e209921 100644 --- a/base_geoengine_demo/i18n/zh_CN.po +++ b/base_geoengine_demo/i18n/zh_CN.po @@ -269,8 +269,8 @@ msgstr "点" #: code:addons/base_geoengine_demo/models/retail_machine.py:0 #, python-format msgid "" -"The point must be placed in the corresponding area. (serial number: %s)." -msgstr "点必须放置在相应的区域。(序列号:%s)。" +"The point must be placed in the corresponding area. (serial number: %(name)s)." +msgstr "点必须放置在相应的区域。(序列号:%(name)s)。" #. module: base_geoengine_demo #: model_terms:ir.ui.view,arch_db:base_geoengine_demo.ir_ui_view_resbetterzipgeoview0 diff --git a/base_geoengine_demo/models/geo_npa.py b/base_geoengine_demo/models/geo_npa.py index 6239cea5e..521e8328f 100644 --- a/base_geoengine_demo/models/geo_npa.py +++ b/base_geoengine_demo/models/geo_npa.py @@ -48,11 +48,7 @@ def _compute_ZIP_total_sales(self): "where id in %s;", (tuple(res.ids),), ) - res = cursor.fetchone() - if res: - rec.total_sales = res[0] or 0.0 - else: - rec.total_sales = 0.0 + rec.total_sales = cursor.fetchone()[0] or 0.0 else: rec.total_sales = 0.0 diff --git a/base_geoengine_demo/models/retail_machine.py b/base_geoengine_demo/models/retail_machine.py index 5397a9f60..4f42cbaf5 100644 --- a/base_geoengine_demo/models/retail_machine.py +++ b/base_geoengine_demo/models/retail_machine.py @@ -2,7 +2,7 @@ # Copyright 2023 ACSONE SA/NV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import _, api, fields, models +from odoo import api, fields, models from odoo.exceptions import ValidationError @@ -25,27 +25,26 @@ class RetailMachine(models.Model): @api.constrains("the_point", "zip_id") def _check_the_point(self): """Check if the point is place in the corresponding area.""" - if self.the_point and self.zip_id: - for rec in self: - zip_match = ( - self.env["dummy.zip"] - .search( - [ - ("id", "=", self.zip_id.id), - ("the_geom", "geo_contains", rec.the_point), - ], - limit=1, - ) - .ids + for rec in self: + if not rec.the_point or not rec.zip_id: + continue + zip_match = ( + self.env["dummy.zip"] + .search( + [ + ("id", "=", rec.zip_id.id), + ("the_geom", "geo_contains", rec.the_point), + ], + limit=1, + ) + .ids + ) + if not zip_match: + message = self.env._( + "The point must be placed in the corresponding area. " + "(serial number: %(name)s)." ) - if not zip_match: - raise ValidationError( - _( - "The point must be placed in the corresponding " - + "area. (serial number: %s).", - rec.name, - ) - ) + raise ValidationError(message % {"name": rec.name}) @api.depends("the_point") def _compute_zip_id(self): @@ -63,4 +62,4 @@ def _compute_zip_id(self): if zip_match: rec.zip_id = zip_match[0] else: - rec.zip_id = 0 + rec.zip_id = False diff --git a/base_geoengine_demo/tests/__init__.py b/base_geoengine_demo/tests/__init__.py new file mode 100644 index 000000000..52383d3d5 --- /dev/null +++ b/base_geoengine_demo/tests/__init__.py @@ -0,0 +1 @@ +from . import test_retail_machine diff --git a/base_geoengine_demo/tests/test_retail_machine.py b/base_geoengine_demo/tests/test_retail_machine.py new file mode 100644 index 000000000..e23841d1f --- /dev/null +++ b/base_geoengine_demo/tests/test_retail_machine.py @@ -0,0 +1,82 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.exceptions import ValidationError +from odoo.tests.common import TransactionCase + + +class TestRetailMachine(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.zip_a_id = cls.env["dummy.zip"].create( + { + "name": "9991", + "city": "Square A", + "the_geom": "MULTIPOLYGON (((0 0, 1000 0, 1000 1000, 0 1000, 0 0)))", + } + ) + cls.zip_b_id = cls.env["dummy.zip"].create( + { + "name": "9992", + "city": "Square B", + "the_geom": "MULTIPOLYGON (((2000 0, 3000 0, 3000 1000, 2000 1000, " + "2000 0)))", + } + ) + cls.machine_model = cls.env["geoengine.demo.automatic.retailing.machine"] + + def test_compute_zip_from_point(self): + machine_id = self.machine_model.create( + {"name": "M-1", "the_point": "POINT (500 500)", "total_sales": 10.0} + ) + self.assertEqual(machine_id.zip_id, self.zip_a_id) + machine_id.the_point = "POINT (2500 500)" + self.assertEqual(machine_id.zip_id, self.zip_b_id) + + def test_compute_zip_without_point(self): + machine_id = self.machine_model.create( + {"name": "M-7", "the_point": "POINT (500 500)"} + ) + self.assertEqual(machine_id.zip_id, self.zip_a_id) + machine_id.the_point = False + self.assertFalse(machine_id.zip_id) + + def test_compute_zip_point_outside_zips(self): + machine_id = self.machine_model.create( + {"name": "M-8", "the_point": "POINT (5000 5000)"} + ) + self.assertFalse(machine_id.zip_id) + + def test_zip_total_sales(self): + self.machine_model.create( + [ + {"name": "M-2", "the_point": "POINT (100 100)", "total_sales": 10.0}, + {"name": "M-3", "the_point": "POINT (900 900)", "total_sales": 5.5}, + ] + ) + self.assertAlmostEqual(self.zip_a_id.total_sales, 15.5) + self.assertAlmostEqual(self.zip_b_id.total_sales, 0.0) + + def test_point_outside_zip_raises(self): + with self.assertRaises(ValidationError): + self.machine_model.create( + { + "name": "M-4", + "the_point": "POINT (500 500)", + "zip_id": self.zip_b_id.id, + } + ) + + def test_constraint_multi_records(self): + machine_ids = self.machine_model.create( + [ + {"name": "M-5", "the_point": "POINT (500 500)"}, + {"name": "M-6", "the_point": "POINT (2500 500)"}, + ] + ) + self.assertEqual(machine_ids.zip_id, self.zip_a_id | self.zip_b_id) + with self.assertRaises(ValidationError): + machine_ids.write({"zip_id": self.zip_a_id.id}) + + def test_display_name(self): + self.assertEqual(self.zip_a_id.display_name, "9991 Square A") diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 000000000..5e5827c1e --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1 @@ +odoo-addon-base_geoengine @ git+https://github.com/OCA/geospatial@refs/pull/465/head#subdirectory=base_geoengine