From 1b9706d8fd06b4832cc832cf4a4b48e7691798f9 Mon Sep 17 00:00:00 2001 From: Ernesto Tejeda Date: Wed, 25 Mar 2020 17:24:35 -0400 Subject: [PATCH] base_search_fuzzy: Migration to 13.0 --- base_search_fuzzy/README.rst | 23 +++++++--- base_search_fuzzy/__manifest__.py | 5 ++- base_search_fuzzy/demo/TrgmIndex_demo.xml | 7 ++++ base_search_fuzzy/demo/res_partner_demo.xml | 21 ++++++++++ base_search_fuzzy/i18n/base_search_fuzzy.pot | 2 +- base_search_fuzzy/models/ir_model.py | 11 +++-- base_search_fuzzy/models/trgm_index.py | 19 +++------ base_search_fuzzy/readme/USAGE.rst | 12 ++++++ .../static/description/index.html | 42 ++++++++++++------- .../tests/test_query_generation.py | 13 +++--- base_search_fuzzy/views/trgm_index.xml | 2 - 11 files changed, 107 insertions(+), 50 deletions(-) create mode 100644 base_search_fuzzy/demo/TrgmIndex_demo.xml create mode 100644 base_search_fuzzy/demo/res_partner_demo.xml diff --git a/base_search_fuzzy/README.rst b/base_search_fuzzy/README.rst index 7775805b6..e54a3f571 100644 --- a/base_search_fuzzy/README.rst +++ b/base_search_fuzzy/README.rst @@ -14,13 +14,13 @@ Fuzzy Search :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github - :target: https://github.com/OCA/server-tools/tree/12.0/base_search_fuzzy + :target: https://github.com/OCA/server-tools/tree/13.0/base_search_fuzzy :alt: OCA/server-tools .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/server-tools-12-0/server-tools-12-0-base_search_fuzzy + :target: https://translation.odoo-community.org/projects/server-tools-13-0/server-tools-13-0-base_search_fuzzy :alt: Translate me on Weblate .. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png - :target: https://runbot.odoo-community.org/runbot/149/12.0 + :target: https://runbot.odoo-community.org/runbot/149/13.0 :alt: Try me on Runbot |badge1| |badge2| |badge3| |badge4| |badge5| @@ -81,6 +81,19 @@ Usage For further questions read the Documentation of the `pg_trgm `_ module. + +Usage with demo data +==================== + +There are some demo data that allow you to test functionally this module +if you are in a **demo** database. The steps are the following: + +#. Then type the text **Jon Smith** or **Smith John** in the search box and + select **Search Display Name for: ...** +#. You will see two contacts, and they are the ones with display names + **John Smith** and **John Smizz**. (See corresponding `demo code + `_) + Known issues / Roadmap ====================== @@ -93,7 +106,7 @@ Bug Tracker Bugs are tracked on `GitHub Issues `_. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us smashing it by providing a detailed and welcomed -`feedback `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -133,6 +146,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. -This module is part of the `OCA/server-tools `_ project on GitHub. +This module is part of the `OCA/server-tools `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/base_search_fuzzy/__manifest__.py b/base_search_fuzzy/__manifest__.py index 4447e1fc4..9ee27afbe 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": "12.0.1.0.0", + "version": "13.0.1.0.0", "website": "https://github.com/OCA/server-tools", "author": "bloopark systems GmbH & Co. KG, " "Eficent, " @@ -13,6 +13,7 @@ "Odoo Community Association (OCA)", "license": "AGPL-3", "depends": ["base"], - "data": ["views/trgm_index.xml", "security/ir.model.access.csv",], + "data": ["views/trgm_index.xml", "security/ir.model.access.csv"], + "demo": ["demo/res_partner_demo.xml", "demo/TrgmIndex_demo.xml"], "installable": True, } diff --git a/base_search_fuzzy/demo/TrgmIndex_demo.xml b/base_search_fuzzy/demo/TrgmIndex_demo.xml new file mode 100644 index 000000000..02719b8ab --- /dev/null +++ b/base_search_fuzzy/demo/TrgmIndex_demo.xml @@ -0,0 +1,7 @@ + + + + + gin + + diff --git a/base_search_fuzzy/demo/res_partner_demo.xml b/base_search_fuzzy/demo/res_partner_demo.xml new file mode 100644 index 000000000..93ab073a8 --- /dev/null +++ b/base_search_fuzzy/demo/res_partner_demo.xml @@ -0,0 +1,21 @@ + + + + John Smith + + + John Smizz + + + Linus Torvalds + + + res.partner + + + + + + + + diff --git a/base_search_fuzzy/i18n/base_search_fuzzy.pot b/base_search_fuzzy/i18n/base_search_fuzzy.pot index bde60e046..0ff610051 100644 --- a/base_search_fuzzy/i18n/base_search_fuzzy.pot +++ b/base_search_fuzzy/i18n/base_search_fuzzy.pot @@ -4,7 +4,7 @@ # msgid "" msgstr "" -"Project-Id-Version: Odoo Server 12.0\n" +"Project-Id-Version: Odoo Server 13.0\n" "Report-Msgid-Bugs-To: \n" "Last-Translator: <>\n" "Language-Team: \n" diff --git a/base_search_fuzzy/models/ir_model.py b/base_search_fuzzy/models/ir_model.py index a113c5997..6d584b165 100644 --- a/base_search_fuzzy/models/ir_model.py +++ b/base_search_fuzzy/models/ir_model.py @@ -25,15 +25,15 @@ def patch_leaf_trgm(method): if left in model._fields: column = "{}.{}".format(table_alias, expression._quote(left)) query = "({} {} {})".format( - column, - sql_operator, - model._fields[left].column_format, + column, sql_operator, model._fields[left].column_format, ) elif left in models.MAGIC_COLUMNS: query = '({}."{}" {} %s)'.format(table_alias, left, sql_operator) params = right else: # Must not happen - raise ValueError(_("Invalid field {!r} in domain term {!r}".format(left, leaf))) + raise ValueError( + _("Invalid field {!r} in domain term {!r}".format(left, leaf)) + ) if left in model._fields: params = str(right) @@ -67,7 +67,6 @@ class IrModel(models.Model): _inherit = "ir.model" - @api.model_cr def _register_hook(self): # We have to prevent wrapping the function twice to avoid recursion # errors @@ -83,4 +82,4 @@ class IrModel(models.Model): models.BaseModel._generate_order_by = patch_generate_order_by( models.BaseModel._generate_order_by ) - return super(IrModel, self)._register_hook() + return super()._register_hook() diff --git a/base_search_fuzzy/models/trgm_index.py b/base_search_fuzzy/models/trgm_index.py index 90d256458..ba30957db 100644 --- a/base_search_fuzzy/models/trgm_index.py +++ b/base_search_fuzzy/models/trgm_index.py @@ -47,7 +47,6 @@ class TrgmIndex(models.Model): 'GiST for often-updated data."', ) - @api.model_cr def _trgm_extension_exists(self): self.env.cr.execute( """ @@ -67,18 +66,16 @@ class TrgmIndex(models.Model): return "installed" - @api.model_cr def _is_postgres_superuser(self): self.env.cr.execute("SHOW is_superuser;") superuser = self.env.cr.fetchone() return superuser is not None and superuser[0] == "on" or False - @api.model_cr def _install_trgm_extension(self): extension = self._trgm_extension_exists() if extension == "missing": _logger.warning( - "To use pg_trgm you have to install the " "postgres-contrib module." + "To use pg_trgm you have to install the postgres-contrib module." ) elif extension == "uninstalled": if self._is_postgres_superuser(): @@ -94,9 +91,8 @@ class TrgmIndex(models.Model): return True return False - @api.model_cr_context def _auto_init(self): - res = super(TrgmIndex, self)._auto_init() + res = super()._auto_init() if self._install_trgm_extension(): _logger.info( "The pg_trgm is loaded in the database and the " @@ -104,7 +100,6 @@ class TrgmIndex(models.Model): ) return res - @api.model_cr def get_not_used_index(self, index_name, table_name, inc=1): if inc > 1: new_index_name = index_name + str(inc) @@ -127,13 +122,12 @@ class TrgmIndex(models.Model): return False, new_index_name - @api.multi def create_index(self): self.ensure_one() if not self._install_trgm_extension(): raise exceptions.UserError( - _("The pg_trgm extension does not exists or cannot be " "installed.") + _("The pg_trgm extension does not exists or cannot be installed.") ) table_name = self.env[self.field_id.model_id.model]._table @@ -172,17 +166,16 @@ class TrgmIndex(models.Model): @api.model def create(self, vals): - rec = super(TrgmIndex, self).create(vals) + rec = super().create(vals) rec.index_name = rec.create_index() return rec - @api.multi def unlink(self): for rec in self: self.env.cr.execute( """ DROP INDEX IF EXISTS %(index)s; """, - {"index": AsIs(rec.index_name),}, + {"index": AsIs(rec.index_name)}, ) - return super(TrgmIndex, self).unlink() + return super().unlink() diff --git a/base_search_fuzzy/readme/USAGE.rst b/base_search_fuzzy/readme/USAGE.rst index 2f667ac81..04f30223d 100644 --- a/base_search_fuzzy/readme/USAGE.rst +++ b/base_search_fuzzy/readme/USAGE.rst @@ -22,3 +22,15 @@ For further questions read the Documentation of the `pg_trgm `_ module. + + +Usage with demo data +==================== + +There are some demo data that allow you to test functionally this module +if you are in a **demo** database. The steps are the following: + +#. Go to *Contacts* and type the text **Jon Smith** or **Smith John** in + the search box and select **Search Display Name for: ...** +#. You will see two contacts, and they are the ones with display names + **John Smith** and **John Smizz**. diff --git a/base_search_fuzzy/static/description/index.html b/base_search_fuzzy/static/description/index.html index 1e030f3b1..203175597 100644 --- a/base_search_fuzzy/static/description/index.html +++ b/base_search_fuzzy/static/description/index.html @@ -367,7 +367,7 @@ ul.auto-toc { !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

Beta License: AGPL-3 OCA/server-tools Translate me on Weblate Try me on Runbot

+

Beta License: AGPL-3 OCA/server-tools Translate me on Weblate Try me on Runbot

This addon provides the ability to create GIN or GiST indexes of char and text fields and also to use the search operator % in search domains. Currently this module doesn’t change the backend search or anything else. It provides @@ -378,12 +378,13 @@ only the possibility to perform the fuzzy search for external addons.

  • Installation
  • Configuration
  • Usage
  • -
  • Known issues / Roadmap
  • -
  • Bug Tracker
  • -
  • Credits @@ -434,25 +435,36 @@ followed:

    For further questions read the Documentation of the pg_trgm module.

    +
    +

    Usage with demo data

    +

    There are some demo data that allow you to test functionally this module +if you are in a demo database. The steps are the following:

    +
      +
    1. Then type the text Jon Smith or Smith John in the search box and +select Search Display Name for: …
    2. +
    3. You will see two contacts, and they are the ones with display names +John Smith and John Smizz. (See corresponding demo code)
    4. +
    +
    -

    Known issues / Roadmap

    +

    Known issues / Roadmap

    • Modify the general search parts (e.g. in tree view or many2one fields)
    • Add better order by handling
    -

    Bug Tracker

    +

    Bug Tracker

    Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us smashing it by providing a detailed and welcomed -feedback.

    +feedback.

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

    -

    Credits

    +

    Credits

    -

    Authors

    +

    Authors

    • bloopark systems GmbH & Co. KG
    • Eficent
    • @@ -460,7 +472,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
    -

    Contributors

    +

    Contributors

    -

    Maintainers

    +

    Maintainers

    This module is maintained by the OCA.

    Odoo Community Association

    OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.

    -

    This module is part of the OCA/server-tools project on GitHub.

    +

    This module is part of the OCA/server-tools project on GitHub.

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

    diff --git a/base_search_fuzzy/tests/test_query_generation.py b/base_search_fuzzy/tests/test_query_generation.py index 9464f6379..f050585c2 100644 --- a/base_search_fuzzy/tests/test_query_generation.py +++ b/base_search_fuzzy/tests/test_query_generation.py @@ -2,11 +2,10 @@ # Copyright 2016 Serpent Consulting Services Pvt. Ltd. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo.osv import expression -from odoo.tests.common import TransactionCase, at_install, post_install +from odoo.tests.common import TransactionCase, tagged -@at_install(False) -@post_install(True) +@tagged("post_install", "-at_install") class QueryGenerationCase(TransactionCase): def setUp(self): super(QueryGenerationCase, self).setUp() @@ -30,7 +29,8 @@ class QueryGenerationCase(TransactionCase): # test the right sql query statement creation # now there should be only one '%' complete_where = self.env.cr.mogrify( - "SELECT FROM {} WHERE {}".format(from_clause, where_clause), where_clause_params + "SELECT FROM {} WHERE {}".format(from_clause, where_clause), + where_clause_params, ) self.assertEqual( complete_where, @@ -53,7 +53,8 @@ class QueryGenerationCase(TransactionCase): ) complete_where = self.env.cr.mogrify( - "SELECT FROM {} WHERE {}".format(from_clause, where_clause), where_clause_params + "SELECT FROM {} WHERE {}".format(from_clause, where_clause), + where_clause_params, ) self.assertIn( @@ -76,7 +77,7 @@ class QueryGenerationCase(TransactionCase): if not self.TrgmIndex.index_exists("res.partner", "name"): field_partner_name = self.env.ref("base.field_res_partner__name") self.TrgmIndex.create( - {"field_id": field_partner_name.id, "index_type": "gin",} + {"field_id": field_partner_name.id, "index_type": "gin"} ) partner1 = self.ResPartner.create({"name": "John Smith"}) diff --git a/base_search_fuzzy/views/trgm_index.xml b/base_search_fuzzy/views/trgm_index.xml index ce8cb3f63..e3514fd9c 100644 --- a/base_search_fuzzy/views/trgm_index.xml +++ b/base_search_fuzzy/views/trgm_index.xml @@ -32,9 +32,7 @@ Trigram Index trgm.index - form tree,form - ir.actions.act_window