diff --git a/base_custom_filter/README.rst b/base_custom_filter/README.rst new file mode 100644 index 0000000000..9d9452bff3 --- /dev/null +++ b/base_custom_filter/README.rst @@ -0,0 +1,115 @@ +============================================================= +Add custom filters in standard filters and group by dropdowns +============================================================= + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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%2Fserver--ux-lightgray.png?logo=github + :target: https://github.com/OCA/server-ux/tree/16.0/base_custom_filter + :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_custom_filter + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/250/16.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows to define custom filters to be shown under the standard +filters and group by menus of a model's search view. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +#. Go to *Settings > Custom Filters*. +#. Create a new Custom Filter, and define following information: + + * The **Model** for which you are defining the filter. + * The **Type** depending on whether you want to add a filter or a grouping by + by a field. + * The **Domain** that will be applied with the filter. + * The **Group By Field** used to perform the group by. + * The **Group** to have filters under the same separator. + +#. You can reorder records from the list view with the arrow handle. This will + determine the order in which they appear in the filters/groupby menu. +#. A separator is added between each custom filter added. You can create Custom + Filter Groups to group filters that you want to have displayed under the same + separator. + +Usage +===== + +#. Go to the model's menu entry for which you have defined the filter. +#. On the filters and group by dropdowns, you will see the configured filters. + +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 +~~~~~~~ + +* Ashish Hirpara +* ForgeFlow + +Contributors +~~~~~~~~~~~~ + +* `ForgeFlow S.L. `_: + + * Jordi Masvidal + +* `Ashish Hirpara ` + +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-AshishHirapara| image:: https://github.com/AshishHirapara.png?size=40px + :target: https://github.com/AshishHirapara + :alt: AshishHirapara +.. |maintainer-ForgeFlow| image:: https://github.com/ForgeFlow.png?size=40px + :target: https://github.com/ForgeFlow + :alt: ForgeFlow + +Current `maintainers `__: + +|maintainer-AshishHirapara| |maintainer-ForgeFlow| + +This module is part of the `OCA/server-ux `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/base_custom_filter/__init__.py b/base_custom_filter/__init__.py new file mode 100644 index 0000000000..c32fd62b78 --- /dev/null +++ b/base_custom_filter/__init__.py @@ -0,0 +1,2 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from . import models diff --git a/base_custom_filter/__manifest__.py b/base_custom_filter/__manifest__.py new file mode 100644 index 0000000000..3375ce55aa --- /dev/null +++ b/base_custom_filter/__manifest__.py @@ -0,0 +1,19 @@ +# Migrated to v14.0 by Ashish Hirpara (https://www.ashish-hirpara.com) +# Copyright 2021 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + "name": "Add custom filters in standard filters and group by dropdowns", + "version": "16.0.1.0.0", + "category": "Usability", + "website": "https://github.com/OCA/server-ux", + "author": "Ashish Hirpara, ForgeFlow, Odoo Community Association (OCA)", + "data": [ + "security/ir.model.access.csv", + "views/ir_filters_views.xml", + "views/ir_filters_group_views.xml", + ], + "depends": ["web"], + "license": "AGPL-3", + "installable": True, + "maintainers": ["AshishHirapara", "ForgeFlow"], +} diff --git a/base_custom_filter/i18n/base_custom_filter.pot b/base_custom_filter/i18n/base_custom_filter.pot new file mode 100644 index 0000000000..f73e5c971d --- /dev/null +++ b/base_custom_filter/i18n/base_custom_filter.pot @@ -0,0 +1,129 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_custom_filter +# +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_custom_filter +#: model:ir.model,name:base_custom_filter.model_base +msgid "Base" +msgstr "" + +#. module: base_custom_filter +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters_group__create_uid +msgid "Created by" +msgstr "" + +#. module: base_custom_filter +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters_group__create_date +msgid "Created on" +msgstr "" + +#. module: base_custom_filter +#: model:ir.actions.act_window,name:base_custom_filter.action_ir_filters_group +#: model:ir.ui.menu,name:base_custom_filter.menu_ir_filters_group +msgid "Custom Filter Groups" +msgstr "" + +#. module: base_custom_filter +#: model:ir.actions.act_window,name:base_custom_filter.action_ir_custom_filter +#: model:ir.ui.menu,name:base_custom_filter.menu_base_custom_filter +#: model:ir.ui.menu,name:base_custom_filter.menu_ir_custom_filter +msgid "Custom Filters" +msgstr "" + +#. module: base_custom_filter +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters__display_name +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters_group__display_name +msgid "Display Name" +msgstr "" + +#. module: base_custom_filter +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters__group_id +msgid "Filter Group" +msgstr "" + +#. module: base_custom_filter +#: model:ir.model,name:base_custom_filter.model_ir_filters +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters_group__filter_ids +msgid "Filters" +msgstr "" + +#. module: base_custom_filter +#: model:ir.model,name:base_custom_filter.model_ir_filters_group +msgid "Filters Group" +msgstr "" + +#. module: base_custom_filter +#: model_terms:ir.ui.view,arch_db:base_custom_filter.search_ir_filters_group +msgid "Group By" +msgstr "" + +#. module: base_custom_filter +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters__groupby_field +msgid "Group By Field" +msgstr "" + +#. module: base_custom_filter +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters__id +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters_group__id +msgid "ID" +msgstr "" + +#. module: base_custom_filter +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters____last_update +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters_group____last_update +msgid "Last Modified on" +msgstr "" + +#. module: base_custom_filter +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters_group__write_uid +msgid "Last Updated by" +msgstr "" + +#. module: base_custom_filter +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters_group__write_date +msgid "Last Updated on" +msgstr "" + +#. module: base_custom_filter +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters_group__model_id +msgid "Model" +msgstr "" + +#. module: base_custom_filter +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters_group__name +msgid "Name" +msgstr "" + +#. module: base_custom_filter +#: model_terms:ir.ui.view,arch_db:base_custom_filter.search_ir_filters_group +msgid "Search Filters Group" +msgstr "" + +#. module: base_custom_filter +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters__sequence +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters_group__sequence +msgid "Sequence" +msgstr "" + +#. module: base_custom_filter +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters__type +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters_group__type +#: model_terms:ir.ui.view,arch_db:base_custom_filter.search_ir_filters_group +msgid "Type" +msgstr "" + +#. module: base_custom_filter +#: model_terms:ir.ui.view,arch_db:base_custom_filter.search_ir_filters_group +msgid "Without Filters" +msgstr "" diff --git a/base_custom_filter/i18n/fr.po b/base_custom_filter/i18n/fr.po new file mode 100644 index 0000000000..be28af67fb --- /dev/null +++ b/base_custom_filter/i18n/fr.po @@ -0,0 +1,130 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_custom_filter +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: Automatically generated\n" +"Language-Team: none\n" +"Language: fr\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" + +#. module: base_custom_filter +#: model:ir.model,name:base_custom_filter.model_base +msgid "Base" +msgstr "" + +#. module: base_custom_filter +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters_group__create_uid +msgid "Created by" +msgstr "" + +#. module: base_custom_filter +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters_group__create_date +msgid "Created on" +msgstr "" + +#. module: base_custom_filter +#: model:ir.actions.act_window,name:base_custom_filter.action_ir_filters_group +#: model:ir.ui.menu,name:base_custom_filter.menu_ir_filters_group +msgid "Custom Filter Groups" +msgstr "" + +#. module: base_custom_filter +#: model:ir.actions.act_window,name:base_custom_filter.action_ir_custom_filter +#: model:ir.ui.menu,name:base_custom_filter.menu_base_custom_filter +#: model:ir.ui.menu,name:base_custom_filter.menu_ir_custom_filter +msgid "Custom Filters" +msgstr "" + +#. module: base_custom_filter +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters__display_name +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters_group__display_name +msgid "Display Name" +msgstr "" + +#. module: base_custom_filter +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters__group_id +msgid "Filter Group" +msgstr "" + +#. module: base_custom_filter +#: model:ir.model,name:base_custom_filter.model_ir_filters +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters_group__filter_ids +msgid "Filters" +msgstr "" + +#. module: base_custom_filter +#: model:ir.model,name:base_custom_filter.model_ir_filters_group +msgid "Filters Group" +msgstr "" + +#. module: base_custom_filter +#: model_terms:ir.ui.view,arch_db:base_custom_filter.search_ir_filters_group +msgid "Group By" +msgstr "" + +#. module: base_custom_filter +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters__groupby_field +msgid "Group By Field" +msgstr "" + +#. module: base_custom_filter +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters__id +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters_group__id +msgid "ID" +msgstr "" + +#. module: base_custom_filter +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters____last_update +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters_group____last_update +msgid "Last Modified on" +msgstr "" + +#. module: base_custom_filter +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters_group__write_uid +msgid "Last Updated by" +msgstr "" + +#. module: base_custom_filter +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters_group__write_date +msgid "Last Updated on" +msgstr "" + +#. module: base_custom_filter +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters_group__model_id +msgid "Model" +msgstr "" + +#. module: base_custom_filter +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters_group__name +msgid "Name" +msgstr "" + +#. module: base_custom_filter +#: model_terms:ir.ui.view,arch_db:base_custom_filter.search_ir_filters_group +msgid "Search Filters Group" +msgstr "" + +#. module: base_custom_filter +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters__sequence +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters_group__sequence +msgid "Sequence" +msgstr "" + +#. module: base_custom_filter +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters__type +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters_group__type +#: model_terms:ir.ui.view,arch_db:base_custom_filter.search_ir_filters_group +msgid "Type" +msgstr "" + +#. module: base_custom_filter +#: model_terms:ir.ui.view,arch_db:base_custom_filter.search_ir_filters_group +msgid "Without Filters" +msgstr "" diff --git a/base_custom_filter/i18n/it.po b/base_custom_filter/i18n/it.po new file mode 100644 index 0000000000..7570238baa --- /dev/null +++ b/base_custom_filter/i18n/it.po @@ -0,0 +1,132 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_custom_filter +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2022-04-13 16:05+0000\n" +"Last-Translator: Francesco Foresti \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 4.3.2\n" + +#. module: base_custom_filter +#: model:ir.model,name:base_custom_filter.model_base +msgid "Base" +msgstr "Base" + +#. module: base_custom_filter +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters_group__create_uid +msgid "Created by" +msgstr "Creato da" + +#. module: base_custom_filter +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters_group__create_date +msgid "Created on" +msgstr "Creato il" + +#. module: base_custom_filter +#: model:ir.actions.act_window,name:base_custom_filter.action_ir_filters_group +#: model:ir.ui.menu,name:base_custom_filter.menu_ir_filters_group +msgid "Custom Filter Groups" +msgstr "Gruppi Filtri Personalizzati" + +#. module: base_custom_filter +#: model:ir.actions.act_window,name:base_custom_filter.action_ir_custom_filter +#: model:ir.ui.menu,name:base_custom_filter.menu_base_custom_filter +#: model:ir.ui.menu,name:base_custom_filter.menu_ir_custom_filter +msgid "Custom Filters" +msgstr "Filtri Personalizzati" + +#. module: base_custom_filter +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters__display_name +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters_group__display_name +msgid "Display Name" +msgstr "Nome Visualizzato" + +#. module: base_custom_filter +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters__group_id +msgid "Filter Group" +msgstr "Gruppo filtro" + +#. module: base_custom_filter +#: model:ir.model,name:base_custom_filter.model_ir_filters +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters_group__filter_ids +msgid "Filters" +msgstr "Filtri" + +#. module: base_custom_filter +#: model:ir.model,name:base_custom_filter.model_ir_filters_group +msgid "Filters Group" +msgstr "Gruppo Filtri" + +#. module: base_custom_filter +#: model_terms:ir.ui.view,arch_db:base_custom_filter.search_ir_filters_group +msgid "Group By" +msgstr "Raggruppa Per" + +#. module: base_custom_filter +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters__groupby_field +msgid "Group By Field" +msgstr "Raggruppa per campo" + +#. module: base_custom_filter +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters__id +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters_group__id +msgid "ID" +msgstr "ID" + +#. module: base_custom_filter +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters____last_update +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters_group____last_update +msgid "Last Modified on" +msgstr "Ultima modifica il" + +#. module: base_custom_filter +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters_group__write_uid +msgid "Last Updated by" +msgstr "Ultimo aggiornamento di" + +#. module: base_custom_filter +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters_group__write_date +msgid "Last Updated on" +msgstr "Ultimo aggiornamento il" + +#. module: base_custom_filter +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters_group__model_id +msgid "Model" +msgstr "Modello" + +#. module: base_custom_filter +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters_group__name +msgid "Name" +msgstr "Nome" + +#. module: base_custom_filter +#: model_terms:ir.ui.view,arch_db:base_custom_filter.search_ir_filters_group +msgid "Search Filters Group" +msgstr "Cerca gruppo filtri" + +#. module: base_custom_filter +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters__sequence +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters_group__sequence +msgid "Sequence" +msgstr "Sequenza" + +#. module: base_custom_filter +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters__type +#: model:ir.model.fields,field_description:base_custom_filter.field_ir_filters_group__type +#: model_terms:ir.ui.view,arch_db:base_custom_filter.search_ir_filters_group +msgid "Type" +msgstr "Tipo" + +#. module: base_custom_filter +#: model_terms:ir.ui.view,arch_db:base_custom_filter.search_ir_filters_group +msgid "Without Filters" +msgstr "Senza filtri" diff --git a/base_custom_filter/models/__init__.py b/base_custom_filter/models/__init__.py new file mode 100644 index 0000000000..0c10423f0a --- /dev/null +++ b/base_custom_filter/models/__init__.py @@ -0,0 +1,4 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from . import base +from . import ir_filters +from . import ir_filters_group diff --git a/base_custom_filter/models/base.py b/base_custom_filter/models/base.py new file mode 100644 index 0000000000..03a38ff50f --- /dev/null +++ b/base_custom_filter/models/base.py @@ -0,0 +1,110 @@ +# Migrated to v14.0 by Ashish Hirpara (https://www.ashish-hirpara.com) +# Copyright 2021 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from lxml import etree + +from odoo import api, models + + +class Base(models.AbstractModel): + _inherit = "base" + + @api.model + def _add_grouped_filters(self, res, custom_filters): + arch = etree.fromstring(res["arch"]) + node = arch.xpath("//search/filter[last()]") + if node: + node[0].addnext(etree.Element("separator")) + for custom_filter in custom_filters: + node = arch.xpath("//search/separator[last()]") + if node: + elem = etree.Element( + "filter", + { + "name": "ir_custom_filter_%s" % custom_filter.id, + "string": custom_filter.name, + "domain": custom_filter.domain, + }, + ) + node[0].addnext(elem) + res["arch"] = etree.tostring(arch) + return res + + @api.model + def _add_grouped_groupby(self, res, custom_groupbys): + arch = etree.fromstring(res["arch"]) + node = arch.xpath("//group/filter[last()]") + if node: + node[0].addnext(etree.Element("separator")) + for custom_groupby in custom_groupbys: + node = arch.xpath("//group/separator[last()]") + if node: + elem = etree.Element( + "filter", + { + "name": "ir_custom_filter_%s" % custom_groupby.id, + "string": custom_groupby.name, + "context": str( + {"group_by": custom_groupby.groupby_field.name} + ), + }, + ) + node[0].addnext(elem) + res["arch"] = etree.tostring(arch) + return res + + @api.model + def get_view(self, view_id=None, view_type="form", **options): + """Add filters in search views.""" + res = super().get_view(view_id=view_id, view_type=view_type, **options) + if view_type == "search": + filter_groups = self.env["ir.filters.group"].search( + [ + ("model_id", "=", res.get("model")), + ("filter_ids", "!=", False), + ("type", "=", "filter"), + ] + ) + filters_no_group = self.env["ir.filters"].search( + [ + ("model_id", "=", res.get("model")), + ("group_id", "=", False), + ("type", "=", "filter"), + ], + order="sequence desc", + ) + groupby_groups = self.env["ir.filters.group"].search( + [ + ("model_id", "=", res.get("model")), + ("filter_ids", "!=", False), + ("type", "=", "groupby"), + ] + ) + groupbys_no_group = self.env["ir.filters"].search( + [ + ("model_id", "=", res.get("model")), + ("group_id", "=", False), + ("type", "=", "groupby"), + ], + order="sequence desc", + ) + # Add filter type + if filter_groups: + for filter_group in filter_groups: + res = self._add_grouped_filters( + res, filter_group.filter_ids.sorted("sequence", True) + ) + if filters_no_group: + for filter_no_group in filters_no_group: + res = self._add_grouped_filters(res, filter_no_group) + # Add groupby type + if groupby_groups: + for groupby_group in groupby_groups: + res = self._add_grouped_groupby( + res, groupby_group.filter_ids.sorted("sequence", True) + ) + if groupbys_no_group: + for groupby_no_group in groupbys_no_group: + res = self._add_grouped_groupby(res, groupby_no_group) + return res diff --git a/base_custom_filter/models/ir_filters.py b/base_custom_filter/models/ir_filters.py new file mode 100644 index 0000000000..01a7e013e2 --- /dev/null +++ b/base_custom_filter/models/ir_filters.py @@ -0,0 +1,47 @@ +# Migrated to v14.0 by Ashish Hirpara (https://www.ashish-hirpara.com) +# Copyright 2021 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import api, fields, models +from odoo.osv import expression + + +class IrFilters(models.Model): + _inherit = "ir.filters" + _order = "model_id, sequence, name, id desc" + + def _selection_type(self): + return [ + ("favorite", "Favorite"), + ("filter", "Standard Filter"), + ("groupby", "Standard Group By"), + ] + + sequence = fields.Integer() + type = fields.Selection( + selection="_selection_type", + required=True, + default="favorite", + ) + groupby_field = fields.Many2one( + comodel_name="ir.model.fields", + string="Group By Field", + ondelete="cascade", + ) + group_id = fields.Many2one(comodel_name="ir.filters.group", string="Filter Group") + + @api.model + def get_filters(self, model, action_id=None): + """We need to inject a context to obtain only the records of favorite type.""" + self = self.with_context(filter_type="favorite") + return super().get_filters(model, action_id=action_id) + + @api.model + def search(self, args, offset=0, limit=None, order=None, count=False): + if self.env.context.get("filter_type"): + args = expression.AND( + (args, [("type", "=", self.env.context["filter_type"])]) + ) + return super().search( + args, offset=offset, limit=limit, order=order, count=count + ) diff --git a/base_custom_filter/models/ir_filters_group.py b/base_custom_filter/models/ir_filters_group.py new file mode 100644 index 0000000000..710d4e22a7 --- /dev/null +++ b/base_custom_filter/models/ir_filters_group.py @@ -0,0 +1,36 @@ +# Migrated to v14.0 by Ashish Hirpara (https://www.ashish-hirpara.com) +# Copyright 2021 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import api, fields, models + + +class IrFiltersGroup(models.Model): + _name = "ir.filters.group" + _description = "Filters Group" + _order = "sequence, name, id" + + def _selection_type(self): + return [("filter", "Filter"), ("groupby", "Group By")] + + sequence = fields.Integer() + model_id = fields.Selection( + selection="_list_all_models", string="Model", required=True + ) + name = fields.Char(required=True, translate=True) + type = fields.Selection( + selection="_selection_type", + required=True, + default="filter", + ) + filter_ids = fields.One2many( + comodel_name="ir.filters", inverse_name="group_id", string="Filters" + ) + + def unlink(self): + self.filter_ids.unlink() + return super(IrFiltersGroup, self).unlink() + + @api.model + def _list_all_models(self): + return self.env["ir.filters"]._list_all_models() diff --git a/base_custom_filter/readme/CONFIGURE.rst b/base_custom_filter/readme/CONFIGURE.rst new file mode 100644 index 0000000000..35c7aefa0f --- /dev/null +++ b/base_custom_filter/readme/CONFIGURE.rst @@ -0,0 +1,15 @@ +#. Go to *Settings > Custom Filters*. +#. Create a new Custom Filter, and define following information: + + * The **Model** for which you are defining the filter. + * The **Type** depending on whether you want to add a filter or a grouping by + by a field. + * The **Domain** that will be applied with the filter. + * The **Group By Field** used to perform the group by. + * The **Group** to have filters under the same separator. + +#. You can reorder records from the list view with the arrow handle. This will + determine the order in which they appear in the filters/groupby menu. +#. A separator is added between each custom filter added. You can create Custom + Filter Groups to group filters that you want to have displayed under the same + separator. diff --git a/base_custom_filter/readme/CONTRIBUTORS.rst b/base_custom_filter/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..fca6ff5eb6 --- /dev/null +++ b/base_custom_filter/readme/CONTRIBUTORS.rst @@ -0,0 +1,5 @@ +* `ForgeFlow S.L. `_: + + * Jordi Masvidal + +* `Ashish Hirpara ` diff --git a/base_custom_filter/readme/DESCRIPTION.rst b/base_custom_filter/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..5280db8cd0 --- /dev/null +++ b/base_custom_filter/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This module allows to define custom filters to be shown under the standard +filters and group by menus of a model's search view. diff --git a/base_custom_filter/readme/USAGE.rst b/base_custom_filter/readme/USAGE.rst new file mode 100644 index 0000000000..fda3f44d9a --- /dev/null +++ b/base_custom_filter/readme/USAGE.rst @@ -0,0 +1,2 @@ +#. Go to the model's menu entry for which you have defined the filter. +#. On the filters and group by dropdowns, you will see the configured filters. diff --git a/base_custom_filter/security/ir.model.access.csv b/base_custom_filter/security/ir.model.access.csv new file mode 100644 index 0000000000..8aea51cacd --- /dev/null +++ b/base_custom_filter/security/ir.model.access.csv @@ -0,0 +1,3 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_ir_filters_group_user,ir.filters.group,model_ir_filters_group,base.group_user,1,0,0,0 +access_ir_filters_group_system,ir.filters.group,model_ir_filters_group,base.group_system,1,1,1,1 diff --git a/base_custom_filter/static/description/icon.png b/base_custom_filter/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/base_custom_filter/static/description/icon.png differ diff --git a/base_custom_filter/static/description/index.html b/base_custom_filter/static/description/index.html new file mode 100644 index 0000000000..1cc15633d5 --- /dev/null +++ b/base_custom_filter/static/description/index.html @@ -0,0 +1,456 @@ + + + + + + +Add custom filters in standard filters and group by dropdowns + + + +
+

