From 862b21f15623965edb3b287bd3bca6a5f92fd9df Mon Sep 17 00:00:00 2001 From: Mathieu Duckerts-Antoine Date: Wed, 10 Feb 2021 15:17:33 +0000 Subject: [PATCH] [FIX] web: boolean field autocompletion with 'No' Before this commit, select the "No" option of a boolean field in the search bar autocompletion menu would crash. closes odoo/odoo#66058 X-original-commit: ad5d642c455d3215857f25e0d69c593324178d29 Signed-off-by: Aaron Bohy (aab) --- .../static/src/js/control_panel/search_bar.js | 2 +- .../tests/control_panel/search_bar_tests.js | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/addons/web/static/src/js/control_panel/search_bar.js b/addons/web/static/src/js/control_panel/search_bar.js index 0dc8599c4ab..c3f8d1ec4d6 100644 --- a/addons/web/static/src/js/control_panel/search_bar.js +++ b/addons/web/static/src/js/control_panel/search_bar.js @@ -278,7 +278,7 @@ odoo.define('web.SearchBar', function (require) { const labelValue = source.label || this.state.inputValue; this.model.dispatch('addAutoCompletionValues', { filterId: source.filterId, - value: source.value || this._parseWithSource(labelValue, source), + value: "value" in source ? source.value : this._parseWithSource(labelValue, source), label: labelValue, operator: source.filterOperator || source.operator, }); diff --git a/addons/web/static/tests/control_panel/search_bar_tests.js b/addons/web/static/tests/control_panel/search_bar_tests.js index ee28b9f43ce..5eaf2287f8d 100644 --- a/addons/web/static/tests/control_panel/search_bar_tests.js +++ b/addons/web/static/tests/control_panel/search_bar_tests.js @@ -571,8 +571,8 @@ odoo.define('web.search_bar_tests', function (require) { actionManager.destroy(); }); - QUnit.test('autocomplete a boolean value', async function (assert) { - assert.expect(5); + QUnit.test('autocompletion with a boolean field', async function (assert) { + assert.expect(9); this.archs['partner,false,search'] = ''; @@ -598,9 +598,22 @@ odoo.define('web.search_bar_tests', function (require) { // select "Yes" await testUtils.dom.click(actionManager.el.querySelector('.o_searchview_autocomplete li:last-child')); + await cpHelpers.removeFacet(actionManager, 0); + + await cpHelpers.editSearch(actionManager, "No"); + + assert.containsN(actionManager, '.o_searchview_autocomplete li', 2); + assert.strictEqual(actionManager.$('.o_searchview_autocomplete li:last-child').text(), "No"); + + // select "No" + await testUtils.dom.click(actionManager.el.querySelector('.o_searchview_autocomplete li:last-child')); + + assert.verifySteps([ JSON.stringify([]), // initial search JSON.stringify([["bool", "=", true]]), + JSON.stringify([]), + JSON.stringify([["bool", "=", false]]), ]); actionManager.destroy();