Skip to content

Commit

Permalink
[FIX] Fix to enable or not the multi-search and add all separator
Browse files Browse the repository at this point in the history
  • Loading branch information
TB-Ph35 committed Nov 12, 2024
1 parent 22a3fe9 commit 1d56a04
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 24 deletions.
14 changes: 9 additions & 5 deletions base_multi_search_separator/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Field MultiSearch with separotor
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:09e3300ded4e724ec2f6472131d8e20faaa4f5706cf24b7fcc2ba53b188598e4
!! source digest: sha256:4e881a9a949e292e686e878b42bcb228e59c8ba22eca33e3cf454f32c9b95e96
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand All @@ -31,10 +31,10 @@ Field MultiSearch with separotor
This module allows mulit_searching for all search.
For that, it add code before the search function.

It will allows you to search for multi_value separate by the a character that you
It will allows you to search for multi_value separate by the character that you
have configure.
* It will split the value like this:
[("name", "ilike","Hart|perry;kelly")] => ['|', '|', '|', '|', '|' ("name", "ilike","Hart|perry;kelly"), ("name", "ilike","Hart|perry"), ("name", "ilike","Hart"), ("name", "ilike","perry;kelly"), ("name", "ilike","kelly"), ("name", "ilike","kelly")]
[("name", "ilike","/Hart|perry;kelly")] => ['|', '|', '|', '|', '|' ("name", "ilike","Hart|perry;kelly"), ("name", "ilike","Hart|perry"), ("name", "ilike","Hart"), ("name", "ilike","perry;kelly"), ("name", "ilike","kelly"), ("name", "ilike","kelly"), ("name", "ilike", "/Hart|perry;kelly")]
**Table of contents**

Expand All @@ -54,13 +54,17 @@ To configure the separator you must:
Usage
=====

To use mulit_search you must put an "/" before the value you want to search.
like this "/Kelly perry hart"
Do not put a separator between the first value and "/".

* Before:
searching "kelly|perry;hart" in employee, will give a none result.
searching "/kelly|perry;hart" in employee, will give a none result.

.. image:: https://raw.githubusercontent.com/OCA/server-ux/16.0/base_multi_search_separator/static/description/img/Before_multi_search.png

* After:
Searching "kelly|perry;hart" in employee, will give "Kelly", "Perry"
Searching "/kelly|perry;hart" in employee, will give "Kelly", "Perry"
and "Hart"

.. image:: https://raw.githubusercontent.com/OCA/server-ux/16.0/base_multi_search_separator/static/description/img/After_multi_search.png
Expand Down
2 changes: 1 addition & 1 deletion base_multi_search_separator/data/multi_search_data.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<odoo>
<record id="multi_search_separator" model="ir.config_parameter">
<field name="key">multi_search_separator_base</field>
<field name="value">|;</field>
<field name="value">|; ,</field>
</record>
</odoo>
12 changes: 6 additions & 6 deletions base_multi_search_separator/monkeypatching.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
def search(self, domain, offset=0, limit=None, order=None, count=False):
"""Override of the Python method to remove the dependency of the unit
fields"""
if (
self.env["ir.model.access"].check_access_rights("read", raise_exception=False)
and self != self.env["res.lang"]
):
if self.env["ir.model.access"].check_access_rights("read", raise_exception=False):
list_separator = self.env["ir.config_parameter"].get_param(
"multi_search_separator_base"
)
Expand All @@ -33,13 +30,16 @@ def search(self, domain, offset=0, limit=None, order=None, count=False):
if (
len(dom) == 3
and isinstance(dom[2], str)
and dom[2].startswith("/")
and any(separator in dom[2] for separator in list_separator)
):
value_list = re.split("{}".format(nlist_sep), dom[2])
text_search = dom[2].replace("/", "", 1)
value_list = re.split("{}".format(nlist_sep), text_search)
value_list.append(text_search)
value_list.append(dom[2])
value_list_set = set(value_list)
for separator in list_separator:
value_list_set = value_list_set.union(dom[2].split(separator))
value_list_set = value_list_set.union(text_search.split(separator))
for value in value_list_set:
domain_search_field = [(dom[0], dom[1], value)]
domain_value.append(domain_search_field)
Expand Down
4 changes: 2 additions & 2 deletions base_multi_search_separator/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
This module allows mulit_searching for all search.
For that, it add code before the search function.

It will allows you to search for multi_value separate by the a character that you
It will allows you to search for multi_value separate by the character that you
have configure.
* It will split the value like this:
[("name", "ilike","Hart|perry;kelly")] => ['|', '|', '|', '|', '|' ("name", "ilike","Hart|perry;kelly"), ("name", "ilike","Hart|perry"), ("name", "ilike","Hart"), ("name", "ilike","perry;kelly"), ("name", "ilike","kelly"), ("name", "ilike","kelly")]
[("name", "ilike","/Hart|perry;kelly")] => ['|', '|', '|', '|', '|' ("name", "ilike","Hart|perry;kelly"), ("name", "ilike","Hart|perry"), ("name", "ilike","Hart"), ("name", "ilike","perry;kelly"), ("name", "ilike","kelly"), ("name", "ilike","kelly"), ("name", "ilike", "/Hart|perry;kelly")]
8 changes: 6 additions & 2 deletions base_multi_search_separator/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
To use mulit_search you must put an "/" before the value you want to search.
like this "/Kelly perry hart"
Do not put a separator between the first value and "/".

