-
-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by yvaucher
- Loading branch information
Showing
52 changed files
with
4,814 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../website_geoengine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |
1 change: 1 addition & 0 deletions
1
setup/website_geoengine_store_locator/odoo/addons/website_geoengine_store_locator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../website_geoengine_store_locator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import controllers | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import res_partner |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import res_partner |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Oops, something went wrong.