Skip to content

Commit 17991ca

Browse files
authored
Merge pull request OCA#767 from OCA/12.0
Syncing from upstream OCA/server-tools (12.0)
2 parents e83e340 + ec75afd commit 17991ca

78 files changed

Lines changed: 105 additions & 891 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

base_search_fuzzy/README.rst

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,6 @@ Usage
7070

7171
``self.env.cr.execute("SELECT set_limit(0.2);")``
7272

73-
#. Another interesting feature is the use of ``similarity(column, 'text')``
74-
function in the ``order`` parameter to order by similarity. This module just
75-
contains a basic implementation which doesn't perform validations and has to
76-
start with this function. For example you can define the function as
77-
followed:
78-
79-
``similarity(%s.name, 'John Mil') DESC" % self.env['res.partner']._table``
80-
8173
For further questions read the Documentation of the
8274
`pg_trgm <https://www.postgresql.org/docs/current/static/pgtrgm.html>`_ module.
8375

base_search_fuzzy/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
# Copyright 2016 Serpent Consulting Services Pvt. Ltd.
33
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
44
from . import models
5+
from .hooks import post_load

base_search_fuzzy/__manifest__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
'name': "Fuzzy Search",
66
'summary': "Fuzzy search with the PostgreSQL trigram extension",
77
'category': 'Uncategorized',
8-
'version': '12.0.1.0.0',
8+
'version': '12.0.1.0.1',
99
'website': 'https://github.com/OCA/server-tools',
1010
'author': 'bloopark systems GmbH & Co. KG, '
1111
'Eficent, '
@@ -18,4 +18,5 @@
1818
'security/ir.model.access.csv',
1919
],
2020
'installable': True,
21+
"post_load": "post_load",
2122
}

base_search_fuzzy/hooks.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Copyright 2016 Eficent Business and IT Consulting Services S.L.
2+
# Copyright 2016 Serpent Consulting Services Pvt. Ltd.
3+
# Copyright 2017 LasLabs Inc.
4+
# Copyright 2021 Tecnativa - Jairo Llopis
5+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
6+
7+
from odoo.osv import expression
8+
from functools import wraps
9+
10+
11+
def patch_leaf_trgm(original):
12+
@wraps(original)
13+
def _wrapper(self, eleaf):
14+
leaf = eleaf.leaf
15+
left, operator, right = leaf
16+
model = eleaf.model
17+
# No overload for other operators...
18+
if operator != "%":
19+
# Except translation "inselect" queries
20+
if operator == 'inselect':
21+
right = (right[0].replace(' % ', ' %% '), right[1])
22+
eleaf.leaf = (left, operator, right)
23+
return original(self, eleaf)
24+
# The field must exist
25+
if left not in model._fields:
26+
raise ValueError("Invalid field %r in domain term %r" % (left, leaf))
27+
# Generate correct WHERE clause part
28+
table_alias = eleaf.generate_alias()
29+
query = '("{}"."{}" %% {})'.format(
30+
table_alias,
31+
left,
32+
model._fields[left].column_format,
33+
)
34+
params = [right]
35+
return query, params
36+
37+
return _wrapper
38+
39+
40+
def post_load():
41+
"""Patch expression generators to enable the fuzzy search operator."""
42+
expression.TERM_OPERATORS += ("%",)
43+
expression.expression._expression__leaf_to_sql = patch_leaf_trgm(
44+
expression.expression._expression__leaf_to_sql
45+
)

base_search_fuzzy/i18n/am.po

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,6 @@ msgstr ""
7171
msgid "Index Type"
7272
msgstr ""
7373

74-
#. module: base_search_fuzzy
75-
#: code:addons/base_search_fuzzy/models/ir_model.py:39
76-
#, python-format
77-
msgid "Invalid field %r in domain term %r"
78-
msgstr ""
79-
8074
#. module: base_search_fuzzy
8175
#: model:ir.model.fields,field_description:base_search_fuzzy.field_trgm_index____last_update
8276
msgid "Last Modified on"
@@ -92,11 +86,6 @@ msgstr "Última actualización por"
9286
msgid "Last Updated on"
9387
msgstr "Última actualización en"
9488

95-
#. module: base_search_fuzzy
96-
#: model:ir.model,name:base_search_fuzzy.model_ir_model
97-
msgid "Models"
98-
msgstr ""
99-
10089
#. module: base_search_fuzzy
10190
#: model:ir.model.fields,help:base_search_fuzzy.field_trgm_index__index_name
10291
msgid ""

base_search_fuzzy/i18n/ar.po

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,6 @@ msgstr ""
7373
msgid "Index Type"
7474
msgstr ""
7575

76-
#. module: base_search_fuzzy
77-
#: code:addons/base_search_fuzzy/models/ir_model.py:39
78-
#, python-format
79-
msgid "Invalid field %r in domain term %r"
80-
msgstr ""
81-
8276
#. module: base_search_fuzzy
8377
#: model:ir.model.fields,field_description:base_search_fuzzy.field_trgm_index____last_update
8478
msgid "Last Modified on"
@@ -94,11 +88,6 @@ msgstr "آخر تحديث بواسطة"
9488
msgid "Last Updated on"
9589
msgstr "آخر تحديث في"
9690

