Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 115 additions & 0 deletions base_name_search_multi_lang/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
======================
Name Search Multi Lang
======================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:93b25b918e684a24cabcf121005768369e05189b159a408efd4715ea703b18cd
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
: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/18.0/base_name_search_multi_lang
: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-18-0/server-tools-18-0-base_name_search_multi_lang
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-tools&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module extends the name search feature to use other translated
languages.

For example, if a product name in English is "Chair", and Thai is "เก้าอี้"

Given user language preference is English, when user types name to
search on product field, "Chair", the product with this name will be
found. But if user types in Thai, "เก้าอี้", no result will be shown.

With this module installed, and model product.product is set to use
"Search Translated Name". Searching by Thai name, "เก้าอี้", now finds the
product "Chair".

Every search matching a translated field with a pattern is extended, so
this covers the Many2one fields as well as the search views.

**Table of contents**

.. contents::
:local:

Configuration
=============

Additional search fields can be configured at Settings > Technical >
Database > Models, using the "Search Translated Name" field.

Usage
=====

Just type into any field with translated names, such as Product on a
Sales Order, or into the search box of a list view.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-tools/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/server-tools/issues/new?body=module:%20base_name_search_multi_lang%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
-------

* Ecosoft

Contributors
------------

- Kitti U. <kittiu@ecosoft.co.th>

Migration
~~~~~~~~~

- Nakrob S. <nakrobs@ecosoft.co.th> (18.0 migration)

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

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.

.. |maintainer-kittiu| image:: https://github.com/kittiu.png?size=40px
:target: https://github.com/kittiu
:alt: kittiu

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-kittiu|

