Skip to content

Commit

Permalink
[MIG] base_geoengine: Migration to 17.0
Browse files Browse the repository at this point in the history
>
>
Co-authored-by: Antoni Marroig Campomar <[email protected]>
Co-authored-by: Red Butay <@reichie020212>
Co-authored-by: Miquel Alzanillas <[email protected]>
Co-authored-by: Sergio Sancho <[email protected]>
"
  • Loading branch information
peluko00 committed Sep 27, 2024
1 parent 2a7cdd3 commit 5142637
Show file tree
Hide file tree
Showing 62 changed files with 731 additions and 339 deletions.
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:12.0
image: postgis/postgis:13-3.4
env:
POSTGRES_USER: odoo
POSTGRES_PASSWORD: odoo
Expand Down
1 change: 1 addition & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ fix = true
extend-select = [
"B",
"C90",
"E501", # line too long (default 88)
"I", # isort
"UP", # pyupgrade
]
Expand Down
7 changes: 7 additions & 0 deletions base_geoengine/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,13 @@ Contributors
- Alexandre Saunier <[email protected]>
- Sandip Mangukiya <[email protected]>
- Samuel Kouff <[email protected]>
- `APSL-Nagarro <https://www.apsl.tech>`__:

- Antoni Marroig <[email protected]>
- Miquel Alzanillas <[email protected]>

- Red Butay <>
- Sergio Sancho <[email protected]>

Maintainers
-----------
Expand Down
4 changes: 2 additions & 2 deletions base_geoengine/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Geospatial support for Odoo",
"version": "16.0.1.0.0",
"version": "17.0.1.0.0",
"category": "GeoBI",
"author": "Camptocamp,ACSONE SA/NV,Odoo Community Association (OCA)",
"license": "AGPL-3",
Expand All @@ -30,7 +30,7 @@
("include", "web._assets_bootstrap"),
]
},
"external_dependencies": {"python": ["shapely", "geojson", "simplejson"]},
"external_dependencies": {"python": ["shapely", "geojson"]},
"installable": True,
"pre_init_hook": "init_postgis",
}
5 changes: 2 additions & 3 deletions base_geoengine/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from odoo.osv import expression
from odoo.osv.expression import TERM_OPERATORS
from odoo.tools import Query
from odoo.tools import SQL, Query

from .fields import GeoField
from .geo_operators import GeoOperator
Expand Down Expand Up @@ -35,7 +35,6 @@ def __leaf_to_sql(self, leaf, model, alias):
geo_operators into the Odoo search method.
"""
left, operator, right = leaf

if isinstance(leaf, list | tuple):
current_field = model._fields.get(left)
current_operator = GeoOperator(current_field)
Expand Down Expand Up @@ -89,7 +88,7 @@ def __leaf_to_sql(self, leaf, model, alias):
query = get_geo_func(
current_operator, operator, left, right, params, model._table
)
return query, params
return SQL(query, *params)
return original__leaf_to_sql(self, leaf=leaf, model=model, alias=alias)


Expand Down
36 changes: 21 additions & 15 deletions base_geoengine/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from odoo.tools import sql

from . import geo_convertion_helper as convert
from .geo_db import create_geo_column
from .geo_db import create_geo_column, create_geo_index

logger = logging.getLogger(__name__)
try:
Expand All @@ -30,13 +30,18 @@ class GeoField(fields.Field):
"""

geo_type = None
dim = 2
dim = "2"
srid = 3857
gist_index = True

@property
def column_type(self):
return ("geometry", f"geometry({self.geo_type.upper()}, {self.srid})")
postgis_geom_type = self.geo_type.upper() if self.geo_type else "GEOMETRY"
if self.dim == "3":
postgis_geom_type += "Z"

Check warning on line 41 in base_geoengine/fields.py

View check run for this annotation

Codecov / codecov/patch

base_geoengine/fields.py#L41

Added line #L41 was not covered by tests
elif self.dim == "4":
postgis_geom_type += "ZM"

Check warning on line 43 in base_geoengine/fields.py

View check run for this annotation

Codecov / codecov/patch

base_geoengine/fields.py#L43

Added line #L43 was not covered by tests
return ("geometry", f"geometry({postgis_geom_type}, {self.srid})")

