Skip to content

[ADD] search_ux: search products and partners by keywords and configurable fields - #441

Open
mav-adhoc wants to merge 1 commit into
ingadhoc:19.0from
adhoc-dev:19.0-t-72472-mav
Open

[ADD] search_ux: search products and partners by keywords and configurable fields#441
mav-adhoc wants to merge 1 commit into
ingadhoc:19.0from
adhoc-dev:19.0-t-72472-mav

Conversation

@mav-adhoc

@mav-adhoc mav-adhoc commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Sustainable replacement for base_name_search_improved (OCA), on products and partners.

Task: https://www.adhoc.inc/odoo/all-tasks/12857/all-tasks/72472

What it does out of the box

  • A "search keywords" field (internal, trigram indexed) on product.template and res.partner, for aliases, nicknames and trade names.
  • That field already included in the search of those two models. Nothing else enabled.

How it hooks

Model Hook
product.template, product.product name_search: calls super() and completes the suggestion list only if the native cascade did not fill limit
res.partner _search_display_name: adds the fields to the same declarative domain, no extra query

No _inherit = "base", no _register_hook, no monkeypatching of the registry. Only the two models inherit the mixin, explicitly.

Multi word: the term is split and all words must appear, in any order and in any configured field, built as a single domain resolved in a single query.

What the consultant configures

Settings > Technical > "Extended Search", per model: fields to include (model fields, Studio fields and forward paths like product_tmpl_id.my_field), related sources for products (lots/serials, vendor code, packaging barcodes), minimum characters before triggering (default 3), and archiving to turn it off completely.

It rejects on save, with an explanation: html fields, binary/attachment fields, non stored fields, wrong paths, group restricted fields and more than 5 fields per model (search_ux.max_fields).

Customization

A customer module adds its own source by inheriting a single extension point, without forking:

def _get_extra_search_domains(self, term):
    domains = super()._get_extra_search_domains(term)
    domains.append(Domain("id", "in",
        self.env["my.model"]._search([("code", "ilike", term)]).subselect("product_id")))
    return domains

Test plan

13 tests, green on a 19.0 database with only search_ux installed:

odoo.tests.stats: search_ux: 15 tests 0.21s 278 queries
odoo.tests.result: 0 failed, 0 error(s) of 13 tests

They discriminate: neutralizing _get_extra_search_domains makes 4 of them fail (keywords on product, on template, on partner, multi word and minimum characters).

Covered: keywords on the three models, native behaviour untouched without configuration, the extended search not running when the native one fills the limit, multi word in a single query, minimum characters, turning it off, the received domain being honoured, the extension point, and every rejected configuration.

Not included on purpose

Typo correction, lot reservation when the product is found by serial, and searching inside html descriptions.

@roboadhoc

Copy link
Copy Markdown
Contributor

Pull request status dashboard

@mav-adhoc
mav-adhoc force-pushed the 19.0-t-72472-mav branch 3 times, most recently from b672c8c to db55487 Compare August 24, 2026 19:31
…rable fields

Adds a "search keywords" field on products and partners for aliases and
trade names, and a per model configuration to add fields and related
sources to the search.

It only hooks into the extension points Odoo documents: name_search on
product.template and product.product (calling super and completing the
suggestion list) and _search_display_name on res.partner. Only those
models inherit the mixin, and the extra criteria are built as a single
domain resolved in a single query, which runs only when the native
search did not fill the limit.

The configuration lives on its own model, restricted to the models that
inherit the mixin, and rejects on save what cannot be sustained: html,
binary and non stored fields, wrong paths, group restricted fields and
more than five fields per model.

Customer specific sources are added from customer modules by inheriting
_get_extra_search_domains, without forking this module.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants