Skip to content

Commit cdd9bec

Browse files
[MIG] website_geoengine: Migration to 17.0
1 parent 1a882fc commit cdd9bec

16 files changed

Lines changed: 763 additions & 0 deletions

File tree

website_geoengine/README.rst

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
==================
2+
Geospatial Website
3+
==================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:c50ec63ee1157d56ef50a5eec4e8f755a6845da87e67cbeea8b64fe36db8f6c3
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18+
:alt: License: AGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fgeospatial-lightgray.png?logo=github
20+
:target: https://github.com/OCA/geospatial/tree/17.0/website_geoengine
21+
:alt: OCA/geospatial
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/geospatial-17-0/geospatial-17-0-website_geoengine
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/geospatial&target_branch=17.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
This module extends the ``website`` odoo module, to allow add endpoints
32+
in order to exchange geospatial data with the frontend.
33+
34+
**Table of contents**
35+
36+
.. contents::
37+
:local:
38+
39+
Configuration
40+
=============
41+
42+
No configuration needed. Just install the module and you are ready to
43+
go.
44+
45+
Usage
46+
=====
47+
48+
49+
50+
Bug Tracker
51+
===========
52+
53+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/geospatial/issues>`_.
54+
In case of trouble, please check there if your issue has already been reported.
55+
If you spotted it first, help us to smash it by providing a detailed and welcomed
56+
`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**>`_.
57+
58+
Do not contact contributors directly about support or help with technical issues.
59+
60+
Credits
61+
=======
62+
63+
Authors
64+
-------
65+
66+
* Camptocamp
67+
68+
Contributors
69+
------------
70+
71+
- Stéphane Brunner <[email protected]>
72+
- Hadrien Huvelle <[email protected]>
73+
- Cédric Paradis <[email protected]>
74+
75+
Maintainers
76+
-----------
77+
78+
This module is maintained by the OCA.
79+
80+
.. image:: https://odoo-community.org/logo.png
81+
:alt: Odoo Community Association
82+
:target: https://odoo-community.org
83+
84+
OCA, or the Odoo Community Association, is a nonprofit organization whose
85+
mission is to support the collaborative development of Odoo features and
86+
promote its widespread use.
87+
88+
This module is part of the `OCA/geospatial <https://github.com/OCA/geospatial/tree/17.0/website_geoengine>`_ project on GitHub.
89+
90+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

website_geoengine/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import controllers
2+
from . import models

website_geoengine/__manifest__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright 2011-2017 Camptocamp SA
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
3+
{
4+
"name": "Geospatial Website",
5+
"version": "17.0.1.0.0",
6+
"category": "GeoBI",
7+
"author": "Camptocamp, Odoo Community Association (OCA)",
8+
"license": "AGPL-3",
9+
"website": "https://github.com/OCA/geospatial",
10+
"depends": ["base_geoengine", "website", "partner_store"],
11+
"data": [],
12+
"installable": True,
13+
"application": True,
14+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import res_partner
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
2+
from odoo import http
3+
4+
5+
class ResPartner(http.Controller):
6+
@http.route("/website-geoengine/tags", type="json", auth="public", cors="*")
7+
def tags(self, **kw):
8+
tags = kw.get("tags", {})
9+
lang = kw.get("lang", "en_US")
10+
return http.request.env["res.partner"].get_search_tags(tags, lang)
11+
12+
@http.route("/website-geoengine/partners", type="json", auth="public", cors="*")
13+
def partners(self, **kw):
14+
tags = kw.get("tags", {})
15+
lang = kw.get("lang", "en_US")
16+
maxResults = kw.get("maxResults", "200")
17+
return http.request.env["res.partner"].fetch_partner_geoengine(
18+
tags, lang, maxResults
19+
)

website_geoengine/i18n/it.po

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Translation of Odoo Server.
2+
# This file contains the translation of the following modules:
3+
# * website_geoengine
4+
#
5+
msgid ""
6+
msgstr ""
7+
"Project-Id-Version: Odoo Server 16.0\n"
8+
"Report-Msgid-Bugs-To: \n"
9+
"PO-Revision-Date: 2024-11-03 17:06+0000\n"
10+
"Last-Translator: mymage <[email protected]>\n"
11+
"Language-Team: none\n"
12+
"Language: it\n"
13+
"MIME-Version: 1.0\n"
14+
"Content-Type: text/plain; charset=UTF-8\n"
15+
"Content-Transfer-Encoding: \n"
16+
"Plural-Forms: nplurals=2; plural=n != 1;\n"
17+
"X-Generator: Weblate 5.6.2\n"
18+
19+
#. module: website_geoengine
20+
#: model:ir.model,name:website_geoengine.model_res_partner
21+
msgid "Contact"
22+
msgstr "Contatto"
23+
24+
#. module: website_geoengine
25+
#: model:ir.model.fields,field_description:website_geoengine.field_res_partner__opening_hours
26+
#: model:ir.model.fields,field_description:website_geoengine.field_res_users__opening_hours
27+
msgid "Opening hours"
28+
msgstr "Ore apertura"
29+
30+
#. module: website_geoengine
31+
#. odoo-python
32+
#: code:addons/website_geoengine/models/res_partner.py:0
33+
#, python-format
34+
msgid "Unauthorized field"
35+
msgstr "Campo non autorizzato"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Translation of Odoo Server.
2+
# This file contains the translation of the following modules:
3+
# * website_geoengine
4+
#
5+
msgid ""
6+
msgstr ""
7+
"Project-Id-Version: Odoo Server 16.0\n"
8+
"Report-Msgid-Bugs-To: \n"
9+
"Last-Translator: \n"
10+
"Language-Team: \n"
11+
"MIME-Version: 1.0\n"
12+
"Content-Type: text/plain; charset=UTF-8\n"
13+
"Content-Transfer-Encoding: \n"
14+
"Plural-Forms: \n"
15+
16+
#. module: website_geoengine
17+
#: model:ir.model,name:website_geoengine.model_res_partner
18+
msgid "Contact"
19+
msgstr ""
20+
21+
#. module: website_geoengine
22+
#: model:ir.model.fields,field_description:website_geoengine.field_res_partner__opening_hours
23+
#: model:ir.model.fields,field_description:website_geoengine.field_res_users__opening_hours
24+
msgid "Opening hours"
25+
msgstr ""
26+
27+
#. module: website_geoengine
28+
#. odoo-python
29+
#: code:addons/website_geoengine/models/res_partner.py:0
30+
#, python-format
31+
msgid "Unauthorized field"
32+
msgstr ""
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import res_partner
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# Copyright 2011-2024 Camptocamp SA
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
3+
4+
from odoo import _, api, fields, models
5+
from odoo.exceptions import ValidationError
6+
7+
8+
class ResPartner(models.Model):
9+
_inherit = "res.partner"
10+
11+
opening_hours = fields.Char(string="Opening hours")
12+
13+
AUTHORIZED_FIELDS = ["name", "city", "zip", "street", "street2", "tag"]
14+
15+
@api.model
16+
def get_search_tags(self, search, lang):
17+
sql = """
18+
WITH
19+
names as (
20+
SELECT
21+
DISTINCT 'name' as column,
22+
name as value
23+
FROM
24+
res_partner
25+
WHERE
26+
type='store'),
27+
cities as (
28+
SELECT
29+
DISTINCT 'city' as column,
30+
city as value
31+
FROM
32+
res_partner
33+
WHERE
34+
type='store'),
35+
zips as (
36+
SELECT
37+
DISTINCT 'zip' as column,
38+
zip as value
39+
FROM
40+
res_partner
41+
WHERE
42+
type='store'),
43+
streets as (
44+
SELECT
45+
DISTINCT 'street' as column,
46+
concat(street, street2) as value
47+
FROM
48+
res_partner
49+
WHERE
50+
type='store'),
51+
tags as (
52+
SELECT
53+
DISTINCT 'tag' as column,
54+
res_partner_category.name->>%s as value
55+
FROM
56+
res_partner_category,
57+
res_partner_res_partner_category_rel,
58+
res_partner
59+
WHERE
60+
res_partner_res_partner_category_rel.partner_id = res_partner.id
61+
AND
62+
res_partner_res_partner_category_rel.category_id
63+
=
64+
res_partner_category.id
65+
AND res_partner.type='store'
66+
),
67+
all_tags as (
68+
SELECT * FROM names
69+
UNION SELECT * FROM cities
70+
UNION SELECT * FROM zips
71+
UNION SELECT * FROM streets
72+
UNION SELECT * FROM tags )
73+
74+
75+
SELECT * FROM all_tags WHERE value ILIKE %s;
76+
"""
77+
self._cr.execute(sql, (lang, f"%{search}%"))
78+
results = self._cr.fetchall()
79+
return results
80+
81+
@api.model
82+
def fetch_partner_geoengine(self, tags, lang, maxResults):
83+
domain = [("type", "=", "store")]
84+
for tag in tags:
85+
field, value = tag.values()
86+
if field not in self.AUTHORIZED_FIELDS:
87+
raise ValidationError(_("Unauthorized field"))
88+
domain.append((field.replace("tag", "category_id.name"), "ilike", value))
89+
90+
partners = self.sudo().search(domain)
91+
features = []
92+
93+
if len(partners) > int(maxResults):
94+
return {
95+
"error": "Too many results",
96+
"message": f"Too many results: {len(partners)}",
97+
}
98+
99+
for partner in partners:
100+
features.append(
101+
{
102+
"type": "Feature",
103+
"geometry": {
104+
"type": "Point",
105+
"coordinates": [
106+
partner.partner_longitude,
107+
partner.partner_latitude,
108+
],
109+
},
110+
"properties": {
111+
"id": partner.id or None,
112+
"name": partner.name or "",
113+
"zip": partner.zip or "",
114+
"city": partner.city or "",
115+
"street": partner.street or "",
116+
"street2": partner.street2 or "",
117+
"tags": partner.category_id.mapped("name") or "",
118+
"opening_hours": partner.opening_hours or "",
119+
},
120+
}
121+
)
122+
return features

website_geoengine/pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["whool"]
3+
build-backend = "whool.buildapi"

0 commit comments

Comments
 (0)