diff --git a/web_advanced_search/__manifest__.py b/web_advanced_search/__manifest__.py index 5f751061e..0ff2a14ed 100644 --- a/web_advanced_search/__manifest__.py +++ b/web_advanced_search/__manifest__.py @@ -1,6 +1,7 @@ # Copyright 2015 Therp BV # Copyright 2017 Tecnativa - Vicent Cubells # Copyright 2018 Tecnativa - Jairo Llopis +# Copyright 2020 Brainbean Apps (https://brainbeanapps.com) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { diff --git a/web_advanced_search/readme/CONTRIBUTORS.rst b/web_advanced_search/readme/CONTRIBUTORS.rst index 89b679a1f..2bdfed063 100644 --- a/web_advanced_search/readme/CONTRIBUTORS.rst +++ b/web_advanced_search/readme/CONTRIBUTORS.rst @@ -5,3 +5,4 @@ * Jose MÂȘ Bernet * Simone Orsi * Dennis Sluijk +* Alexey Pelykh diff --git a/web_advanced_search/readme/ROADMAP.rst b/web_advanced_search/readme/ROADMAP.rst index 8a0a68717..bab0de12a 100644 --- a/web_advanced_search/readme/ROADMAP.rst +++ b/web_advanced_search/readme/ROADMAP.rst @@ -8,3 +8,7 @@ Improvements to the search view in this addon: * Use widgets ``one2many_tags`` when searching ``one2many`` fields * Use widgets ``many2many_tags`` when searching ``many2many`` fields * Allow to edit current full search using the advanced domain editor + +Improvements to the `is child of`/`is parent of` operators: + +* Show the operators only for models with `_parent_store = True` diff --git a/web_advanced_search/readme/USAGE.rst b/web_advanced_search/readme/USAGE.rst index b8e6f2778..9e1ac6d3f 100644 --- a/web_advanced_search/readme/USAGE.rst +++ b/web_advanced_search/readme/USAGE.rst @@ -2,7 +2,8 @@ To use this module, you need to: * Open *Filters* in a search view * Select any relational field -* Select operator `is equal to` or `is not equal to` +* Select one of operators: `is equal to`, `is not equal to`, `is child of`, + or `is parent of` * The text field changes to a relational selection field where you can search for the record in question * Click *Apply* diff --git a/web_advanced_search/static/src/js/web_advanced_search.js b/web_advanced_search/static/src/js/web_advanced_search.js index 571ea6c08..00a488fbd 100644 --- a/web_advanced_search/static/src/js/web_advanced_search.js +++ b/web_advanced_search/static/src/js/web_advanced_search.js @@ -1,5 +1,6 @@ /* Copyright 2015 Therp BV * Copyright 2017-2018 Jairo Llopis + * Copyright 2020 Brainbean Apps (https://brainbeanapps.com) * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ odoo.define("web_advanced_search", function (require) { @@ -16,6 +17,8 @@ odoo.define("web_advanced_search", function (require) { var Widget = require("web.Widget"); var Char = core.search_filters_registry.get("char"); + var _lt = core._lt; + SearchView.include({ custom_events: _.extend({}, SearchView.prototype.custom_events, { "get_dataset": "_on_get_dataset", @@ -153,14 +156,23 @@ odoo.define("web_advanced_search", function (require) { // To make widgets work, we need a model and an empty record FieldManagerMixin.init.call(this); this.trigger_up("get_dataset"); - // Make equal and not equal appear 1st and 2nd + // Unfortunately, it's impossible to check if model supports these + this.operators = this.operators.concat([ + {value: "child_of", text: _lt("is child of")}, + {value: "parent_of", text: _lt("is parent of")} + ]) + // Prioritize equal, not equal, child_of, parent_of this.operators = _.sortBy( this.operators, function (op) { switch (op.value) { case "=": - return -2; + return -4; case "!=": + return -3; + case "child_of": + return -2; + case "parent_of": return -1; default: return 0; @@ -242,6 +254,8 @@ odoo.define("web_advanced_search", function (require) { switch ($operator.val()) { case "=": case "!=": + case "child_of": + case "parent_of": this._field_widget_name = "many2one"; break; default: