From 1d56a040a0a30bcf6d8e1b378a063672f30d1182 Mon Sep 17 00:00:00 2001
From: Bonnerue
Date: Tue, 12 Nov 2024 09:46:22 +0100
Subject: [PATCH] [FIX] Fix to enable or not the multi-search and add all
separator
---
base_multi_search_separator/README.rst | 14 +++++++++-----
.../data/multi_search_data.xml | 2 +-
base_multi_search_separator/monkeypatching.py | 12 ++++++------
base_multi_search_separator/readme/DESCRIPTION.rst | 4 ++--
base_multi_search_separator/readme/USAGE.rst | 8 ++++++--
.../static/description/index.html | 13 ++++++++-----
.../tests/test_multi_search.py | 11 ++++++++---
7 files changed, 40 insertions(+), 24 deletions(-)
diff --git a/base_multi_search_separator/README.rst b/base_multi_search_separator/README.rst
index b0dd44ae9c..83e0a9caca 100644
--- a/base_multi_search_separator/README.rst
+++ b/base_multi_search_separator/README.rst
@@ -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
@@ -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**
@@ -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
diff --git a/base_multi_search_separator/data/multi_search_data.xml b/base_multi_search_separator/data/multi_search_data.xml
index 96dd884f8e..324e955f11 100644
--- a/base_multi_search_separator/data/multi_search_data.xml
+++ b/base_multi_search_separator/data/multi_search_data.xml
@@ -1,6 +1,6 @@
multi_search_separator_base
- |;
+ |; ,
diff --git a/base_multi_search_separator/monkeypatching.py b/base_multi_search_separator/monkeypatching.py
index 05c88578e7..cc15696164 100644
--- a/base_multi_search_separator/monkeypatching.py
+++ b/base_multi_search_separator/monkeypatching.py
@@ -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"
)
@@ -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)
diff --git a/base_multi_search_separator/readme/DESCRIPTION.rst b/base_multi_search_separator/readme/DESCRIPTION.rst
index a7f729790f..e30d8002ef 100644
--- a/base_multi_search_separator/readme/DESCRIPTION.rst
+++ b/base_multi_search_separator/readme/DESCRIPTION.rst
@@ -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")]
diff --git a/base_multi_search_separator/readme/USAGE.rst b/base_multi_search_separator/readme/USAGE.rst
index 87dcf5b9b9..dbf4672cf3 100644
--- a/base_multi_search_separator/readme/USAGE.rst
+++ b/base_multi_search_separator/readme/USAGE.rst
@@ -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
diff --git a/base_multi_search_separator/static/description/index.html b/base_multi_search_separator/static/description/index.html
index 301fe617ae..0eac7e5f45 100644
--- a/base_multi_search_separator/static/description/index.html
+++ b/base_multi_search_separator/static/description/index.html
@@ -367,15 +367,15 @@ 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
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
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
+
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.
- After:
-Searching “kelly|perry;hart” in employee, will give “Kelly”, “Perry”
+Searching “/kelly|perry;hart” in employee, will give “Kelly”, “Perry”
and “Hart”
diff --git a/base_multi_search_separator/tests/test_multi_search.py b/base_multi_search_separator/tests/test_multi_search.py
index 9d79664127..581a618f0d 100644
--- a/base_multi_search_separator/tests/test_multi_search.py
+++ b/base_multi_search_separator/tests/test_multi_search.py
@@ -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"],
+ )