[MIG] base_search_fuzzy: Migrated to v16
parent
ca64967391
commit
3b5f41c0de
|
@ -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, "
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<odoo>
|
||||
<record id="trgm_index_gin_partner_name" model="trgm.index">
|
||||
<field name="field_id" ref="base.field_res_partner__name" />
|
||||
|
|
|
@ -1,14 +1,16 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<odoo>
|
||||
<record id="res_partner_John_Smith" model="res.partner">
|
||||
<field name="name">John Smith</field>
|
||||
</record>
|
||||
|
||||
<record id="res_partner_John_Smizz" model="res.partner">
|
||||
<field name="name">John Smizz</field>
|
||||
</record>
|
||||
|
||||
<record id="res_partner_Linus_Torvalds" model="res.partner">
|
||||
<field name="name">Linus Torvalds</field>
|
||||
</record>
|
||||
|
||||
<record id="view_res_partner_filter" model="ir.ui.view">
|
||||
<field name="model">res.partner</field>
|
||||
<field name="inherit_id" ref="base.view_res_partner_filter" />
|
||||
|
|
|
@ -25,11 +25,11 @@ def patch_leaf_trgm(original):
|
|||
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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -163,11 +163,12 @@ class TrgmIndex(models.Model):
|
|||
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:
|
||||
|
|
|
@ -6,4 +6,7 @@
|
|||
* `Tecnativa <https://www.tecnativa.com>`_:
|
||||
* Vicent Cubells
|
||||
* Ernesto Tejeda
|
||||
|
||||
* teodoralexandru@nexterp.ro 2020 NextERP SRL.
|
||||
* Daniel Reis <dreis@opensourceintegrators.com>
|
||||
* Nikul Chaudhary <nchaudhary@opensourceintegrators.com>
|
||||
|
|
|
@ -46,7 +46,7 @@ class QueryGenerationCase(TransactionCase):
|
|||
|
||||
# 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 @@ class QueryGenerationCase(TransactionCase):
|
|||
)
|
||||
|
||||
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 @@ class QueryGenerationCase(TransactionCase):
|
|||
{"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)
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
../../../../base_search_fuzzy
|
|
@ -0,0 +1,6 @@
|
|||
import setuptools
|
||||
|
||||
setuptools.setup(
|
||||
setup_requires=['setuptools-odoo'],
|
||||
odoo_addon=True,
|
||||
)
|
Loading…
Reference in New Issue