diff --git a/attribute_set_searchable/README.rst b/attribute_set_searchable/README.rst new file mode 100644 index 00000000..a13a7eba --- /dev/null +++ b/attribute_set_searchable/README.rst @@ -0,0 +1,80 @@ +======================== +Attribute Set Searchable +======================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/14.0/attribute_set_searchable + :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-14-0/odoo-pim-14-0-attribute_set_searchable + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/295/14.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows the user to make an attribute searchable directly from the search view of the related model. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +On the attribute, tick the check box 'Searchable' and refresh your browser. +Open the search view linked to the related model and begin to type, the attribute is now available. + +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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* ACSONE SA/NV + +Contributors +~~~~~~~~~~~~ + +* Cédric PIGEON +* Dhara Solanki + +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 `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/attribute_set_searchable/__init__.py b/attribute_set_searchable/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/attribute_set_searchable/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/attribute_set_searchable/__manifest__.py b/attribute_set_searchable/__manifest__.py new file mode 100644 index 00000000..c0739830 --- /dev/null +++ b/attribute_set_searchable/__manifest__.py @@ -0,0 +1,14 @@ +# Copyright 2020 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Attribute Set Searchable", + "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": ["attribute_set", "base_search_custom_field_filter"], + "data": ["views/attribute_attribute.xml"], + "demo": [], + "installable": True, +} diff --git a/attribute_set_searchable/i18n/attribute_set_searchable.pot b/attribute_set_searchable/i18n/attribute_set_searchable.pot new file mode 100644 index 00000000..9ac212e6 --- /dev/null +++ b/attribute_set_searchable/i18n/attribute_set_searchable.pot @@ -0,0 +1,48 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * attribute_set_searchable +# +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: attribute_set_searchable +#: model:ir.model,name:attribute_set_searchable.model_attribute_attribute +#: model:ir.model.fields,field_description:attribute_set_searchable.field_ir_ui_custom_field_filter__attribute_id +msgid "Attribute" +msgstr "" + +#. module: attribute_set_searchable +#: model:ir.model,name:attribute_set_searchable.model_ir_ui_custom_field_filter +msgid "Custom UI field filter" +msgstr "" + +#. module: attribute_set_searchable +#: model:ir.model.fields,field_description:attribute_set_searchable.field_attribute_attribute__display_name +#: model:ir.model.fields,field_description:attribute_set_searchable.field_ir_ui_custom_field_filter__display_name +msgid "Display Name" +msgstr "" + +#. module: attribute_set_searchable +#: model:ir.model.fields,field_description:attribute_set_searchable.field_attribute_attribute__id +#: model:ir.model.fields,field_description:attribute_set_searchable.field_ir_ui_custom_field_filter__id +msgid "ID" +msgstr "" + +#. module: attribute_set_searchable +#: model:ir.model.fields,field_description:attribute_set_searchable.field_attribute_attribute____last_update +#: model:ir.model.fields,field_description:attribute_set_searchable.field_ir_ui_custom_field_filter____last_update +msgid "Last Modified on" +msgstr "" + +#. module: attribute_set_searchable +#: model:ir.model.fields,field_description:attribute_set_searchable.field_attribute_attribute__searchable +msgid "Searchable" +msgstr "" diff --git a/attribute_set_searchable/models/__init__.py b/attribute_set_searchable/models/__init__.py new file mode 100644 index 00000000..03c1fe64 --- /dev/null +++ b/attribute_set_searchable/models/__init__.py @@ -0,0 +1,2 @@ +from . import attribute_attribute +from . import ir_ui_custom_field_filter diff --git a/attribute_set_searchable/models/attribute_attribute.py b/attribute_set_searchable/models/attribute_attribute.py new file mode 100644 index 00000000..25fcf5fa --- /dev/null +++ b/attribute_set_searchable/models/attribute_attribute.py @@ -0,0 +1,66 @@ +# Copyright 2020 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class AttributeAttribute(models.Model): + + _inherit = "attribute.attribute" + + searchable = fields.Boolean(default=False) + + def _get_custom_filter(self): + self.ensure_one() + return self.env["ir.ui.custom.field.filter"].search( + [("attribute_id", "=", self.id)] + ) + + def _prepare_create_custom_filter(self): + self.ensure_one() + model_id = self.attribute_group_id.model_id + return { + "model_id": model_id.id, + "name": self.field_description, + "expression": self.name, + "sequence": self.sequence, + "attribute_id": self.id, + } + + def _create_custom_filter(self): + data = self._prepare_create_custom_filter() + return self.env["ir.ui.custom.field.filter"].create(data) + + def _update_custom_filter(self, custom_filter): + self.ensure_one() + data = {} + if custom_filter.name != self.field_description: + data.update({"name": self.field_description}) + if custom_filter.expression != self.name: + data.update({"expression": self.name}) + if custom_filter.sequence != self.sequence: + data.update({"sequence": self.sequence}) + if data: + custom_filter.write(data) + + def write(self, vals): + res = super(AttributeAttribute, self).write(vals) + for attribute in self: + custom_filter = self._get_custom_filter() + if attribute.searchable: + if not custom_filter: + self._create_custom_filter() + else: + self._update_custom_filter(custom_filter) + elif custom_filter: + custom_filter.unlink() + return res + + @api.model_create_multi + @api.returns("self", lambda value: value.id) + def create(self, vals_list): + attributes = super(AttributeAttribute, self).create(vals_list) + search_attributes = attributes.filtered(lambda att: att.searchable) + for attribute in search_attributes: + attribute._create_custom_filter() + return attributes diff --git a/attribute_set_searchable/models/ir_ui_custom_field_filter.py b/attribute_set_searchable/models/ir_ui_custom_field_filter.py new file mode 100644 index 00000000..311b6fc1 --- /dev/null +++ b/attribute_set_searchable/models/ir_ui_custom_field_filter.py @@ -0,0 +1,11 @@ +# Copyright 2020 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class IrUiCustomFieldFilter(models.Model): + + _inherit = "ir.ui.custom.field.filter" + + attribute_id = fields.Many2one("attribute.attribute", ondelete="cascade") diff --git a/attribute_set_searchable/readme/CONTRIBUTORS.rst b/attribute_set_searchable/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..6c859331 --- /dev/null +++ b/attribute_set_searchable/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Cédric PIGEON +* Dhara Solanki diff --git a/attribute_set_searchable/readme/DESCRIPTION.rst b/attribute_set_searchable/readme/DESCRIPTION.rst new file mode 100644 index 00000000..98f4105d --- /dev/null +++ b/attribute_set_searchable/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module allows the user to make an attribute searchable directly from the search view of the related model. diff --git a/attribute_set_searchable/readme/USAGE.rst b/attribute_set_searchable/readme/USAGE.rst new file mode 100644 index 00000000..b92db57e --- /dev/null +++ b/attribute_set_searchable/readme/USAGE.rst @@ -0,0 +1,2 @@ +On the attribute, thick the check box 'Searchable' and refresh your browser. +Open the search view linked to the related model and begin to type, the attribute is now available. diff --git a/attribute_set_searchable/static/description/icon.png b/attribute_set_searchable/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/attribute_set_searchable/static/description/icon.png differ diff --git a/attribute_set_searchable/static/description/index.html b/attribute_set_searchable/static/description/index.html new file mode 100644 index 00000000..e561931e --- /dev/null +++ b/attribute_set_searchable/static/description/index.html @@ -0,0 +1,425 @@ + + + + + + +Attribute Set Searchable + + + +
+

Attribute Set Searchable

+ + +

Beta License: AGPL-3 OCA/odoo-pim Translate me on Weblate Try me on Runbot

+

This module allows the user to make an attribute searchable directly from the search view of the related model.

+

Table of contents

+ +
+

Usage

+

On the attribute, thick the check box ‘Searchable’ and refresh your browser. +Open the search view linked to the related model and begin to type, the attribute is now available.

+
+
+

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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • ACSONE SA/NV
  • +
+
+
+

Contributors

+ +
+
+

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/odoo-pim project on GitHub.

+

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

+
+
+
+ + diff --git a/attribute_set_searchable/tests/__init__.py b/attribute_set_searchable/tests/__init__.py new file mode 100644 index 00000000..2a070419 --- /dev/null +++ b/attribute_set_searchable/tests/__init__.py @@ -0,0 +1 @@ +from . import test_attribute_set_searchable diff --git a/attribute_set_searchable/tests/test_attribute_set_searchable.py b/attribute_set_searchable/tests/test_attribute_set_searchable.py new file mode 100644 index 00000000..975ca0b8 --- /dev/null +++ b/attribute_set_searchable/tests/test_attribute_set_searchable.py @@ -0,0 +1,58 @@ +# Copyright 2020 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.tests.common import TransactionCase + + +class TestAttributeSetSearchable(TransactionCase): + def setUp(self): + super(TestAttributeSetSearchable, self).setUp() + self.model_id = self.env.ref("base.model_res_partner").id + self.group = self.env["attribute.group"].create( + {"name": "My Group", "model_id": self.model_id} + ) + self.vals = { + "nature": "custom", + "model_id": self.model_id, + "attribute_type": "char", + "field_description": "Attribute test", + "name": "x_test", + "attribute_group_id": self.group.id, + } + + self.attr = self.env["attribute.attribute"].create(self.vals) + + def _get_filter(self, forced_attr=False): + attr = forced_attr or self.attr + filter_obj = self.env["ir.ui.custom.field.filter"] + return filter_obj.search([("attribute_id", "=", attr.id)]) + + def test_attr_searchable(self): + custom_filter = self._get_filter() + self.assertFalse(custom_filter) + self.attr.searchable = True + custom_filter = self._get_filter() + self.assertTrue(custom_filter) + self.assertEqual(custom_filter.model_id.id, self.model_id) + self.assertEqual(custom_filter.name, self.attr.field_description) + self.assertEqual(custom_filter.expression, self.attr.name) + self.assertEqual(custom_filter.sequence, self.attr.sequence) + self.attr.searchable = False + custom_filter = self._get_filter() + self.assertFalse(custom_filter) + + def test_attr_unlink(self): + custom_filter = self._get_filter() + self.assertFalse(custom_filter) + self.attr.searchable = True + custom_filter = self._get_filter() + self.assertTrue(custom_filter) + self.attr.unlink() + self.assertFalse(custom_filter.exists()) + + def test_attr_create(self): + vals = self.vals.copy() + vals.update({"searchable": True, "name": "x_test2"}) + attr = self.env["attribute.attribute"].create(vals) + custom_filter = self._get_filter(forced_attr=attr) + self.assertTrue(custom_filter) diff --git a/attribute_set_searchable/views/attribute_attribute.xml b/attribute_set_searchable/views/attribute_attribute.xml new file mode 100644 index 00000000..a35bbe4d --- /dev/null +++ b/attribute_set_searchable/views/attribute_attribute.xml @@ -0,0 +1,15 @@ + + + + + attribute.attribute.form (in attribut_set_searchable) + attribute.attribute + + + + + + + + diff --git a/setup/attribute_set_searchable/odoo/addons/attribute_set_searchable b/setup/attribute_set_searchable/odoo/addons/attribute_set_searchable new file mode 120000 index 00000000..5fa61c1c --- /dev/null +++ b/setup/attribute_set_searchable/odoo/addons/attribute_set_searchable @@ -0,0 +1 @@ +../../../../attribute_set_searchable \ No newline at end of file diff --git a/setup/attribute_set_searchable/setup.py b/setup/attribute_set_searchable/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/attribute_set_searchable/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)