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
90 changes: 90 additions & 0 deletions website_geoengine/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
==================
Geospatial Website
==================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:c50ec63ee1157d56ef50a5eec4e8f755a6845da87e67cbeea8b64fe36db8f6c3
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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/17.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-17-0/geospatial-17-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=17.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.

Usage
=====



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:%2017.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>
- Cédric Paradis <cparadis@impressfoods.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/17.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": "17.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
)
35 changes: 35 additions & 0 deletions website_geoengine/i18n/it.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * website_geoengine
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2024-11-03 17:06+0000\n"
"Last-Translator: mymage <stefano.consolaro@mymage.it>\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 5.6.2\n"

#. module: website_geoengine
#: model:ir.model,name:website_geoengine.model_res_partner
msgid "Contact"
msgstr "Contatto"

#. module: website_geoengine
#: model:ir.model.fields,field_description:website_geoengine.field_res_partner__opening_hours
#: model:ir.model.fields,field_description:website_geoengine.field_res_users__opening_hours
msgid "Opening hours"
msgstr "Ore apertura"

#. module: website_geoengine
#. odoo-python
#: code:addons/website_geoengine/models/res_partner.py:0
#, python-format
msgid "Unauthorized field"
msgstr "Campo non autorizzato"
32 changes: 32 additions & 0 deletions website_geoengine/i18n/website_geoengine.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * website_geoengine
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.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: website_geoengine
#: model:ir.model,name:website_geoengine.model_res_partner
msgid "Contact"
msgstr ""

#. module: website_geoengine
#: model:ir.model.fields,field_description:website_geoengine.field_res_partner__opening_hours
#: model:ir.model.fields,field_description:website_geoengine.field_res_users__opening_hours
msgid "Opening hours"
msgstr ""

#. module: website_geoengine
#. odoo-python
#: code:addons/website_geoengine/models/res_partner.py:0
#, python-format
msgid "Unauthorized field"
msgstr ""
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
123 changes: 123 additions & 0 deletions website_geoengine/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# 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
3 changes: 3 additions & 0 deletions website_geoengine/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
2 changes: 2 additions & 0 deletions website_geoengine/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
No configuration needed. Just install the module and you are ready to
go.
3 changes: 3 additions & 0 deletions website_geoengine/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Stéphane Brunner \<stephane.brunner@camptocamp.com\>
- Hadrien Huvelle \<hadrien.huvelle@camptocamp.com\>
- Cédric Paradis \<cparadis@impressfoods.com\>
2 changes: 2 additions & 0 deletions website_geoengine/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This module extends the `website` odoo module, to allow add endpoints in
order to exchange geospatial data with the frontend.
1 change: 1 addition & 0 deletions website_geoengine/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Binary file added website_geoengine/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading