From 3da3ae11783c9ed6bc0634e07089f62ad05c75cb Mon Sep 17 00:00:00 2001 From: Mathieu Duckerts-Antoine Date: Tue, 11 Aug 2020 15:16:32 +0000 Subject: [PATCH] [FIX] web: pivot: avoid to toggle invalid measure Before this commit, click on the divider in the menu 'Measures' of the pivot control panel would cause a crash. The present commit fixes that situation. We also bring another small correction: the menu won't close if one clicks on the measure list but not exactly on a menu item or the divider. closes odoo/odoo#55902 X-original-commit: aad9f3fd7499ef8b660cc25fea840a34d70f75a6 Signed-off-by: Aaron Bohy (aab) Signed-off-by: Mathieu Duckerts-Antoine Co-authored-by: Aaron Bohy Co-authored-by: Mathieu Duckerts-Antoine --- .../src/js/views/pivot/pivot_controller.js | 2 +- addons/web/static/tests/views/pivot_tests.js | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/js/views/pivot/pivot_controller.js b/addons/web/static/src/js/views/pivot/pivot_controller.js index 723d52aa25c..1138778156a 100644 --- a/addons/web/static/src/js/views/pivot/pivot_controller.js +++ b/addons/web/static/src/js/views/pivot/pivot_controller.js @@ -173,7 +173,7 @@ odoo.define('web.PivotController', function (require) { if (ev.target.closest('.o_pivot_measures_list')) { ev.preventDefault(); ev.stopPropagation(); - const field = $target.data('field'); + const field = ev.target.dataset.field; if (field) { this.update({ measure: field }); } diff --git a/addons/web/static/tests/views/pivot_tests.js b/addons/web/static/tests/views/pivot_tests.js index 6fd8aaf4e92..ebcd2b69902 100644 --- a/addons/web/static/tests/views/pivot_tests.js +++ b/addons/web/static/tests/views/pivot_tests.js @@ -2333,6 +2333,32 @@ QUnit.module('Views', { pivot.destroy(); }); + QUnit.test('Click on the measure list but not on a menu item', async function (assert) { + assert.expect(2); + + const pivot = await createView({ + View: PivotView, + model: "partner", + data: this.data, + arch: ``, + }); + + // open the "Measures" menu + await testUtils.dom.click(pivot.el.querySelector('.o_cp_buttons button')); + + // click on the divider in the "Measures" menu does not crash + await testUtils.dom.click(pivot.el.querySelector('.o_pivot_measures_list .dropdown-divider')); + // the menu should still be open + assert.isVisible(pivot.el.querySelector('.o_pivot_measures_list')); + + // click on the measure list but not on a menu item or the separator + await testUtils.dom.click(pivot.el.querySelector('.o_pivot_measures_list')); + // the menu should still be open + assert.isVisible(pivot.el.querySelector('.o_pivot_measures_list')); + + pivot.destroy(); + }); + QUnit.test('Navigation list view for a group and back with breadcrumbs', async function (assert) { assert.expect(16); // create an action manager to test the interactions with the search view