diff --git a/web_advanced_search/README.rst b/web_advanced_search/README.rst index 4be970beaf9a..c897866cc69a 100644 --- a/web_advanced_search/README.rst +++ b/web_advanced_search/README.rst @@ -60,6 +60,37 @@ to a journal which has a user who is member of a certain group etc. Note also the domain dialog offers an editable preview in debug mode: .. image:: https://raw.githubusercontent.com/OCA/web/14.0/web_advanced_search/static/img/debug_mode.png +In Selection operator +~~~~~~~~~~~~~~~~~~~~~ + +It is also possible when having selected a relational field to filter on, to +choose for the 'is in selection' operator. This will result in opening a list view for +the related model, where it is possible either to select some records, and then use the +'Select' butto, or to enter filters on the related model, and then click the +'Use Criteria' button. + +Example: select the 'Created By' field to filter Invoices, and then 'is in selection' +as operator: + +.. image:: https://raw.githubusercontent.com/OCA/web/14.0/web_advanced_search/static/img/01-is-in-selection-operator.png + +Then select some records and click on the select button: + +.. image:: https://raw.githubusercontent.com/OCA/web/14.0/web_advanced_search/static/img/02-select-button.png + +Only invoices created by the selected users will be shown: + +.. image:: https://raw.githubusercontent.com/OCA/web/14.0/web_advanced_search/static/img/03-select-result.png + +Another example would be to filter on the invoice partners: + +.. image:: https://raw.githubusercontent.com/OCA/web/14.0/web_advanced_search/static/img/04-use-criteria-button.png + +Now only invoices for partners that are companies, and are in a country with 'Swit' in +the name will be shown: + +.. image:: https://raw.githubusercontent.com/OCA/web/14.0/web_advanced_search/static/img/05-use-criteria-result.png + Known issues / Roadmap ====================== @@ -77,10 +108,22 @@ Improvements to the search view in this addon: Issues: * Grouped totals can show incorrect values. See https://github.com/odoo/odoo/issues/47950 +* DomainSelector Dialog cannot correctly show 'in selection' domains. Changelog ========= +14.0.2.0.0 (2021-09-21) +~~~~~~~~~~~~~~~~~~~~~~~ + +* Restore the 'is in selection' operator. + + The 'is in selection' operator offers a really convenient way to either pick a + selection of related records, or specify criteria / filters to define a domain for + the related records. + + [NL66278] + 11.0.1.0.2 (2018-10-31) ~~~~~~~~~~~~~~~~~~~~~~~ @@ -92,7 +135,6 @@ Changelog [simahawk] - 11.0.1.0.1 (2018-09-18) ~~~~~~~~~~~~~~~~~~~~~~~ @@ -159,6 +201,10 @@ Contributors * Raf Ven +* `Therp BV `_: + + * Ronald Portier + Maintainers ~~~~~~~~~~~ diff --git a/web_advanced_search/__manifest__.py b/web_advanced_search/__manifest__.py index c980699d3e63..b0a0babad180 100644 --- a/web_advanced_search/__manifest__.py +++ b/web_advanced_search/__manifest__.py @@ -1,12 +1,12 @@ -# Copyright 2015 Therp BV +# Copyright 2015-2021 Therp BV # Copyright 2017 Tecnativa - Vicent Cubells # Copyright 2018 Tecnativa - Jairo Llopis -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). { "name": "Advanced search", - "version": "14.0.1.0.1", - "author": "Therp BV, " "Tecnativa, " "Odoo Community Association (OCA)", + "version": "14.0.2.0.0", + "author": "Therp BV, Tecnativa, Odoo Community Association (OCA)", "license": "AGPL-3", "category": "Usability", "summary": "Easier and more powerful searching tools", diff --git a/web_advanced_search/readme/HISTORY.rst b/web_advanced_search/readme/HISTORY.rst index 7b791ed951d7..fac3cdf26234 100644 --- a/web_advanced_search/readme/HISTORY.rst +++ b/web_advanced_search/readme/HISTORY.rst @@ -1,3 +1,14 @@ +14.0.2.0.0 (2021-09-21) +~~~~~~~~~~~~~~~~~~~~~~~ + +* Restore the 'is in selection' operator. + + The 'is in selection' operator offers a really convenient way to either pick a + selection of related records, or specify criteria / filters to define a domain for + the related records. + + [NL66278] + 11.0.1.0.2 (2018-10-31) ~~~~~~~~~~~~~~~~~~~~~~~ @@ -9,7 +20,6 @@ [simahawk] - 11.0.1.0.1 (2018-09-18) ~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/web_advanced_search/readme/ROADMAP.rst b/web_advanced_search/readme/ROADMAP.rst index b71b3c344ff9..b94b432bbfd5 100644 --- a/web_advanced_search/readme/ROADMAP.rst +++ b/web_advanced_search/readme/ROADMAP.rst @@ -12,3 +12,4 @@ Improvements to the search view in this addon: Issues: * Grouped totals can show incorrect values. See https://github.com/odoo/odoo/issues/47950 +* DomainSelector Dialog cannot correctly show 'in selection' domains. diff --git a/web_advanced_search/readme/USAGE.rst b/web_advanced_search/readme/USAGE.rst index 76f224a0d992..6b58f883dd6a 100644 --- a/web_advanced_search/readme/USAGE.rst +++ b/web_advanced_search/readme/USAGE.rst @@ -22,3 +22,34 @@ to a journal which has a user who is member of a certain group etc. Note also the domain dialog offers an editable preview in debug mode: .. image:: ../static/img/debug_mode.png + +In Selection operator +~~~~~~~~~~~~~~~~~~~~~ + +It is also possible when having selected a relational field to filter on, to +choose for the 'is in selection' operator. This will result in opening a list view for +the related model, where it is possible either to select some records, and then use the +'Select' butto, or to enter filters on the related model, and then click the +'Use Criteria' button. + +Example: select the 'Created By' field to filter Invoices, and then 'is in selection' +as operator: + +.. image:: ../static/img/01-is-in-selection-operator.png + +Then select some records and click on the select button: + +.. image:: ../static/img/02-select-button.png + +Only invoices created by the selected users will be shown: + +.. image:: ../static/img/03-select-result.png + +Another example would be to filter on the invoice partners: + +.. image:: ../static/img/04-use-criteria-button.png + +Now only invoices for partners that are companies, and are in a country with 'Swit' in +the name will be shown: + +.. image:: ../static/img/05-use-criteria-result.png diff --git a/web_advanced_search/static/description/index.html b/web_advanced_search/static/description/index.html index 8e653864d240..907a20be6c40 100644 --- a/web_advanced_search/static/description/index.html +++ b/web_advanced_search/static/description/index.html @@ -372,25 +372,29 @@

Advanced search

Table of contents

-

Usage

+

Usage

To use this module, you need to:

  • Open Filters in a search view
  • @@ -417,9 +421,29 @@

    Usage

    https://raw.githubusercontent.com/OCA/web/14.0/web_advanced_search/static/img/debug_mode.png
    +
    +

    In Selection operator

    +

    It is also possible when having selected a relational field to filter on, to +choose for the ‘is in selection’ operator. This will result in opening a list view for +the related model, where it is possible either to select some records, and then use the +‘Select’ butto, or to enter filters on the related model, and then click the +‘Use Criteria’ button.

    +

    Example: select the ‘Created By’ field to filter Invoices, and then ‘is in selection’ +as operator:

    +https://raw.githubusercontent.com/OCA/web/14.0/web_advanced_search/static/img/01-is-in-selection-operator.png +

    Then select some records and click on the select button:

    +https://raw.githubusercontent.com/OCA/web/14.0/web_advanced_search/static/img/02-select-button.png +

    Only invoices created by the selected users will be shown:

    +https://raw.githubusercontent.com/OCA/web/14.0/web_advanced_search/static/img/03-select-result.png +

    Another example would be to filter on the invoice partners:

    +https://raw.githubusercontent.com/OCA/web/14.0/web_advanced_search/static/img/04-use-criteria-button.png +

    Now only invoices for partners that are companies, and are in a country with ‘Swit’ in +the name will be shown:

    +https://raw.githubusercontent.com/OCA/web/14.0/web_advanced_search/static/img/05-use-criteria-result.png +