def convert_to_column(self, value, record, values=None):
"""Convert value to database format
Expand Down Expand Up @@ -106,7 +111,8 @@ def entry_to_shape(self, value, same_type=False):
if same_type and not shape.is_empty:
if shape.geom_type.lower() != self.geo_type.lower():
msg = _(

Check warning on line 113 in base_geoengine/fields.py

View check run for this annotation

Codecov / codecov/patch

base_geoengine/fields.py#L113

Added line #L113 was not covered by tests
"Geo Value %(geom_type)s must be of the same type %(geo_type)s as fields",
"Geo Value %(geom_type)s must be of the same type %(geo_type)s \
as fields",
geom_type=shape.geom_type.lower(),
geo_type=self.geo_type.lower(),
)
Expand Down Expand Up @@ -157,14 +163,7 @@ def update_geo_db_column(self, model):
)
)
if self.gist_index:
cr.execute(
"SELECT indexname FROM pg_indexes WHERE indexname = %s",
(self._postgis_index_name(model._table, self.name),),
)
index = cr.fetchone()
if index:
return True
self._create_index(cr, model._table, self.name)
create_geo_index(cr, self.name, model._table)
return True

Check warning on line 167 in base_geoengine/fields.py

View check run for this annotation

Codecov / codecov/patch

base_geoengine/fields.py#L166-L167

Added lines #L166 - L167 were not covered by tests

def update_db_column(self, model, column):
Expand All @@ -188,9 +187,13 @@ def update_db_column(self, model, column):
self.dim,
self.string,
)
if self.gist_index:
create_geo_index(model._cr, self.name, model._table)
return

Check warning on line 192 in base_geoengine/fields.py

View check run for this annotation

Codecov / codecov/patch

base_geoengine/fields.py#L191-L192

Added lines #L191 - L192 were not covered by tests

if column["udt_name"] == self.column_type[0]:
if self.gist_index:
create_geo_index(model._cr, self.name, model._table)
return

self.update_geo_db_column(model)

Check warning on line 199 in base_geoengine/fields.py

View check run for this annotation

Codecov / codecov/patch

base_geoengine/fields.py#L199

Added line #L199 was not covered by tests
Expand Down Expand Up @@ -269,10 +272,13 @@ def from_latlon(cls, cr, latitude, longitude):

@classmethod
def to_latlon(cls, cr, geopoint):
"""Convert a UTM coordinate point to (latitude, longitude):"""
# Line to execute to retrieve longitude, latitude from UTM in postgres command line:
"""Convert a UTM coordinate point to \
(latitude, longitude):"""
# Line to execute to retrieve
# longitude, latitude from UTM in postgres command line:
# SELECT ST_X(geom), ST_Y(geom) FROM (SELECT ST_TRANSFORM(ST_SetSRID(
# ST_MakePoint(601179.61612, 6399375,681364), 900913), 4326) as geom) g;
# ST_MakePoint(601179.61612, 6399375,681364),
# ..............900913), 4326) as geom) g;
if isinstance(geopoint, BaseGeometry):
geo_point_instance = geopoint

Check warning on line 283 in base_geoengine/fields.py

View check run for this annotation

Codecov / codecov/patch

base_geoengine/fields.py#L283

Added line #L283 was not covered by tests
else:
Expand Down
4 changes: 3 additions & 1 deletion base_geoengine/geo_db.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright 2011-2012 Nicolas Bessi (Camptocamp SA)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
"""Helper to setup Postgis"""

import logging

from odoo import _
Expand All @@ -11,12 +12,13 @@
_schema = logging.getLogger("odoo.schema")


def init_postgis(cr):
def init_postgis(env):
"""Initialize postgis
Add PostGIS support to the database. PostGIS is a spatial database
extender for PostgreSQL object-relational database. It adds support for
geographic objects allowing location queries to be run in SQL.
"""
cr = env.cr
cr.execute(
"""
SELECT
Expand Down
14 changes: 7 additions & 7 deletions base_geoengine/i18n/base_geoengine.pot
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ msgstr ""

#. module: base_geoengine
#: model:ir.model.fields.selection,name:base_geoengine.selection__ir_model_fields__geo_type__linestring
msgid "LINESTRING"
msgid "LineString"
msgstr ""

#. module: base_geoengine
Expand Down Expand Up @@ -373,17 +373,17 @@ msgstr ""

#. module: base_geoengine
#: model:ir.model.fields.selection,name:base_geoengine.selection__ir_model_fields__geo_type__multilinestring
msgid "MULTILINESTRING"
msgid "MultiLineString"
msgstr ""

#. module: base_geoengine
#: model:ir.model.fields.selection,name:base_geoengine.selection__ir_model_fields__geo_type__multipoint
msgid "MULTIPOINT"
msgid "MultiPoint"
msgstr ""

#. module: base_geoengine
#: model:ir.model.fields.selection,name:base_geoengine.selection__ir_model_fields__geo_type__multipolygon
msgid "MULTIPOLYGON"
msgid "MultiPolygon"
msgstr ""

#. module: base_geoengine
Expand Down Expand Up @@ -488,17 +488,17 @@ msgstr ""

#. module: base_geoengine
#: model:ir.model.fields.selection,name:base_geoengine.selection__ir_model_fields__geo_type__point
msgid "POINT"
msgid "Point"
msgstr ""

#. module: base_geoengine
#: model:ir.model.fields.selection,name:base_geoengine.selection__ir_model_fields__geo_type__polygon
msgid "POLYGON"
msgid "Polygon"
msgstr ""

#. module: base_geoengine
#: model:ir.model.fields,field_description:base_geoengine.field_geoengine_raster_layer__params
#: model:ir.model.fields,field_description:base_geoengine.field_geoengine_raster_layer__params_wms
#: model_terms:ir.ui.view,arch_db:base_geoengine.geo_raster_view_form
msgid "Params"
msgstr ""

