Skip to content

Commit b4dea29

Browse files
committed
[MIG] base_name_search_improved: Migration to 19.0
1 parent f7d1840 commit b4dea29

5 files changed

Lines changed: 61 additions & 50 deletions

File tree

base_name_search_improved/README.rst

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ Improved Name Search
2121
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
2222
:alt: License: AGPL-3
2323
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github
24-
:target: https://github.com/OCA/server-tools/tree/18.0/base_name_search_improved
24+
:target: https://github.com/OCA/server-tools/tree/19.0/base_name_search_improved
2525
:alt: OCA/server-tools
2626
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
27-
:target: https://translation.odoo-community.org/projects/server-tools-18-0/server-tools-18-0-base_name_search_improved
27+
:target: https://translation.odoo-community.org/projects/server-tools-19-0/server-tools-19-0-base_name_search_improved
2828
:alt: Translate me on Weblate
2929
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
30-
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-tools&target_branch=18.0
30+
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-tools&target_branch=19.0
3131
:alt: Try me on Runboat
3232

3333
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -61,9 +61,9 @@ added on searches that would normally yield results.
6161
But if not enough results are found, then additional search methods are
6262
tried. The specific methods used are:
6363

64-
- Try regular search on each of the additional fields
65-
- Try ordered word search on each of the search fields
66-
- Try unordered word search on each of the search fields
64+
- Try regular search on each of the additional fields
65+
- Try ordered word search on each of the search fields
66+
- Try unordered word search on each of the search fields
6767

6868
All results found are presented in that order, hopefully presenting them
6969
in order of relevance.
@@ -98,28 +98,28 @@ Just type into any related field, such as Customer on a Sale Order.
9898
Known issues / Roadmap
9999
======================
100100

101-
- Also use fuzzy search, such as the Levenshtein distance:
102-
https://www.postgresql.org/docs/9.5/static/fuzzystrmatch.html
103-
- The list of additional fields to search could benefit from caching,
104-
for efficiency.
105-
- This feature could also be implemented for regular ``search`` on the
106-
``name`` field.
107-
- While adding m2o or other related field that also have an improved
108-
name search, that improved name search is not used (while if
109-
name_search is customizend on a module and you add a field of that
110-
model on another model it works ok). Esto por ejemplo es en productos
111-
si agregamos campo "categoría pública" y a categoría pública le
112-
ponemos "parent_id". Entonces vamos a ver que si buscamos por una
113-
categoría padre no busca nada, en vez si hacemos esa lógica en
114-
name_search de modulo si funciona
101+
- Also use fuzzy search, such as the Levenshtein distance:
102+
`https://www.postgresql.org/docs/9.5/static/fuzzystrmatch.html <https://www.postgresql.org/docs/9.5/static/fuzzystrmatch.html>`__
103+
- The list of additional fields to search could benefit from caching,
104+
for efficiency.
105+
- This feature could also be implemented for regular ``search`` on the
106+
``name`` field.
107+
- While adding m2o or other related field that also have an improved
108+
name search, that improved name search is not used (while if
109+
name_search is customizend on a module and you add a field of that
110+
model on another model it works ok). Esto por ejemplo es en productos
111+
si agregamos campo "categoría pública" y a categoría pública le
112+
ponemos "parent_id". Entonces vamos a ver que si buscamos por una
113+
categoría padre no busca nada, en vez si hacemos esa lógica en
114+
name_search de modulo si funciona
115115

116116
Bug Tracker
117117
===========
118118

119119
Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-tools/issues>`_.
120120
In case of trouble, please check there if your issue has already been reported.
121121
If you spotted it first, help us to smash it by providing a detailed and welcomed
122-
`feedback <https://github.com/OCA/server-tools/issues/new?body=module:%20base_name_search_improved%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
122+
`feedback <https://github.com/OCA/server-tools/issues/new?body=module:%20base_name_search_improved%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
123123

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

@@ -135,16 +135,17 @@ Authors
135135
Contributors
136136
------------
137137

138-
- Daniel Reis <https://github.com/dreispt>
139-
- Kitti U. <kittiu@ecosoft.co.th> (migrate to v14)
140-
- Radovan Skolnik <radovan@skolnik.info>
138+
- Daniel Reis
139+
<`https://github.com/dreispt <https://github.com/dreispt>`__>
140+
- Kitti U. <kittiu@ecosoft.co.th> (migrate to v14)
141+
- Radovan Skolnik <radovan@skolnik.info>
141142

142143
Other credits
143144
-------------
144145

145146
The development of this module has been financially supported by:
146147

147-
- Odoo Community Association
148+
- Odoo Community Association
148149

149150
Maintainers
150151
-----------
@@ -159,6 +160,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
159160
mission is to support the collaborative development of Odoo features and
160161
promote its widespread use.
161162