This module is part of the `OCA/server-tools <https://github.com/OCA/server-tools/tree/18.0/base_name_search_multi_lang>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
3 changes: 3 additions & 0 deletions base_name_search_multi_lang/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Copyright 2020 Ecosoft Co., Ltd (http://ecosoft.co.th/)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)
from . import models
15 changes: 15 additions & 0 deletions base_name_search_multi_lang/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2020 Ecosoft Co., Ltd (http://ecosoft.co.th/)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)
{
"name": "Name Search Multi Lang",
"summary": "Name search by multiple active language",
"version": "18.0.1.0.0",
"category": "Tools",
"website": "https://github.com/OCA/server-tools",
"author": "Ecosoft, Odoo Community Association (OCA)",
"license": "AGPL-3",
"depends": ["base"],
"data": ["views/ir_model_views.xml"],
"maintainers": ["kittiu"],
"installable": True,
}
49 changes: 49 additions & 0 deletions base_name_search_multi_lang/i18n/base_name_search_multi_lang.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * base_name_search_multi_lang
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: base_name_search_multi_lang
#: model:ir.model.fields,field_description:base_name_search_multi_lang.field_ir_model__display_name
msgid "Display Name"
msgstr ""

#. module: base_name_search_multi_lang
#: model:ir.model.fields,field_description:base_name_search_multi_lang.field_ir_model__id
msgid "ID"
msgstr ""

#. module: base_name_search_multi_lang
#: model:ir.model.fields,field_description:base_name_search_multi_lang.field_ir_model____last_update
msgid "Last Modified on"
msgstr ""

#. module: base_name_search_multi_lang
#: model:ir.model,name:base_name_search_multi_lang.model_ir_model
msgid "Models"
msgstr ""

#. module: base_name_search_multi_lang
#: model:ir.model.fields,help:base_name_search_multi_lang.field_ir_model__name_search_multi_lang
msgid "Name search this model from all translated languages"
msgstr ""

#. module: base_name_search_multi_lang
#: model:ir.model.fields,field_description:base_name_search_multi_lang.field_ir_model__name_search_multi_lang
msgid "Search Translated Name"
msgstr ""

#. module: base_name_search_multi_lang
#: model:ir.model.fields,field_description:base_name_search_multi_lang.field_ir_model__smart_search
msgid "Smart Search"
msgstr ""
52 changes: 52 additions & 0 deletions base_name_search_multi_lang/i18n/es_AR.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * base_name_search_multi_lang
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2022-09-04 06:07+0000\n"
"Last-Translator: Ignacio Buioli <ibuioli@gmail.com>\n"
"Language-Team: none\n"
"Language: es_AR\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 4.3.2\n"

#. module: base_name_search_multi_lang
#: model:ir.model.fields,field_description:base_name_search_multi_lang.field_ir_model__display_name
msgid "Display Name"
msgstr "Mostrar Nombre"

#. module: base_name_search_multi_lang
#: model:ir.model.fields,field_description:base_name_search_multi_lang.field_ir_model__id
msgid "ID"
msgstr "ID"

#. module: base_name_search_multi_lang
#: model:ir.model.fields,field_description:base_name_search_multi_lang.field_ir_model____last_update
msgid "Last Modified on"
msgstr "Última modificación en"

#. module: base_name_search_multi_lang
#: model:ir.model,name:base_name_search_multi_lang.model_ir_model
msgid "Models"
msgstr "Modelos"

#. module: base_name_search_multi_lang
#: model:ir.model.fields,help:base_name_search_multi_lang.field_ir_model__name_search_multi_lang
msgid "Name search this model from all translated languages"
msgstr "Búsqueda por nombre de este modelo en todos los idiomas traducidos"

#. module: base_name_search_multi_lang
#: model:ir.model.fields,field_description:base_name_search_multi_lang.field_ir_model__name_search_multi_lang
msgid "Search Translated Name"
msgstr "Buscar Nombre Traducido"

#. module: base_name_search_multi_lang
#: model:ir.model.fields,field_description:base_name_search_multi_lang.field_ir_model__smart_search
msgid "Smart Search"
msgstr "Búsqueda Inteligente"
52 changes: 52 additions & 0 deletions base_name_search_multi_lang/i18n/it.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * base_name_search_multi_lang
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2025-03-14 15:06+0000\n"
"Last-Translator: mymage <stefano.consolaro@mymage.it>\n"
"Language-Team: none\n"
"Language: it\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 5.10.2\n"

#. module: base_name_search_multi_lang
#: model:ir.model.fields,field_description:base_name_search_multi_lang.field_ir_model__display_name
msgid "Display Name"
msgstr "Nome visualizzato"

#. module: base_name_search_multi_lang
#: model:ir.model.fields,field_description:base_name_search_multi_lang.field_ir_model__id
msgid "ID"
msgstr ""

#. module: base_name_search_multi_lang
#: model:ir.model.fields,field_description:base_name_search_multi_lang.field_ir_model____last_update
msgid "Last Modified on"
msgstr ""

#. module: base_name_search_multi_lang
#: model:ir.model,name:base_name_search_multi_lang.model_ir_model
msgid "Models"
msgstr ""

#. module: base_name_search_multi_lang
#: model:ir.model.fields,help:base_name_search_multi_lang.field_ir_model__name_search_multi_lang
msgid "Name search this model from all translated languages"
msgstr ""

#. module: base_name_search_multi_lang
#: model:ir.model.fields,field_description:base_name_search_multi_lang.field_ir_model__name_search_multi_lang
msgid "Search Translated Name"
msgstr ""

#. module: base_name_search_multi_lang
#: model:ir.model.fields,field_description:base_name_search_multi_lang.field_ir_model__smart_search
msgid "Smart Search"
msgstr ""
4 changes: 4 additions & 0 deletions base_name_search_multi_lang/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2020 Ecosoft Co., Ltd (http://ecosoft.co.th/)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)
from . import base
from . import ir_model
65 changes: 65 additions & 0 deletions base_name_search_multi_lang/models/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Copyright 2020 Ecosoft Co., Ltd (http://ecosoft.co.th/)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)
from odoo import models, tools
from odoo.osv import expression
from odoo.tools import SQL

# Other operators compare the value as a whole, where matching another
# language makes no sense
PATTERN_OPERATORS = ("like", "ilike", "not like", "not ilike", "=like", "=ilike")


class Base(models.AbstractModel):
_inherit = "base"

@tools.ormcache("self._name")
def _name_search_multi_lang_enabled(self):
"""Whether this model is searched in all the installed languages"""
data = (
self.env["ir.model"]
.sudo()
.search_read([("model", "=", self._name)], ["name_search_multi_lang"])
)
return bool(data and data[0]["name_search_multi_lang"])

def _condition_to_sql(self, alias, fname, operator, value, query):
"""Match a translated field in every language

The standard implementation only matches the current language, with a
fallback on the company ones.
"""
sql = super()._condition_to_sql(alias, fname, operator, value, query)
field = self._fields.get(fname)
if (
field is None
or not field.translate
or not field.store
or operator not in PATTERN_OPERATORS
or not isinstance(value, str)
or not value
or not self._name_search_multi_lang_enabled()
):
return sql
# All languages live in the same jsonb column, and this is the
# expression a trigram index is built on, so such an index is still used
sql_langs = self.env.registry.unaccent(
SQL(
"jsonb_path_query_array(%s, '$.*')::text",
SQL.identifier(alias, fname, to_flush=field),
)
)
sql_like = SQL("ILIKE") if operator.endswith("ilike") else SQL("LIKE")
sql_pattern = self.env.registry.unaccent(
SQL("%s", value if operator.startswith("=") else f"%{value}%")
)
if operator in expression.NEGATIVE_TERM_OPERATORS:
# Exclude the record as soon as one language matches
return SQL(
"(%s AND (%s IS NULL OR %s NOT %s %s))",
sql,
sql_langs,
sql_langs,
sql_like,
sql_pattern,
)
return SQL("(%s OR %s %s %s)", sql, sql_langs, sql_like, sql_pattern)
16 changes: 16 additions & 0 deletions base_name_search_multi_lang/models/ir_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2020 Ecosoft Co., Ltd (http://ecosoft.co.th/)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)
from odoo import api, fields, models


class IrModel(models.Model):
_inherit = "ir.model"

name_search_multi_lang = fields.Boolean(
string="Search Translated Name",
help="Name search this model from all translated languages",
)

@api.constrains("name_search_multi_lang")
def update_name_search_multi_lang(self):
self.env.registry.clear_cache()
3 changes: 3 additions & 0 deletions base_name_search_multi_lang/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
2 changes: 2 additions & 0 deletions base_name_search_multi_lang/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Additional search fields can be configured at Settings \> Technical \>
Database \> Models, using the "Search Translated Name" field.
5 changes: 5 additions & 0 deletions base_name_search_multi_lang/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- Kitti U. \<kittiu@ecosoft.co.th\>

## Migration

- Nakrob S. \<nakrobs@ecosoft.co.th\> (18.0 migration)
Loading
Loading