Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][mig] attribute_set_searchable: Migration to 16.0 #163

Closed
Closed
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
80 changes: 80 additions & 0 deletions attribute_set_searchable/README.rst
Original file line number Diff line number Diff line change
@@ -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 <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 smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/odoo-pim/issues/new?body=module:%20attribute_set_searchable%0Aversion:%2014.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 <cedric.pigeon@acsone.eu>
* Dhara Solanki <dhara.solanki@initos.com>

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/14.0/attribute_set_searchable>`_ 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 attribute_set_searchable/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
14 changes: 14 additions & 0 deletions attribute_set_searchable/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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,
}
48 changes: 48 additions & 0 deletions attribute_set_searchable/i18n/attribute_set_searchable.pot
Original file line number Diff line number Diff line change
@@ -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 ""
2 changes: 2 additions & 0 deletions attribute_set_searchable/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import attribute_attribute
from . import ir_ui_custom_field_filter
66 changes: 66 additions & 0 deletions attribute_set_searchable/models/attribute_attribute.py
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions attribute_set_searchable/models/ir_ui_custom_field_filter.py
Original file line number Diff line number Diff line change
@@ -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")
2 changes: 2 additions & 0 deletions attribute_set_searchable/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Cédric PIGEON <cedric.pigeon@acsone.eu>
* Dhara Solanki <dhara.solanki@initos.com>
1 change: 1 addition & 0 deletions attribute_set_searchable/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module allows the user to make an attribute searchable directly from the search view of the related model.
2 changes: 2 additions & 0 deletions attribute_set_searchable/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading