From 3b5f41c0dee5581da90121d104c1c449c95b9e57 Mon Sep 17 00:00:00 2001 From: Nikul-OSI Date: Fri, 20 Jan 2023 12:17:41 +0530 Subject: [PATCH] [MIG] base_search_fuzzy: Migrated to v16 --- base_search_fuzzy/__manifest__.py | 2 +- base_search_fuzzy/demo/TrgmIndex_demo.xml | 1 - base_search_fuzzy/demo/res_partner_demo.xml | 4 +++- base_search_fuzzy/hooks.py | 4 ++-- base_search_fuzzy/models/query.py | 2 +- base_search_fuzzy/models/trgm_index.py | 11 ++++++----- base_search_fuzzy/readme/CONTRIBUTORS.rst | 3 +++ base_search_fuzzy/tests/test_query_generation.py | 10 +++++----- setup/base_search_fuzzy/odoo/addons/base_search_fuzzy | 1 + setup/base_search_fuzzy/setup.py | 6 ++++++ 10 files changed, 28 insertions(+), 16 deletions(-) create mode 120000 setup/base_search_fuzzy/odoo/addons/base_search_fuzzy create mode 100644 setup/base_search_fuzzy/setup.py diff --git a/base_search_fuzzy/__manifest__.py b/base_search_fuzzy/__manifest__.py index e3c428fd9c5..3e899b9cb4b 100644 --- a/base_search_fuzzy/__manifest__.py +++ b/base_search_fuzzy/__manifest__.py @@ -5,7 +5,7 @@ "name": "Fuzzy Search", "summary": "Fuzzy search with the PostgreSQL trigram extension", "category": "Uncategorized", - "version": "15.0.1.0.0", + "version": "16.0.1.0.0", "website": "https://github.com/OCA/server-tools", "author": "bloopark systems GmbH & Co. KG, " "ForgeFlow, " diff --git a/base_search_fuzzy/demo/TrgmIndex_demo.xml b/base_search_fuzzy/demo/TrgmIndex_demo.xml index 02719b8ab96..0a665b2622f 100644 --- a/base_search_fuzzy/demo/TrgmIndex_demo.xml +++ b/base_search_fuzzy/demo/TrgmIndex_demo.xml @@ -1,4 +1,3 @@ - diff --git a/base_search_fuzzy/demo/res_partner_demo.xml b/base_search_fuzzy/demo/res_partner_demo.xml index 93ab073a8c5..52b2bf2b2c4 100644 --- a/base_search_fuzzy/demo/res_partner_demo.xml +++ b/base_search_fuzzy/demo/res_partner_demo.xml @@ -1,14 +1,16 @@ - John Smith + John Smizz + Linus Torvalds + res.partner diff --git a/base_search_fuzzy/hooks.py b/base_search_fuzzy/hooks.py index fb83ba4e9ab..264232006a8 100644 --- a/base_search_fuzzy/hooks.py +++ b/base_search_fuzzy/hooks.py @@ -25,11 +25,11 @@ def _wrapper(self, leaf, model, alias): raise ValueError( "Invalid field {!r} in domain term {!r}".format(left, leaf) ) + # Generate correct WHERE clause part - query = '("{}"."{}" %% {})'.format( + query = '("{}"."{}" %% %s)'.format( alias, left, - model._fields[left].column_format, ) params = [right] return query, params diff --git a/base_search_fuzzy/models/query.py b/base_search_fuzzy/models/query.py index add791a2bd9..8b2592358f1 100644 --- a/base_search_fuzzy/models/query.py +++ b/base_search_fuzzy/models/query.py @@ -5,7 +5,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo.osv import query +from odoo.tools import query Oridinal_Query_obj = query.Query diff --git a/base_search_fuzzy/models/trgm_index.py b/base_search_fuzzy/models/trgm_index.py index 192704d66b8..f486df744b3 100644 --- a/base_search_fuzzy/models/trgm_index.py +++ b/base_search_fuzzy/models/trgm_index.py @@ -163,11 +163,12 @@ def index_exists(self, model_name, field_name): trgm_index = self.search([("field_id", "=", field.id)], limit=1) return bool(trgm_index) - @api.model - def create(self, vals): - rec = super().create(vals) - rec.index_name = rec.create_index() - return rec + @api.model_create_multi + def create(self, vals_list): + recs = super().create(vals_list) + for rec in recs: + rec.index_name = rec.create_index() + return recs def unlink(self): for rec in self: diff --git a/base_search_fuzzy/readme/CONTRIBUTORS.rst b/base_search_fuzzy/readme/CONTRIBUTORS.rst index 37599d228d4..b7c8bdc409c 100644 --- a/base_search_fuzzy/readme/CONTRIBUTORS.rst +++ b/base_search_fuzzy/readme/CONTRIBUTORS.rst @@ -6,4 +6,7 @@ * `Tecnativa `_: * Vicent Cubells * Ernesto Tejeda + * teodoralexandru@nexterp.ro 2020 NextERP SRL. +* Daniel Reis +* Nikul Chaudhary diff --git a/base_search_fuzzy/tests/test_query_generation.py b/base_search_fuzzy/tests/test_query_generation.py index 9f48a8f5a7f..2bb3d9e5068 100644 --- a/base_search_fuzzy/tests/test_query_generation.py +++ b/base_search_fuzzy/tests/test_query_generation.py @@ -46,7 +46,7 @@ def test_fuzzy_where_generation_translatable(self): # the % parameter has to be escaped (%%) for the string replation self.assertIn( - """COALESCE("res_partner_category__name"."value", "res_partner_category"."name") %% %s""", # noqa + """("res_partner_category"."name"->>'en_US' %% %s)""", where_clause, ) @@ -56,7 +56,7 @@ def test_fuzzy_where_generation_translatable(self): ) self.assertIn( - b"""SELECT FROM "res_partner_category" LEFT JOIN "ir_translation" AS "res_partner_category__name" ON ("res_partner_category"."id" = "res_partner_category__name"."res_id" AND "res_partner_category__name"."type" = \'model\' AND "res_partner_category__name"."name" = \'res.partner.category,name\' AND "res_partner_category__name"."lang" = \'de_DE\' AND "res_partner_category__name"."value" != \'\') WHERE COALESCE("res_partner_category__name"."value", "res_partner_category"."name") % \'Goschaeftlic\'""", # noqa + b'SELECT FROM "res_partner_category" WHERE ("res_partner_category"."name"->>\'en_US\' % \'Goschaeftlic\')', # noqa complete_where, ) @@ -71,9 +71,9 @@ def test_fuzzy_search(self): {"field_id": field_partner_name.id, "index_type": "gin"} ) - partner1 = self.ResPartner.create({"name": "John Smith"}) - partner2 = self.ResPartner.create({"name": "John Smizz"}) - partner3 = self.ResPartner.create({"name": "Linus Torvalds"}) + partner1, partner2, partner3 = self.ResPartner.create( + [{"name": "John Smith"}, {"name": "John Smizz"}, {"name": "Linus Torvalds"}] + ) res = self.ResPartner.search([("name", "%", "Jon Smith")]) self.assertIn(partner1.id, res.ids) diff --git a/setup/base_search_fuzzy/odoo/addons/base_search_fuzzy b/setup/base_search_fuzzy/odoo/addons/base_search_fuzzy new file mode 120000 index 00000000000..916c8ba1343 --- /dev/null +++ b/setup/base_search_fuzzy/odoo/addons/base_search_fuzzy @@ -0,0 +1 @@ +../../../../base_search_fuzzy \ No newline at end of file diff --git a/setup/base_search_fuzzy/setup.py b/setup/base_search_fuzzy/setup.py new file mode 100644 index 00000000000..28c57bb6403 --- /dev/null +++ b/setup/base_search_fuzzy/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)