* Before:
searching "kelly|perry;hart" in employee, will give a none result.
searching "/kelly|perry;hart" in employee, will give a none result.

.. image:: ../static/description/img/Before_multi_search.png

* After:
Searching "kelly|perry;hart" in employee, will give "Kelly", "Perry"
Searching "/kelly|perry;hart" in employee, will give "Kelly", "Perry"
and "Hart"

.. image:: ../static/description/img/After_multi_search.png
13 changes: 8 additions & 5 deletions base_multi_search_separator/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,15 +367,15 @@ <h1 class="title">Field MultiSearch with separotor</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:09e3300ded4e724ec2f6472131d8e20faaa4f5706cf24b7fcc2ba53b188598e4
!! source digest: sha256:4e881a9a949e292e686e878b42bcb228e59c8ba22eca33e3cf454f32c9b95e96
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/server-ux/tree/16.0/base_multi_search_separator"><img alt="OCA/server-ux" src="https://img.shields.io/badge/github-OCA%2Fserver--ux-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/server-ux-16-0/server-ux-16-0-base_multi_search_separator"><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-ux&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module allows mulit_searching for all search.
For that, it add code before the search function.</p>
<p>It will allows you to search for multi_value separate by the a character that you
<p>It will allows you to search for multi_value separate by the character that you
have configure.
* It will split the value like this:
[(“name”, “ilike”,”Hart|perry;kelly”)] =&gt; [‘|’, ‘|’, ‘|’, ‘|’, ‘|’ (“name”, “ilike”,”Hart|perry;kelly”), (“name”, “ilike”,”Hart|perry”), (“name”, “ilike”,”Hart”), (“name”, “ilike”,”perry;kelly”), (“name”, “ilike”,”kelly”), (“name”, “ilike”,”kelly”)]</p>
[(“name”, “ilike”,”/Hart|perry;kelly”)] =&gt; [‘|’, ‘|’, ‘|’, ‘|’, ‘|’ (“name”, “ilike”,”Hart|perry;kelly”), (“name”, “ilike”,”Hart|perry”), (“name”, “ilike”,”Hart”), (“name”, “ilike”,”perry;kelly”), (“name”, “ilike”,”kelly”), (“name”, “ilike”,”kelly”), (“name”, “ilike”, “/Hart|perry;kelly”)]</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
Expand Down Expand Up @@ -406,14 +406,17 @@ <h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
</div>
<div class="section" id="usage">
<h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
<p>To use mulit_search you must put an “/” before the value you want to search.
like this “/Kelly perry hart”
Do not put a separator between the first value and “/”.</p>
<ul class="simple">
<li>Before:
searching “kelly|perry;hart” in employee, will give a none result.</li>
searching “/kelly|perry;hart” in employee, will give a none result.</li>
</ul>
<img alt="https://raw.githubusercontent.com/OCA/server-ux/16.0/base_multi_search_separator/static/description/img/Before_multi_search.png" src="https://raw.githubusercontent.com/OCA/server-ux/16.0/base_multi_search_separator/static/description/img/Before_multi_search.png" />
<ul class="simple">
<li>After:
Searching “kelly|perry;hart” in employee, will give “Kelly”, “Perry”
Searching “/kelly|perry;hart” in employee, will give “Kelly”, “Perry”
and “Hart”</li>
</ul>
<img alt="https://raw.githubusercontent.com/OCA/server-ux/16.0/base_multi_search_separator/static/description/img/After_multi_search.png" src="https://raw.githubusercontent.com/OCA/server-ux/16.0/base_multi_search_separator/static/description/img/After_multi_search.png" />
Expand Down
11 changes: 8 additions & 3 deletions base_multi_search_separator/tests/test_multi_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,26 @@ def setUp(self):

def test_multi_search(self):
search_1 = self.env["res.partner"].search(
[("name", "like", "partner_one|partner_two")]
[("name", "like", "/partner_one|partner_two")]
)
self.assertEqual(
search_1,
self.env["res.partner"].browse((self.partner_1.id, self.partner_2.id)),
)
search_2 = self.env["res.partner"].search([("name", "ilike", "one;two|four")])
search_2 = self.env["res.partner"].search([("name", "ilike", "/one;two|four")])
self.assertEqual(
search_2,
self.env["res.partner"].browse((self.partner_1.id, self.partner_2.id)),
)
search_3 = self.env["res.partner"].search([("name", "ilike", "one;two|three")])
search_3 = self.env["res.partner"].search([("name", "ilike", "/one;two|three")])
self.assertEqual(
search_3,
self.env["res.partner"].browse(
(self.partner_1.id, self.partner_2.id, self.partner_3.id)
),
)
search_4 = self.env["res.partner"].search([("name", "ilike", "one;two|three")])
self.assertEqual(
search_4,
self.env["res.partner"],
)

0 comments on commit 1d56a04

Please sign in to comment.