Expand Down
26 changes: 13 additions & 13 deletions base_geoengine/i18n/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,8 @@ msgstr "¿Es una capa de superposición?"

#. module: base_geoengine
#: model:ir.model.fields.selection,name:base_geoengine.selection__ir_model_fields__geo_type__linestring
msgid "LINESTRING"
msgstr "SECUENCIA DE LÍNEAS"
msgid "LineString"
msgstr "Secuencia de líneas"

#. module: base_geoengine
#: model:ir.model.fields,field_description:base_geoengine.field_geoengine_raster_layer____last_update
Expand Down Expand Up @@ -393,18 +393,18 @@ msgstr "Lista de dimensiones separadas por ','"

#. module: base_geoengine
#: model:ir.model.fields.selection,name:base_geoengine.selection__ir_model_fields__geo_type__multilinestring
msgid "MULTILINESTRING"
msgstr "CADENA MULTILÍNEA"
msgid "MultiLineString"
msgstr "Cadena multilínea"

#. module: base_geoengine
#: model:ir.model.fields.selection,name:base_geoengine.selection__ir_model_fields__geo_type__multipoint
msgid "MULTIPOINT"
msgstr "PUNTO MÚLTIPLE"
msgid "MultiPoint"
msgstr "Punto Múltiple"

#. module: base_geoengine
#: model:ir.model.fields.selection,name:base_geoengine.selection__ir_model_fields__geo_type__multipolygon
msgid "MULTIPOLYGON"
msgstr "MULTIPOLÍGONO"
msgid "MultiPolygon"
msgstr "Multipolígono"

#. module: base_geoengine
#: model:ir.model.fields,field_description:base_geoengine.field_geoengine_raster_layer__matrix_set
Expand Down Expand Up @@ -508,17 +508,17 @@ msgstr "OpenStreetMap"

#. module: base_geoengine
#: model:ir.model.fields.selection,name:base_geoengine.selection__ir_model_fields__geo_type__point
msgid "POINT"
msgstr "PUNTO"
msgid "Point"
msgstr "Punto"

#. module: base_geoengine
#: model:ir.model.fields.selection,name:base_geoengine.selection__ir_model_fields__geo_type__polygon
msgid "POLYGON"
msgstr "POLÍGONO"
msgid "Polygon"
msgstr "Polígono"

#. module: base_geoengine
#: model:ir.model.fields,field_description:base_geoengine.field_geoengine_raster_layer__params
#: model:ir.model.fields,field_description:base_geoengine.field_geoengine_raster_layer__params_wms
#: model_terms:ir.ui.view,arch_db:base_geoengine.geo_raster_view_form
msgid "Params"
msgstr "Parámetros"

Expand Down
14 changes: 7 additions & 7 deletions base_geoengine/i18n/fr_BE.po
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ msgstr "S'agit-il d'une couche superposée ?"

#. module: base_geoengine
#: model:ir.model.fields.selection,name:base_geoengine.selection__ir_model_fields__geo_type__linestring
msgid "LINESTRING"
msgid "LineString"
msgstr ""

#. module: base_geoengine
Expand Down Expand Up @@ -394,17 +394,17 @@ msgstr "Liste des dimensions séparées par ','"

#. module: base_geoengine
#: model:ir.model.fields.selection,name:base_geoengine.selection__ir_model_fields__geo_type__multilinestring
msgid "MULTILINESTRING"
msgid "MultiLineString"
msgstr ""

#. module: base_geoengine
#: model:ir.model.fields.selection,name:base_geoengine.selection__ir_model_fields__geo_type__multipoint
msgid "MULTIPOINT"
msgid "MultiPoint"
msgstr ""

#. module: base_geoengine
#: model:ir.model.fields.selection,name:base_geoengine.selection__ir_model_fields__geo_type__multipolygon
msgid "MULTIPOLYGON"
msgid "MultiPolygon"
msgstr ""

#. module: base_geoengine
Expand Down Expand Up @@ -509,17 +509,17 @@ msgstr ""

#. module: base_geoengine
#: model:ir.model.fields.selection,name:base_geoengine.selection__ir_model_fields__geo_type__point
msgid "POINT"
msgid "Point"
msgstr ""

#. module: base_geoengine
#: model:ir.model.fields.selection,name:base_geoengine.selection__ir_model_fields__geo_type__polygon
msgid "POLYGON"
msgid "Polygon"
msgstr ""

#. module: base_geoengine
#: model:ir.model.fields,field_description:base_geoengine.field_geoengine_raster_layer__params
#: model:ir.model.fields,field_description:base_geoengine.field_geoengine_raster_layer__params_wms
#: model_terms:ir.ui.view,arch_db:base_geoengine.geo_raster_view_form
msgid "Params"
msgstr "Paramètres"

Expand Down
Loading

0 comments on commit 5142637

Please sign in to comment.