Add custom filters in standard filters and group by dropdowns

+ + +

Beta License: AGPL-3 OCA/server-ux Translate me on Weblate Try me on Runbot

+

This module allows to define custom filters to be shown under the standard +filters and group by menus of a model’s search view.

+

Table of contents

+ +
+

Configuration

+
    +
  1. Go to Settings > Custom Filters.
  2. +
  3. Create a new Custom Filter, and define following information:
      +
    • The Model for which you are defining the filter.
    • +
    • The Type depending on whether you want to add a filter or a grouping by +by a field.
    • +
    • The Domain that will be applied with the filter.
    • +
    • The Group By Field used to perform the group by.
    • +
    • The Group to have filters under the same separator.
    • +
    +
  4. +
  5. You can reorder records from the list view with the arrow handle. This will +determine the order in which they appear in the filters/groupby menu.
  6. +
  7. A separator is added between each custom filter added. You can create Custom +Filter Groups to group filters that you want to have displayed under the same +separator.
  8. +
+
+
+

Usage

+
    +
  1. Go to the model’s menu entry for which you have defined the filter.
  2. +
  3. On the filters and group by dropdowns, you will see the configured filters.
  4. +
+
+
+

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

+
    +
  • Ashish Hirpara
  • +
  • ForgeFlow
  • +
+
+
+

Contributors

+
    +
  • ForgeFlow S.L.:
      +
    • Jordi Masvidal
    • +
    +
  • +
  • Ashish Hirpara <https://www.ashish-hirpara.com>
  • +
+
+
+

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.

+

Current maintainers:

+

AshishHirapara ForgeFlow

+

This module is part of the OCA/server-ux project on GitHub.

+

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

+
+
+
+ + diff --git a/base_custom_filter/tests/__init__.py b/base_custom_filter/tests/__init__.py new file mode 100644 index 0000000000..0a22e05b2c --- /dev/null +++ b/base_custom_filter/tests/__init__.py @@ -0,0 +1 @@ +from . import test_filters diff --git a/base_custom_filter/tests/test_filters.py b/base_custom_filter/tests/test_filters.py new file mode 100644 index 0000000000..24a0db4f51 --- /dev/null +++ b/base_custom_filter/tests/test_filters.py @@ -0,0 +1,67 @@ +from odoo.tests.common import Form, TransactionCase, tagged + + +@tagged("post_install", "-at_install") +class Test(TransactionCase): + @classmethod + def setUpClass(cls, chart_template_ref=None): + super().setUpClass() + filters_obj = cls.env["ir.filters"] + filters_group = Form(filters_obj) + filters_group.name = "Test No groupby group" + filters_group.type = "groupby" + filters_group.model_id = "ir.filters.group" + filters_group.groupby_field = cls.env.ref( + "base_custom_filter.field_ir_filters_group__name" + ) + cls.filters_groupby = filters_group.save() + + filters_group = Form(filters_obj) + filters_group.name = "Test No filters group" + filters_group.type = "filter" + filters_group.model_id = "ir.filters.group" + filters_group.domain = '[["id","=",1]]' + cls.filters_filter = filters_group.save() + + filters_group = Form(filters_obj) + filters_group.name = "Test favorite" + filters_group.type = "favorite" + filters_group.model_id = "ir.filters.group" + filters_group.domain = '[["id","=",1]]' + cls.filters_favorite = filters_group.save() + + def test_filters_favorite(self): + res = self.env["ir.filters"].get_filters("ir.filters.group") + res_ids = [item["id"] for item in res] + self.assertNotIn(self.filters_groupby.id, res_ids) + self.assertNotIn(self.filters_filter.id, res_ids) + self.assertIn(self.filters_favorite.id, res_ids) + + def test_sale_order_line(self): + filters_group_obj = self.env["ir.filters.group"] + filters_obj = self.env["ir.filters"] + filters_obj.unlink() + filters_group_obj.unlink() + with Form(filters_group_obj) as filters_group: + filters_group.name = "Test filters group" + filters_group.type = "filter" + filters_group.model_id = "ir.filters.group" + with filters_group.filter_ids.new() as line: + line.name = "Test filter line" + line.domain = '[["id","=",1]]' + + filter_group = filters_group_obj.search([("name", "=", "Test filters group")]) + self.assertEqual(filter_group.name, "Test filters group") + + with Form(filters_group_obj) as filters_group: + filters_group.name = "Test groupby group" + filters_group.type = "groupby" + filters_group.model_id = "ir.filters.group" + with filters_group.filter_ids.new() as line: + line.name = "Test groupby line" + line.groupby_field = self.env.ref( + "base_custom_filter.field_ir_filters_group__name" + ) + + filters_group_obj.get_view(view_type="search") + filter_group.unlink() diff --git a/base_custom_filter/views/ir_filters_group_views.xml b/base_custom_filter/views/ir_filters_group_views.xml new file mode 100644 index 0000000000..1d382e7b55 --- /dev/null +++ b/base_custom_filter/views/ir_filters_group_views.xml @@ -0,0 +1,114 @@ + + + + + ir.filters.group.form + ir.filters.group + +
+ +
+

+ +

+
+ + + + + + + + + + + + +
+

+ +

+
+ + + + + + +
+ +
+
+
+ +
+
+ + ir.filters.group.tree + ir.filters.group + + + + + + + + + + + search.ir.filters.group + ir.filters.group + + + + + + + + + + + + + + Custom Filter Groups + ir.filters.group + tree,form + + +
diff --git a/base_custom_filter/views/ir_filters_views.xml b/base_custom_filter/views/ir_filters_views.xml new file mode 100644 index 0000000000..871776a7cc --- /dev/null +++ b/base_custom_filter/views/ir_filters_views.xml @@ -0,0 +1,111 @@ + + + + + ir.filters.form - base_custom_filter + ir.filters + + + + + + + + {'invisible': [('type', '=', 'groupby')]} + + + + + + {'invisible': [('type', '!=', 'favorite')]} + + + {'invisible': [('type', '!=', 'favorite')]} + + + {'invisible': [('type', '!=', 'favorite')]} + + + {'invisible': [('type', '!=', 'favorite')]} + + + {'invisible': [('type', '!=', 'favorite')]} + + + + + ir.filters.tree - base_custom_filter + ir.filters + + + + + + + + + + + + + ir.filters.tree.custom + ir.filters + + + + + + + + + + + + + + Custom Filters + ir.filters + [('type', '!=', 'favorite')] + + {'default_type': 'filter'} + + + + diff --git a/setup/base_custom_filter/odoo/addons/base_custom_filter b/setup/base_custom_filter/odoo/addons/base_custom_filter new file mode 120000 index 0000000000..ed9cbda28c --- /dev/null +++ b/setup/base_custom_filter/odoo/addons/base_custom_filter @@ -0,0 +1 @@ +../../../../base_custom_filter \ No newline at end of file diff --git a/setup/base_custom_filter/setup.py b/setup/base_custom_filter/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/base_custom_filter/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)