97-
#. module: base_search_fuzzy
98-
#: model:ir.model,name:base_search_fuzzy.model_ir_model
99-
msgid "Models"
100-
msgstr ""
101-
10291
#. module: base_search_fuzzy
10392
#: model:ir.model.fields,help:base_search_fuzzy.field_trgm_index__index_name
10493
msgid ""

base_search_fuzzy/i18n/base_search_fuzzy.pot

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,6 @@ msgstr ""
6363
msgid "Index Type"
6464
msgstr ""
6565

66-
#. module: base_search_fuzzy
67-
#: code:addons/base_search_fuzzy/models/ir_model.py:39
68-
#, python-format
69-
msgid "Invalid field %r in domain term %r"
70-
msgstr ""
71-
7266
#. module: base_search_fuzzy
7367
#: model:ir.model.fields,field_description:base_search_fuzzy.field_trgm_index____last_update
7468
msgid "Last Modified on"
@@ -84,11 +78,6 @@ msgstr ""
8478
msgid "Last Updated on"
8579
msgstr ""
8680

87-
#. module: base_search_fuzzy
88-
#: model:ir.model,name:base_search_fuzzy.model_ir_model
89-
msgid "Models"
90-
msgstr ""
91-
9281
#. module: base_search_fuzzy
9382
#: model:ir.model.fields,help:base_search_fuzzy.field_trgm_index__index_name
9483
msgid "The index name is automatically generated like fieldname_indextype_idx. If the index already exists and the index is located in the same table then this index is reused. If the index is located in another table then a number is added at the end of the index name."

base_search_fuzzy/i18n/bg.po

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,6 @@ msgstr ""
7171
msgid "Index Type"
7272
msgstr ""
7373

74-
#. module: base_search_fuzzy
75-
#: code:addons/base_search_fuzzy/models/ir_model.py:39
76-
#, python-format
77-
msgid "Invalid field %r in domain term %r"
78-
msgstr ""
79-
8074
#. module: base_search_fuzzy
8175
#: model:ir.model.fields,field_description:base_search_fuzzy.field_trgm_index____last_update
8276
msgid "Last Modified on"
@@ -92,11 +86,6 @@ msgstr "Последно обновено от"
9286
msgid "Last Updated on"
9387
msgstr "Последно обновено на"
9488

95-
#. module: base_search_fuzzy
96-
#: model:ir.model,name:base_search_fuzzy.model_ir_model
97-
msgid "Models"
98-
msgstr ""
99-
10089
#. module: base_search_fuzzy
10190
#: model:ir.model.fields,help:base_search_fuzzy.field_trgm_index__index_name
10291
msgid ""

base_search_fuzzy/i18n/bs.po

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,6 @@ msgstr ""
7272
msgid "Index Type"
7373
msgstr ""
7474

75-
#. module: base_search_fuzzy
76-
#: code:addons/base_search_fuzzy/models/ir_model.py:39
77-
#, python-format
78-
msgid "Invalid field %r in domain term %r"
79-
msgstr ""
80-
8175
#. module: base_search_fuzzy
8276
#: model:ir.model.fields,field_description:base_search_fuzzy.field_trgm_index____last_update
8377
msgid "Last Modified on"
@@ -93,11 +87,6 @@ msgstr "Zadnji ažurirao"
9387
msgid "Last Updated on"
9488
msgstr "Zadnje ažurirano"
9589

96-
#. module: base_search_fuzzy
97-
#: model:ir.model,name:base_search_fuzzy.model_ir_model
98-
msgid "Models"
99-
msgstr ""
100-
10190
#. module: base_search_fuzzy
10291
#: model:ir.model.fields,help:base_search_fuzzy.field_trgm_index__index_name
10392
msgid ""

base_search_fuzzy/i18n/ca.po

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,6 @@ msgstr ""
7272
msgid "Index Type"
7373
msgstr ""
7474

75-
#. module: base_search_fuzzy
76-
#: code:addons/base_search_fuzzy/models/ir_model.py:39
77-
#, python-format
78-
msgid "Invalid field %r in domain term %r"
79-
msgstr ""
80-
8175
#. module: base_search_fuzzy
8276
#: model:ir.model.fields,field_description:base_search_fuzzy.field_trgm_index____last_update
8377
msgid "Last Modified on"
@@ -93,11 +87,6 @@ msgstr "Darrera Actualització per"
9387
msgid "Last Updated on"
9488
msgstr "Darrera Actualització el"
9589

96-
#. module: base_search_fuzzy
97-
#: model:ir.model,name:base_search_fuzzy.model_ir_model
98-
msgid "Models"
99-
msgstr ""
100-
10190
#. module: base_search_fuzzy
10291
#: model:ir.model.fields,help:base_search_fuzzy.field_trgm_index__index_name
10392
msgid ""

0 commit comments

Comments
 (0)