Skip to content

Commit

Permalink
[ADD][16.0] base_search_multi_value: add
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinkhao committed Aug 27, 2024
1 parent adcd164 commit 03413c1
Show file tree
Hide file tree
Showing 17 changed files with 681 additions and 0 deletions.
100 changes: 100 additions & 0 deletions base_search_multi_value/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
=======================
Base Search Multi Value
=======================

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

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

This module allows users to search any arbitrary field using
space-separated values.

For example for sale orders you could search: S00001 S00002 S00003 and
it would return these three records.

**Table of contents**

.. contents::
:local:

Usage
=====

Inherit search.multi.value.mixin on your model and implement the search
fields getter

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

- add arbitrary delimiter

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-ux/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-ux/issues/new?body=module:%20base_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
-------

* Akretion

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

- Kevin Khao kevin.khao@akretion.com

Other credits
-------------

This module is heavily inspired by product_search_multi_value, credits
to the creators:

- Cédric PIGEON cedric.pigeon@acsone.eu
- Xavier Bouquiaux xavier.bouquiaux@acsone.eu

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/server-ux <https://github.com/OCA/server-ux/tree/16.0/base_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 base_search_multi_value/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
15 changes: 15 additions & 0 deletions base_search_multi_value/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2024 Akretion
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Base Search Multi Value",
"summary": """
Search multiple space-separated values""",
"version": "16.0.1.0.0",
"license": "AGPL-3",
"author": "Akretion,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/server-ux",
"depends": ["base"],
"data": [],
"demo": [],
}
1 change: 1 addition & 0 deletions base_search_multi_value/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import search_multi_value_mixin
40 changes: 40 additions & 0 deletions base_search_multi_value/models/search_multi_value_mixin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright 2024 Akretion
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

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


class SearchMultiValueMixin(models.AbstractModel):

_name = "search.multi.value.mixin"
_description = "Mixin to allow delimiter-separated searches"

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_multi_value(self):
raise NotImplementedError

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_multi_value()
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)
1 change: 1 addition & 0 deletions base_search_multi_value/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Kevin Khao <kevin.khao@akretion.com>
4 changes: 4 additions & 0 deletions base_search_multi_value/readme/CREDITS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
This module is heavily inspired by product_search_multi_value, credits to the creators:

* Cédric PIGEON <cedric.pigeon@acsone.eu>
* Xavier Bouquiaux <xavier.bouquiaux@acsone.eu>
3 changes: 3 additions & 0 deletions base_search_multi_value/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This module allows users to search any arbitrary field using space-separated values.

For example for sale orders you could search: S00001 S00002 S00003 and it would return these three records.
1 change: 1 addition & 0 deletions base_search_multi_value/readme/ROADMAP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* add arbitrary delimiter
1 change: 1 addition & 0 deletions base_search_multi_value/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Inherit search.multi.value.mixin on your model and implement the search fields getter
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 03413c1

Please sign in to comment.