-

Known issues / Roadmap

+

Known issues / Roadmap

Improvements to the domain widget, not exclusively related to this addon:

-

Changelog

+

Changelog

-

11.0.1.0.2 (2018-10-31)

+

14.0.2.0.0 (2021-09-21)

+
    +
  • Restore the ‘is in selection’ operator.

    +

    The ‘is in selection’ operator offers a really convenient way to either pick a +selection of related records, or specify criteria / filters to define a domain for +the related records.

    +

    [NL66278]

    +
  • +
+
+
+

11.0.1.0.2 (2018-10-31)

  • Fix initialization of 1st domain node

    Sometime the dialog is not ready yet, like on EE version. @@ -449,8 +485,8 @@

    11.0.1.0.2 (2018-10-31)

-
-

11.0.1.0.1 (2018-09-18)

+
+

11.0.1.0.1 (2018-09-18)

  • Fix undefined in x2m fields

    Before this patch, when searching with the “equals to” operator in any @@ -468,8 +504,8 @@

    11.0.1.0.1 (2018-09-18)

-
-

11.0.1.0.0 (2018-07-20)

+
+

11.0.1.0.0 (2018-07-20)

-

Bug Tracker

+

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 @@ -486,16 +522,16 @@

Bug Tracker

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

-

Credits

+

Credits

-

Authors

+

Authors

  • Therp BV
  • Tecnativa
-

Contributors

+

Contributors

