From 7aafa205090c558d3d52eb893762c00a70ca307f Mon Sep 17 00:00:00 2001 From: Hardik Prajapati Date: Fri, 10 Jul 2020 09:18:31 +0000 Subject: [PATCH] [FIX] web: list: hide export button when list empty Before this commit, at first rendering, the export button was displayed in the list view even if the list was empty. The issue occurred because at first rendering, the buttons aren't moved inside the control panel yet (this is done in the 'mounted' hook of the control panel). As we render in a fragment, the hook is called later on, when everything is ready and inserted into the DOM. We'll get rid of these painful manipulations as soon as everything will be converted to OWL. Task 2294306 closes odoo/odoo#54307 Signed-off-by: Aaron Bohy (aab) --- .../src/js/views/list/list_controller.js | 4 ++-- addons/web/static/tests/views/list_tests.js | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/addons/web/static/src/js/views/list/list_controller.js b/addons/web/static/src/js/views/list/list_controller.js index 12a3e8c75e1..24dbc4683dd 100644 --- a/addons/web/static/src/js/views/list/list_controller.js +++ b/addons/web/static/src/js/views/list/list_controller.js @@ -174,9 +174,9 @@ var ListController = BasicController.extend({ this.$buttons.toggleClass('o-editing', mode === 'edit'); const state = this.model.get(this.handle, {raw: true}); if (state.count) { - this.$('.o_list_export_xlsx').show(); + this.$buttons.find('.o_list_export_xlsx').show(); } else { - this.$('.o_list_export_xlsx').hide(); + this.$buttons.find('.o_list_export_xlsx').hide(); } } this._updateSelectionBox(); diff --git a/addons/web/static/tests/views/list_tests.js b/addons/web/static/tests/views/list_tests.js index 012ebedec19..6f17ac1e662 100644 --- a/addons/web/static/tests/views/list_tests.js +++ b/addons/web/static/tests/views/list_tests.js @@ -278,6 +278,25 @@ QUnit.module('Views', { list.destroy(); }); + QUnit.test('export button in empty list view', async function (assert) { + assert.expect(2); + + const list = await createView({ + View: ListView, + model: "foo", + data: this.data, + arch: '', + domain: [["id", "<", 0]], // such that no record matches the domain + }); + + assert.isNotVisible(list.el.querySelector('.o_list_export_xlsx')); + + await list.reload({ domain: [['id', '>', 0]] }); + assert.isVisible(list.el.querySelector('.o_list_export_xlsx')); + + list.destroy(); + }); + QUnit.test('list view with adjacent buttons', async function (assert) { assert.expect(2);