162-
This module is part of the `OCA/server-tools <https://github.com/OCA/server-tools/tree/18.0/base_name_search_improved>`_ project on GitHub.
163+
This module is part of the `OCA/server-tools <https://github.com/OCA/server-tools/tree/19.0/base_name_search_improved>`_ project on GitHub.
163164

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

base_name_search_improved/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{
44
"name": "Improved Name Search",
55
"summary": "Friendlier search when typing in relation fields",
6-
"version": "18.0.1.1.0",
6+
"version": "19.0.1.0.0",
77
"category": "Uncategorized",
88
"website": "https://github.com/OCA/server-tools",
99
"author": "Daniel Reis, Odoo Community Association (OCA), ADHOC SA",

base_name_search_improved/models/ir_model.py

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88

99
from odoo import api, fields, models, tools
1010
from odoo.exceptions import ValidationError
11-
from odoo.osv import expression
11+
from odoo.fields import Domain
1212

1313
_logger = logging.getLogger(__name__)
1414
# Extended name search is only used on some operators
1515
ALLOWED_OPS = {"ilike", "like"}
1616

1717

18-
@tools.ormcache(skiparg=0)
18+
@tools.ormcache()
1919
def _get_rec_names(self):
2020
"List of fields to search into"
2121
model = self.env["ir.model"].search([("model", "=", str(self._name))])
@@ -24,7 +24,7 @@ def _get_rec_names(self):
2424
return rec_name + other_names
2525

2626

27-
@tools.ormcache(skiparg=0)
27+
@tools.ormcache()
2828
def _get_use_smart_name_search(self):
2929
return (
3030
self.env["ir.model"]
@@ -33,7 +33,7 @@ def _get_use_smart_name_search(self):
3333
)
3434

3535

36-
@tools.ormcache(skiparg=0)
36+
@tools.ormcache()
3737
def _get_add_smart_search(self):
3838
"Add Smart Search on search views"
3939
model = self.env["ir.model"].search([("model", "=", str(self._name))])
@@ -43,7 +43,7 @@ def _get_add_smart_search(self):
4343
return False
4444

4545

46-
@tools.ormcache(skiparg=0)
46+
@tools.ormcache()
4747
def _get_name_search_domain(self):
4848
"Add Smart Search on search views"
4949
name_search_domain = (
@@ -95,27 +95,27 @@ def _search_smart_search(self, operator, value):
9595
return []
9696

9797
@api.model
98-
def name_search(self, name="", args=None, operator="ilike", limit=100):
98+
def name_search(self, name="", domain=None, operator="ilike", limit=100):
9999
if not name or not (
100100
self.env.context.get("force_smart_name_search", False)
101101
or _get_use_smart_name_search(self.sudo())
102102
):
103-
return super().name_search(name, args, operator, limit)
103+
return super().name_search(name, domain, operator, limit)
104104

105105
# Support a list of fields to search on
106106
all_names = _get_rec_names(self.sudo())
107-
base_domain = args or []
107+
base_domain = domain or []
108108
limit = limit or 0
109109
results = []
110110

111111
# Try regular search on each additional search field
112112
for rec_name in all_names:
113-
domain = expression.AND([base_domain, [(rec_name, operator, name)]])
113+
domain = Domain.AND([base_domain, [(rec_name, operator, name)]])
114114
results = _extend_name_results(self, domain, results, limit)
115115

116116
# Try ordered word search on each of the search fields
117117
for rec_name in all_names:
118-
domain = expression.AND(
118+
domain = Domain.AND(
119119
[base_domain, [(rec_name, operator, name.replace(" ", "%"))]]
120120
)
121121
results = _extend_name_results(self, domain, results, limit)
@@ -126,16 +126,16 @@ def name_search(self, name="", args=None, operator="ilike", limit=100):
126126
if " " in name:
127127
unordered_domain = []
128128
for word in name.split():
129-
word_domain = expression.OR(
129+
word_domain = Domain.OR(
130130
[[(rec_name, operator, word)] for rec_name in all_names]
131131
)
132132
unordered_domain = (
133-
expression.AND([unordered_domain, word_domain])
133+
Domain.AND([unordered_domain, word_domain])
134134
if unordered_domain
135135
else word_domain
136136
)
137137
results = _extend_name_results(
138-
self, expression.AND([base_domain, unordered_domain]), results, limit
138+
self, Domain.AND([base_domain, unordered_domain]), results, limit
139139
)
140140

141141
results = results[:limit]
@@ -211,7 +211,7 @@ def check_name_search_domain(self):
211211
RecursionError,
212212
) as e:
213213
raise ValidationError(
214-
self.env._("Couldn't eval Name Search Domain (%s)") % e
214+
self.env._("Couldn't eval Name Search Domain (%s)", e)
215215
) from e
216216
if not isinstance(name_search_domain, list):
217217
raise ValidationError(
@@ -226,17 +226,26 @@ def write(self, vals):
226226
def _register_hook(self):
227227
def make_smart_name_search(original_name_search):
228228
def wrapper(
229-
self, name="", args=None, operator="ilike", limit=100, **kwargs
229+
self, name="", domain=None, operator="ilike", limit=100, **kwargs
230230
):
231231
original_results = original_name_search(
232-
self, name, args, operator, limit, **kwargs
232+
self,
233+
name=name,
234+
domain=domain,
235+
operator=operator,
236+
limit=limit,
237+
**kwargs,
233238
)
234239
if not name or (limit and len(original_results) >= limit):
235240
return original_results
236241
seen_ids = {res[0] for res in original_results}
237242
remaining_limit = limit - len(original_results) if limit else None
238243
smart_results = Base.name_search(
239-
self, name=name, args=args, operator=operator, limit=remaining_limit
244+
self,
245+
name=name,
246+
domain=domain,
247+
operator=operator,
248+
limit=remaining_limit,
240249
)
241250
additional_results = [
242251
(res_id, res_name)

base_name_search_improved/static/description/index.html

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ <h1>Improved Name Search</h1>
374374
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
375375
!! source digest: sha256:506ec7a25a0bb1d86a79c06d4577aca5a3cda5d81ed921490e95a53a5e49df24
376376
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
377-
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/server-tools/tree/18.0/base_name_search_improved"><img alt="OCA/server-tools" src="https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/server-tools-18-0/server-tools-18-0-base_name_search_improved"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/server-tools&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
377+
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/server-tools/tree/19.0/base_name_search_improved"><img alt="OCA/server-tools" src="https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/server-tools-19-0/server-tools-19-0-base_name_search_improved"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/server-tools&amp;target_branch=19.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
378378
<p>Extends the name search feature to use additional, more relaxed matching
379379
methods, and to allow searching into configurable additional record
380380
fields.</p>
@@ -455,7 +455,7 @@ <h2><a class="toc-backref" href="#toc-entry-4">Bug Tracker</a></h2>
455455
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/server-tools/issues">GitHub Issues</a>.
456456
In case of trouble, please check there if your issue has already been reported.
457457
If you spotted it first, help us to smash it by providing a detailed and welcomed
458-
<a class="reference external" href="https://github.com/OCA/server-tools/issues/new?body=module:%20base_name_search_improved%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
458+
<a class="reference external" href="https://github.com/OCA/server-tools/issues/new?body=module:%20base_name_search_improved%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
459459
<p>Do not contact contributors directly about support or help with technical issues.</p>
460460
</div>
461461
<div class="section" id="credits">
@@ -470,7 +470,8 @@ <h3><a class="toc-backref" href="#toc-entry-6">Authors</a></h3>
470470
<div class="section" id="contributors">
471471
<h3><a class="toc-backref" href="#toc-entry-7">Contributors</a></h3>
472472
<ul class="simple">
473-
<li>Daniel Reis &lt;<a class="reference external" href="https://github.com/dreispt">https://github.com/dreispt</a>&gt;</li>
473+
<li>Daniel Reis
474+
&lt;<a class="reference external" href="https://github.com/dreispt">https://github.com/dreispt</a>&gt;</li>
474475
<li>Kitti U. &lt;<a class="reference external" href="mailto:kittiu&#64;ecosoft.co.th">kittiu&#64;ecosoft.co.th</a>&gt; (migrate to v14)</li>
475476
<li>Radovan Skolnik &lt;<a class="reference external" href="mailto:radovan&#64;skolnik.info">radovan&#64;skolnik.info</a>&gt;</li>
476477
</ul>
@@ -491,7 +492,7 @@ <h3><a class="toc-backref" href="#toc-entry-9">Maintainers</a></h3>
491492
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
492493
mission is to support the collaborative development of Odoo features and
493494
promote its widespread use.</p>
494-
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/server-tools/tree/18.0/base_name_search_improved">OCA/server-tools</a> project on GitHub.</p>
495+
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/server-tools/tree/19.0/base_name_search_improved">OCA/server-tools</a> project on GitHub.</p>
495496
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
496497
</div>
497498
</div>

base_name_search_improved/tests/test_name_search.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def test_NameSearchDomain(self):
7171

7272
def test_MustHonorDomain(self):
7373
"""Must also honor a provided Domain"""
74-
res = self.Partner.name_search("+351", args=[("vat", "=", "3333")])
74+
res = self.Partner.name_search("+351", domain=[("vat", "=", "3333")])
7575
gambulputty = self.partner3.id
7676
self.assertEqual(len(res), 1)
7777
self.assertEqual(res[0][0], gambulputty)
@@ -105,7 +105,7 @@ def test_SmartSearchWarning(self):
105105
"ttype": "char",
106106
"model_id": self.model_partner.id,
107107
"model": self.model_partner.model,
108-
"translate": True,
108+
"translate": "standard",
109109
}
110110
)
111111
self.model_partner.name_search_ids = [(4, translatable_field.id)]

0 commit comments

Comments
 (0)