Skip to content

Commit

Permalink
Merge PR #376 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by yvaucher
  • Loading branch information
OCA-git-bot committed Oct 30, 2024
2 parents 6018cdc + e277c99 commit f7a5bb1
Show file tree
Hide file tree
Showing 52 changed files with 4,814 additions and 21 deletions.
1 change: 1 addition & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ globals:
openerp: readonly
owl: readonly
luxon: readonly
ol: readonly

# Styling is handled by Prettier, so we only need to enable AST rules;
# see https://github.com/OCA/maintainer-quality-tools/pull/618#issuecomment-558576890
Expand Down
34 changes: 17 additions & 17 deletions base_geoengine/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,23 +97,23 @@ def get_geo_func(current_operator, operator, left, right, params, table):
"""
This method will call the SQL query corresponding to the requested geo operator
"""
match operator:
case "geo_greater":
query = current_operator.get_geo_greater_sql(table, left, right, params)
case "geo_lesser":
query = current_operator.get_geo_lesser_sql(table, left, right, params)
case "geo_equal":
query = current_operator.get_geo_equal_sql(table, left, right, params)
case "geo_touch":
query = current_operator.get_geo_touch_sql(table, left, right, params)
case "geo_within":
query = current_operator.get_geo_within_sql(table, left, right, params)
case "geo_contains":
query = current_operator.get_geo_contains_sql(table, left, right, params)
case "geo_intersect":
query = current_operator.get_geo_intersect_sql(table, left, right, params)
case _:
raise NotImplementedError(f"The operator {operator} is not supported")

if operator == "geo_greater":
query = current_operator.get_geo_greater_sql(table, left, right, params)
elif operator == "geo_lesser":
query = current_operator.get_geo_lesser_sql(table, left, right, params)
elif operator == "geo_equal":
query = current_operator.get_geo_equal_sql(table, left, right, params)
elif operator == "geo_touch":
query = current_operator.get_geo_touch_sql(table, left, right, params)
elif operator == "geo_within":
query = current_operator.get_geo_within_sql(table, left, right, params)
elif operator == "geo_contains":
query = current_operator.get_geo_contains_sql(table, left, right, params)
elif operator == "geo_intersect":
query = current_operator.get_geo_intersect_sql(table, left, right, params)
else:
raise NotImplementedError(f"The operator {operator} is not supported")
return query


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ export class GeoengineRenderer extends Component {
.getSource()
.getExtent();
var infinite_extent = [Infinity, Infinity, -Infinity, -Infinity];
if (extent !== infinite_extent) {
if (JSON.stringify(extent) !== JSON.stringify(infinite_extent)) {
var map_view = this.map.getView();
if (map_view) {
map_view.fit(extent, {maxZoom: 15});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ export class RecordsPanel extends Component {
*/
filterItems(value, items) {
const lowerValue = value.toLowerCase();
return items.filter(
(item) => item.data.display_name.toLowerCase().indexOf(lowerValue) >= 0
return items.filter((item) =>
item.data && item.data.display_name
? item.data.display_name.toLowerCase().indexOf(lowerValue) >= 0
: false
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion geoengine_partner/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"author": "Camptocamp, Odoo Community Association (OCA)",
"license": "AGPL-3",
"website": "https://github.com/OCA/geospatial",
"depends": ["base", "base_geoengine"],
"depends": ["base", "base_geoengine", "contacts"],
"data": ["views/partner.xml"],
"installable": True,
"application": True,
Expand Down
13 changes: 13 additions & 0 deletions geoengine_partner/views/partner.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,17 @@
<field eval="0" name="overlay" />
</record>

<record id="contacts.action_contacts" model="ir.actions.act_window">
<field name="view_mode">kanban,tree,form,activity,geoengine</field>
</record>



<record id="action_contacts_view_map" model="ir.actions.act_window.view">
<field name="sequence" eval="3" />
<field name="view_mode">geoengine</field>
<field name="view_id" ref="ir_ui_view_geo_partner" />
<field name="act_window_id" ref="contacts.action_contacts" />
</record>

</odoo>
1 change: 1 addition & 0 deletions setup/website_geoengine/odoo/addons/website_geoengine
6 changes: 6 additions & 0 deletions setup/website_geoengine/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
6 changes: 6 additions & 0 deletions setup/website_geoengine_store_locator/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
84 changes: 84 additions & 0 deletions website_geoengine/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
==================
Geospatial Website
==================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:f9c3c1b51848bfa78b041913165f41f2c4d084c77204c7dcacc0ad61f7559a9d
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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/licence-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/16.0/website_geoengine
:alt: OCA/geospatial
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/geospatial-16-0/geospatial-16-0-website_geoengine
: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=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module extends the ``website`` odoo module, to allow
add endpoints in order to exchange geospatial data with the frontend.


**Table of contents**

.. contents::
:local:

Configuration
=============

No configuration needed. Just install the module and you are ready to go.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/geospatial/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 <https://github.com/OCA/geospatial/issues/new?body=module:%20website_geoengine%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
~~~~~~~

* Camptocamp

Contributors
~~~~~~~~~~~~

* Stéphane Brunner <stephane.brunner@camptocamp.com>
* Hadrien Huvelle <hadrien.huvelle@camptocamp.com>

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 <https://github.com/OCA/geospatial/tree/16.0/website_geoengine>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions website_geoengine/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import controllers
from . import models
14 changes: 14 additions & 0 deletions website_geoengine/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2011-2017 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
{
"name": "Geospatial Website",
"version": "16.0.1.0.0",
"category": "GeoBI",
"author": "Camptocamp, Odoo Community Association (OCA)",
"license": "AGPL-3",
"website": "https://github.com/OCA/geospatial",
"depends": ["base_geoengine", "website", "partner_store"],
"data": [],
"installable": True,
"application": True,
}
1 change: 1 addition & 0 deletions website_geoengine/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import res_partner
19 changes: 19 additions & 0 deletions website_geoengine/controllers/res_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import http


class ResPartner(http.Controller):
@http.route("/website-geoengine/tags", type="json", auth="public", cors="*")
def tags(self, **kw):
tags = kw.get("tags", {})
lang = kw.get("lang", "en_US")
return http.request.env["res.partner"].get_search_tags(tags, lang)

@http.route("/website-geoengine/partners", type="json", auth="public", cors="*")
def partners(self, **kw):
tags = kw.get("tags", {})
lang = kw.get("lang", "en_US")
maxResults = kw.get("maxResults", "200")
return http.request.env["res.partner"].fetch_partner_geoengine(
tags, lang, maxResults
)
1 change: 1 addition & 0 deletions website_geoengine/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import res_partner
120 changes: 120 additions & 0 deletions website_geoengine/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Copyright 2011-2024 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

from odoo import _, api, fields, models
from odoo.exceptions import ValidationError


class ResPartner(models.Model):
_inherit = "res.partner"

opening_hours = fields.Char(string="Opening hours")

AUTHORIZED_FIELDS = ["name", "city", "zip", "street", "street2", "tag"]

@api.model
def get_search_tags(self, search, lang):
sql = """
WITH
names as (
SELECT
DISTINCT 'name' as column,
name as value
FROM
res_partner
WHERE
type='store'),
cities as (
SELECT
DISTINCT 'city' as column,
city as value
FROM
res_partner
WHERE
type='store'),
zips as (
SELECT
DISTINCT 'zip' as column,
zip as value
FROM
res_partner
WHERE
type='store'),
streets as (
SELECT
DISTINCT 'street' as column,
concat(street, street2) as value
FROM
res_partner
WHERE
type='store'),
tags as (
SELECT
DISTINCT 'tag' as column,
res_partner_category.name->>%s as value
FROM
res_partner_category,
res_partner_res_partner_category_rel,
res_partner
WHERE
res_partner_res_partner_category_rel.partner_id = res_partner.id
AND
res_partner_res_partner_category_rel.category_id = res_partner_category.id
AND res_partner.type='store'
),
all_tags as (
SELECT * FROM names
UNION SELECT * FROM cities
UNION SELECT * FROM zips
UNION SELECT * FROM streets
UNION SELECT * FROM tags )
SELECT * FROM all_tags WHERE value ILIKE %s;
"""
self._cr.execute(sql, (lang, f"%{search}%"))
results = self._cr.fetchall()
return results

@api.model
def fetch_partner_geoengine(self, tags, lang, maxResults):
domain = [("type", "=", "store")]
for tag in tags:
field, value = tag.values()
if field not in self.AUTHORIZED_FIELDS:
raise ValidationError(_("Unauthorized field"))
domain.append((field.replace("tag", "category_id.name"), "ilike", value))

partners = self.sudo().search(domain)
features = []

if len(partners) > int(maxResults):
return {
"error": "Too many results",
"message": f"Too many results: {len(partners)}",
}

for partner in partners:
features.append(
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
partner.partner_longitude,
partner.partner_latitude,
],
},
"properties": {
"id": partner.id or None,
"name": partner.name or "",
"zip": partner.zip or "",
"city": partner.city or "",
"street": partner.street or "",
"street2": partner.street2 or "",
"tags": partner.category_id.mapped("name") or "",
"opening_hours": partner.opening_hours or "",
},
}
)
return features
1 change: 1 addition & 0 deletions website_geoengine/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
No configuration needed. Just install the module and you are ready to go.
2 changes: 2 additions & 0 deletions website_geoengine/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Stéphane Brunner <stephane.brunner@camptocamp.com>
* Hadrien Huvelle <hadrien.huvelle@camptocamp.com>
3 changes: 3 additions & 0 deletions website_geoengine/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This module extends the ``website`` odoo module, to allow
add endpoints in order to exchange geospatial data with the frontend.

Empty file.
Loading

0 comments on commit f7a5bb1

Please sign in to comment.