diff --git a/website_geoengine/README.rst b/website_geoengine/README.rst new file mode 100644 index 000000000..a4395857d --- /dev/null +++ b/website_geoengine/README.rst @@ -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 `_. +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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Camptocamp + +Contributors +------------ + +- Stéphane Brunner +- Hadrien Huvelle +- Cédric Paradis + +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 `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/website_geoengine/__init__.py b/website_geoengine/__init__.py new file mode 100644 index 000000000..91c5580fe --- /dev/null +++ b/website_geoengine/__init__.py @@ -0,0 +1,2 @@ +from . import controllers +from . import models diff --git a/website_geoengine/__manifest__.py b/website_geoengine/__manifest__.py new file mode 100644 index 000000000..add8bb355 --- /dev/null +++ b/website_geoengine/__manifest__.py @@ -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, +} diff --git a/website_geoengine/controllers/__init__.py b/website_geoengine/controllers/__init__.py new file mode 100644 index 000000000..91fed54d4 --- /dev/null +++ b/website_geoengine/controllers/__init__.py @@ -0,0 +1 @@ +from . import res_partner diff --git a/website_geoengine/controllers/res_partner.py b/website_geoengine/controllers/res_partner.py new file mode 100644 index 000000000..a6ab76849 --- /dev/null +++ b/website_geoengine/controllers/res_partner.py @@ -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 + ) diff --git a/website_geoengine/i18n/it.po b/website_geoengine/i18n/it.po new file mode 100644 index 000000000..c589ffa42 --- /dev/null +++ b/website_geoengine/i18n/it.po @@ -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 \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" diff --git a/website_geoengine/i18n/website_geoengine.pot b/website_geoengine/i18n/website_geoengine.pot new file mode 100644 index 000000000..a016651fa --- /dev/null +++ b/website_geoengine/i18n/website_geoengine.pot @@ -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 "" diff --git a/website_geoengine/models/__init__.py b/website_geoengine/models/__init__.py new file mode 100644 index 000000000..91fed54d4 --- /dev/null +++ b/website_geoengine/models/__init__.py @@ -0,0 +1 @@ +from . import res_partner diff --git a/website_geoengine/models/res_partner.py b/website_geoengine/models/res_partner.py new file mode 100644 index 000000000..6f9d96835 --- /dev/null +++ b/website_geoengine/models/res_partner.py @@ -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 diff --git a/website_geoengine/pyproject.toml b/website_geoengine/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/website_geoengine/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/website_geoengine/readme/CONFIGURE.md b/website_geoengine/readme/CONFIGURE.md new file mode 100644 index 000000000..66c20ecb3 --- /dev/null +++ b/website_geoengine/readme/CONFIGURE.md @@ -0,0 +1,2 @@ +No configuration needed. Just install the module and you are ready to +go. diff --git a/website_geoengine/readme/CONTRIBUTORS.md b/website_geoengine/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..b5e60e851 --- /dev/null +++ b/website_geoengine/readme/CONTRIBUTORS.md @@ -0,0 +1,3 @@ +- Stéphane Brunner \ +- Hadrien Huvelle \ +- Cédric Paradis \ diff --git a/website_geoengine/readme/DESCRIPTION.md b/website_geoengine/readme/DESCRIPTION.md new file mode 100644 index 000000000..f8c6923c4 --- /dev/null +++ b/website_geoengine/readme/DESCRIPTION.md @@ -0,0 +1,2 @@ +This module extends the `website` odoo module, to allow add endpoints in +order to exchange geospatial data with the frontend. diff --git a/website_geoengine/readme/USAGE.md b/website_geoengine/readme/USAGE.md new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/website_geoengine/readme/USAGE.md @@ -0,0 +1 @@ + diff --git a/website_geoengine/static/description/icon.png b/website_geoengine/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/website_geoengine/static/description/icon.png differ diff --git a/website_geoengine/static/description/index.html b/website_geoengine/static/description/index.html new file mode 100644 index 000000000..a89be04d3 --- /dev/null +++ b/website_geoengine/static/description/index.html @@ -0,0 +1,436 @@ + + + + + +Geospatial Website + + + +
+

Geospatial Website

+ + +

Beta License: AGPL-3 OCA/geospatial Translate me on Weblate Try me on Runboat

+

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

+

Table of contents

+ +
+

Configuration

+

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

+
+
+

Usage

+
+
+

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Camptocamp
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

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 project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ +