Skip to content

Commit

Permalink
Apply changes to fit pre-commit requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
Hadrien Huvelle committed Oct 30, 2024
1 parent d14399c commit 6ecf4d2
Show file tree
Hide file tree
Showing 19 changed files with 1,092 additions and 765 deletions.
78 changes: 78 additions & 0 deletions website_geoengine/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
==================
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

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.
1 change: 0 additions & 1 deletion website_geoengine/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
{
"name": "Geospatial Website",
"version": "16.0.1.0.0",
"description": "Create a method to search records getting only the ones that are 'is_published'",
"category": "GeoBI",
"author": "Camptocamp, Odoo Community Association (OCA)",
"license": "AGPL-3",
Expand Down
69 changes: 46 additions & 23 deletions website_geoengine/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import logging

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

_logger = logging.getLogger(__name__)


class ResPartner(models.Model):
_inherit = "res.partner"
Expand All @@ -15,19 +11,44 @@ class ResPartner(models.Model):

@api.model
def get_search_tags(self, search, lang):
_logger.info(f"get_search_tags: {search}")
_logger.info(f"get_search_tags: {lang}")
# TODO FILTER res_partner on is_store = True AND is_published = True AND website_published = True. And filter category_ids on partners as well
sql = f"""
sql = """

Check warning on line 14 in website_geoengine/models/res_partner.py

View check run for this annotation

Codecov / codecov/patch

website_geoengine/models/res_partner.py#L14

Added line #L14 was not covered by tests
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'),
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->>'{lang}' as value
SELECT
DISTINCT 'tag' as column,
res_partner_category.name->>%s as value
FROM
res_partner_category,
res_partner_res_partner_category_rel,
Expand All @@ -38,23 +59,25 @@ def get_search_tags(self, search, lang):
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 )
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 '%{search}%';
SELECT * FROM all_tags WHERE value ILIKE %s;
"""
self._cr.execute(sql)
return self._cr.fetchall()
self._cr.execute(sql, (lang, f"%{search}%"))
results = self._cr.fetchall()
return results

Check warning on line 74 in website_geoengine/models/res_partner.py

View check run for this annotation

Codecov / codecov/patch

website_geoengine/models/res_partner.py#L72-L74

Added lines #L72 - L74 were not covered by tests

@api.model
def fetch_partner_geoengine(self, tags, lang, maxResults):
_logger.info(f"fetch_partner_geoengine: {tags}")
_logger.info(f"fetch_partner_geoengine: {lang}")

domain = [("type", "=", "store")]

Check warning on line 78 in website_geoengine/models/res_partner.py

View check run for this annotation

Codecov / codecov/patch

website_geoengine/models/res_partner.py#L78

Added line #L78 was not covered by tests
for tag in tags:
field, value = tag.values()

Check warning on line 80 in website_geoengine/models/res_partner.py

View check run for this annotation

Codecov / codecov/patch

website_geoengine/models/res_partner.py#L80

Added line #L80 was not covered by tests
_logger.info(f"fetch_partner_geoengine: {field}: {value}")
if field not in self.AUTHORIZED_FIELDS:
raise ValidationError(_("Unauthorized field"))
domain.append((field.replace("tag", "category_id.name"), "ilike", value))

Check warning on line 83 in website_geoengine/models/res_partner.py

View check run for this annotation

Codecov / codecov/patch

website_geoengine/models/res_partner.py#L82-L83

Added lines #L82 - L83 were not covered by tests
Expand Down
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/CONTIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Stéphane Brunner <[email protected]>
* Hadrien Huvelle <[email protected]>
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 6ecf4d2

Please sign in to comment.