+
  • Therp BV:
      +
    • Ronald Portier
    • +
    +
  • -

    Maintainers

    +

    Maintainers

    This module is maintained by the OCA.

    Odoo Community Association

    OCA, or the Odoo Community Association, is a nonprofit organization whose diff --git a/web_advanced_search/static/img/01-is-in-selection-operator.png b/web_advanced_search/static/img/01-is-in-selection-operator.png new file mode 100644 index 000000000000..6f35685c7802 Binary files /dev/null and b/web_advanced_search/static/img/01-is-in-selection-operator.png differ diff --git a/web_advanced_search/static/img/02-select-button.png b/web_advanced_search/static/img/02-select-button.png new file mode 100644 index 000000000000..0b3781b44b38 Binary files /dev/null and b/web_advanced_search/static/img/02-select-button.png differ diff --git a/web_advanced_search/static/img/03-select-result.png b/web_advanced_search/static/img/03-select-result.png new file mode 100644 index 000000000000..e3e428946c0f Binary files /dev/null and b/web_advanced_search/static/img/03-select-result.png differ diff --git a/web_advanced_search/static/img/04-use-criteria-button.png b/web_advanced_search/static/img/04-use-criteria-button.png new file mode 100644 index 000000000000..d602474f8fc1 Binary files /dev/null and b/web_advanced_search/static/img/04-use-criteria-button.png differ diff --git a/web_advanced_search/static/img/05-use-criteria-result.png b/web_advanced_search/static/img/05-use-criteria-result.png new file mode 100644 index 000000000000..b691b12a5812 Binary files /dev/null and b/web_advanced_search/static/img/05-use-criteria-result.png differ diff --git a/web_advanced_search/static/src/js/control_panel/advanced_select_dialog.js b/web_advanced_search/static/src/js/control_panel/advanced_select_dialog.js index ebcc0f3dbe09..2eccf1543fc9 100644 --- a/web_advanced_search/static/src/js/control_panel/advanced_select_dialog.js +++ b/web_advanced_search/static/src/js/control_panel/advanced_select_dialog.js @@ -2,17 +2,42 @@ odoo.define("web_advanced_search.AdvancedSelectDialog", function (require) { "use strict"; const { _lt, _t } = require("web.core"); - const Context = require("web.Context"); const dialogs = require("web.view_dialogs"); const AdvancedSelectDialog = dialogs.SelectCreateDialog.extend({ /** - * prepare buttons for dialog footer based on options - * - * Fully overide funtion to just show Select and Use Criteria. - * - * @private - */ + * - Prevent dialog from closing when clicking on line. + * - Make sure Use Criteria button only shown when criteria selected. + */ + custom_events: _.extend( + {}, + dialogs.SelectCreateDialog.prototype.custom_events, + { + select_record: function (event) { + event.stopPropagation(); // Do nothing + }, + open_record: function (event) { + event.stopPropagation(); // Do nothing + }, + controller_update: function (event) { + event.stopPropagation(); + if (this.$footer) { + const state = event.data.state; + const domain = state.getDomain(); + let disable_criteria = true; + if (domain && domain.length > 0) { + disable_criteria = false; + } + this.$footer.find( + ".o_use_criteria_button" + ).prop('disabled', disable_criteria); + } + }, + } + ), + /** + * Fully overide function to just show Select and Use Criteria. + */ _prepareButtons: function () { this.__buttons = [ { @@ -23,18 +48,56 @@ odoo.define("web_advanced_search.AdvancedSelectDialog", function (require) { click: function () { const records = this.viewController.getSelectedRecords(); const ids = records.map(record => record.res_id); - const names = records.map(record => record.data.display_name); + // Alternative might be to do somehow name_get for each record. + const names = records.map( + record => ( + record.data.display_name + || record.data.name + || '' + record.res_id + ) + ); + const description = names.join(); this.trigger_up( "domain_selected", - { domain: [['id', 'in', ids]], names: names } + { domain: [['id', 'in', ids]], description: description } ); }, }, { text: _t("Use criteria"), - classes: "btn-primary", - // TODO: get somehow the criteria selected... - click: this.create_edit_record.bind(this) + classes: "btn-primary o_use_criteria_button", + disabled: true, + close: true, + click: function () { + let description = 'Criteria Selected'; + let description_list = []; + const controller = this.viewController; + const state = controller.model.get(controller.handle); + const domain = state.getDomain(); + const es = controller.exportState(); + const sm = JSON.parse(es.searchModel); + if (sm.ControlPanelModelExtension) { + const cp = sm.ControlPanelModelExtension; + if (cp.query && cp.query.length > 0) { + const filters = cp.filters; + const query = cp.query; + let active_filter = 0; + query.forEach(function (query_part) { + active_filter = query_part.filterId; + description_list.push( + filters[active_filter].description + ); + }); + } + } + if (description_list.length > 0) { + description = description_list.join(', '); + } + this.trigger_up( + "domain_selected", + { domain: domain, description: description } + ); + }, }, { text: _t("Cancel"), diff --git a/web_advanced_search/static/src/js/control_panel/advanced_select_list_controller.js b/web_advanced_search/static/src/js/control_panel/advanced_select_list_controller.js new file mode 100644 index 000000000000..dea28b4c6a0f --- /dev/null +++ b/web_advanced_search/static/src/js/control_panel/advanced_select_list_controller.js @@ -0,0 +1,16 @@ +/* Copyright 2021 Therp BV {https://therp.nl>. + * License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + */ +odoo.define("web_advanced_search.select_create_list_controller", function (require) { + "use strict"; + const controller_registry = require('web.select_create_controllers_registry'); + const selectCreateController = controller_registry.SelectCreateListController; + + selectCreateController.include({ + async _update(state, params) { + return this._super(state, params).then( + this.trigger_up('controller_update', { state: state }) + ); + }, + }); +}); diff --git a/web_advanced_search/static/src/js/control_panel/custom_filter_item.js b/web_advanced_search/static/src/js/control_panel/custom_filter_item.js index 7f0e7b7d0f35..a18fbfcc4398 100644 --- a/web_advanced_search/static/src/js/control_panel/custom_filter_item.js +++ b/web_advanced_search/static/src/js/control_panel/custom_filter_item.js @@ -18,9 +18,14 @@ odoo.define("web_advanced_search.CustomFilterItem", function (require) { this.state.field = false; this.OPERATORS.relational = this.OPERATORS.char; this.FIELD_TYPES.many2one = "relational"; - this.OPERATORS.relational.push( - { symbol: "domain", description: _lt("is in selection") } - ); + // Add 'is in selection' operator if not present already. + if (!this.OPERATORS.relational.some( + operator => operator.symbol === 'domain') + ) { + this.OPERATORS.relational.push( + { symbol: "domain", description: _lt("is in selection") } + ); + } useListener("m2xchange", this._onM2xDataChanged); } @@ -147,12 +152,29 @@ odoo.define("web_advanced_search.CustomFilterItem", function (require) { no_create: true, }; const select_dialog = new dialogs.AdvancedSelectDialog(this, options); - select_dialog.on("domain_selected", this, function (e) { - const domain = e.data.domain; - domain[0][0] = this.state.field.name; + select_dialog.on("domain_selected", this, function (event) { + event.stopPropagation(); + const domain = event.data.domain; + const fieldname = this.state.field.name; + let first_term = ''; + // Add fieldname to all fields to create qualified name, + // e.g. [['country_id', 'like', 'United']] will become + // [['partner_id.country_id', 'like', 'United']] when Partner must + // be in selection. + domain.forEach(function(part) { + if (part.length === 3) { + // This is a proper tuple + first_term = part[0]; + part[0] = fieldname + '.' + first_term; + } + }); const preFilter = { - description: e.data.names.join(), - domain: Domain.prototype.arrayToString(e.data.domain), + description: ( + this.state.field.description + + ': ' + + event.data.description + ), + domain: Domain.prototype.arrayToString(domain), type: "filter", }; this.model.dispatch("createNewFilters", [preFilter]); diff --git a/web_advanced_search/static/src/js/widget/domain_leaf.js b/web_advanced_search/static/src/js/widget/domain_leaf.js new file mode 100644 index 000000000000..2c264e834bf0 --- /dev/null +++ b/web_advanced_search/static/src/js/widget/domain_leaf.js @@ -0,0 +1,33 @@ +/* Copyright 2021 Therp BV . + * License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + */ +odoo.define("web_advanced_search.domain_leaf", function (require) { + "use strict"; + + const DomainLeaf = require("web.DomainSelector"); + FormController.include({ + async _update(state, params) { + return this._super(state, params).then(this.show_hide_buttons(state)); + }, + show_hide_buttons: function (state) { + var self = this; + return self + ._rpc({ + model: this.modelName, + method: "check_access_rule_all", + args: [[state.data.id], ["write"]], + }) + .then(function (accesses) { + self.show_hide_edit_button(accesses.write); + }); + }, + show_hide_edit_button: function (access) { + if (this.$buttons) { + var button = this.$buttons.find(".o_form_button_edit"); + if (button) { + button.prop("disabled", !access); + } + } + }, + }); +}); diff --git a/web_advanced_search/views/templates.xml b/web_advanced_search/views/templates.xml index c0b135e56b9d..77f659cc15c8 100644 --- a/web_advanced_search/views/templates.xml +++ b/web_advanced_search/views/templates.xml @@ -9,6 +9,10 @@ type="text/javascript" src="/web_advanced_search/static/src/js/control_panel/advanced_filter_item.js" /> +