Skip to content

Commit

Permalink
Merge PR #178 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by bguillot
  • Loading branch information
OCA-git-bot committed Feb 1, 2024
2 parents dce9d7b + ee7e3cd commit 1a92f2a
Show file tree
Hide file tree
Showing 19 changed files with 724 additions and 0 deletions.
96 changes: 96 additions & 0 deletions product_search_multi_value/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
==========================
Product Search Multi Value
==========================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:9d22337e1ca831145830acd08136f0828db22d5e868807321209fbba2c967d0f
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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%2Fodoo--pim-lightgray.png?logo=github
:target: https://github.com/OCA/odoo-pim/tree/16.0/product_search_multi_value
:alt: OCA/odoo-pim
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/odoo-pim-16-0/odoo-pim-16-0-product_search_multi_value
: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/odoo-pim&target_branch=16.0
:alt: Try me on Runboat

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

This module allows users to search products based on a list of default codes or barcodes.
It can be extended to other values if needed.

**Table of contents**

.. contents::
:local:

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

By default, the multi value search looks on default_code and barcode properties.
If you need to extend to other property, you just need to adapt the related system parameter: 'product_search_multi_value.search_field'.

Usage
=====

Go on the product search view and search on a list of default_code separated by a space.
The search must be based on "Multiple search" field.

Known issues / Roadmap
======================

* The searched fields should not be related non stored ones where the target
model has an 'active' field as it can leads to not found records.

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/odoo-pim/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/odoo-pim/issues/new?body=module:%20product_search_multi_value%0Aversion:%2016.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
~~~~~~~

* ACSONE SA/NV

Contributors
~~~~~~~~~~~~

* Cédric PIGEON <[email protected]>
* Xavier Bouquiaux <[email protected]>

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.

This module is part of the `OCA/odoo-pim <https://github.com/OCA/odoo-pim/tree/16.0/product_search_multi_value>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions product_search_multi_value/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
13 changes: 13 additions & 0 deletions product_search_multi_value/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2020 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Product Search Multi Value",
"version": "16.0.1.0.0",
"license": "AGPL-3",
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/odoo-pim",
"depends": ["product"],
"data": ["data/search_field_data.xml", "views/product_template_view.xml"],
"demo": [],
}
6 changes: 6 additions & 0 deletions product_search_multi_value/data/search_field_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<odoo noupdate="1">
<record model="ir.config_parameter" id="search_fields">
<field name="key">product_search_multi_value.search_fields</field>
<field name="value">['default_code', 'description']</field>
</record>
</odoo>
46 changes: 46 additions & 0 deletions product_search_multi_value/i18n/product_search_multi_value.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * product_search_multi_value
#
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: product_search_multi_value
#: model:ir.model.fields,field_description:product_search_multi_value.field_product_template__display_name
msgid "Display Name"
msgstr ""

#. module: product_search_multi_value
#: model:ir.model.fields,field_description:product_search_multi_value.field_product_template__id
msgid "ID"
msgstr ""

#. module: product_search_multi_value
#: model:ir.model.fields,field_description:product_search_multi_value.field_product_template____last_update
msgid "Last Modified on"
msgstr ""

#. module: product_search_multi_value
#: model:ir.model.fields,field_description:product_search_multi_value.field_product_product__search_multi
#: model:ir.model.fields,field_description:product_search_multi_value.field_product_template__search_multi
msgid "Multiple search"
msgstr ""

#. module: product_search_multi_value
#: code:addons/product_search_multi_value/models/product_template.py:0
#, python-format
msgid "Operator %s is not usable with multisearch"
msgstr ""

#. module: product_search_multi_value
#: model:ir.model,name:product_search_multi_value.model_product_template
msgid "Product Template"
msgstr ""
1 change: 1 addition & 0 deletions product_search_multi_value/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import product_template
54 changes: 54 additions & 0 deletions product_search_multi_value/models/product_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Copyright 2020 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import logging

from odoo import _, api, fields, models
from odoo.exceptions import UserError
from odoo.osv.expression import OR
from odoo.tools.safe_eval import safe_eval

_logger = logging.getLogger(__name__)


class ProductTemplate(models.Model):

_inherit = "product.template"

search_multi = fields.Char(
"Multiple search",
compute="_compute_search_multi",
search="_search_multi",
)

def _compute_search_multi(self):
self.update({"search_multi": False})

@api.model
def _get_search_fields(self):
try:
search_fields = (
self.env["ir.config_parameter"]
.sudo()
.get_param("product_search_multi_value.search_fields")
)
return safe_eval(search_fields)
except SyntaxError as error:
_logger.error("Error while evaluating search fields")
_logger.error(error)
return []

def _search_multi(self, operator, value):
if operator == "=" or operator == "ilike":
operator = "in"
comparator = OR
else:
raise UserError(_("Operator %s is not usable with multisearch", operator))

value_list = value.split(" ") if " " in value else [value]
search_fields = self._get_search_fields()
domain_list = []
for search_field in search_fields:
domain_search_field = [(search_field, operator, tuple(value_list))]
domain_list.append(domain_search_field)
return comparator(domain_list)
2 changes: 2 additions & 0 deletions product_search_multi_value/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
By default, the multi value search looks on default_code and barcode properties.
If you need to extend to other property, you just need to adapt the related system parameter: 'product_search_multi_value.search_field'.
2 changes: 2 additions & 0 deletions product_search_multi_value/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Cédric PIGEON <[email protected]>
* Xavier Bouquiaux <[email protected]>
2 changes: 2 additions & 0 deletions product_search_multi_value/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This module allows users to search products based on a list of default codes or barcodes.
It can be extended to other values if needed.
2 changes: 2 additions & 0 deletions product_search_multi_value/readme/ROADMAP.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* The searched fields should not be related non stored ones where the target
model has an 'active' field as it can leads to not found records.
2 changes: 2 additions & 0 deletions product_search_multi_value/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Go on the product search view and search on a list of default_code separated by a space.
The search must be based on "Multiple search" field.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 1a92f2a

Please sign in to comment.