Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 0 additions & 34 deletions base_geoengine_demo/UPGRADE.md

This file was deleted.

2 changes: 1 addition & 1 deletion base_geoengine_demo/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion base_geoengine_demo/i18n/base_geoengine_demo.pot
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions base_geoengine_demo/i18n/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions base_geoengine_demo/i18n/it.po
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions base_geoengine_demo/i18n/zh_CN.po
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions base_geoengine_demo/models/geo_npa.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
43 changes: 21 additions & 22 deletions base_geoengine_demo/models/retail_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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),
],

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Edited areas leave invalid assignments

When a ZIP geometry is edited so it no longer contains a machine assigned to that ZIP, editing a ZIP polygon does not invoke _check_the_point on its retail machines, so machines whose points are no longer inside their assigned ZIP remain stored with invalid assignments; a concurrent polygon edit after this search can produce the same state.

Validate linked machines when ZIP geometry changes, and make that validation safe against concurrent geometry and machine updates.

Prompt for AI agents
In `base_geoengine_demo/models/retail_machine.py` at line 37:

**Edited areas leave invalid assignments**

When a ZIP geometry is edited so it no longer contains a machine assigned to that ZIP, editing a ZIP polygon does not invoke `_check_the_point` on its retail machines, so machines whose points are no longer inside their assigned ZIP remain stored with invalid assignments; a concurrent polygon edit after this search can produce the same state.

Validate linked machines when ZIP geometry changes, and make that validation safe against concurrent geometry and machine updates.

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):
Expand All @@ -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
1 change: 1 addition & 0 deletions base_geoengine_demo/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_retail_machine
82 changes: 82 additions & 0 deletions base_geoengine_demo/tests/test_retail_machine.py
Original file line number Diff line number Diff line change
@@ -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")
1 change: 1 addition & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
odoo-addon-base_geoengine @ git+https://github.com/OCA/geospatial@refs/pull/465/head#subdirectory=base_geoengine
Loading