From 067e8c88fe12a29fe8d87ba35a892f1c36a01e2e Mon Sep 17 00:00:00 2001
From: pka-odoo <pka@odoo.com>
Date: Mon, 4 May 2020 09:07:20 +0000
Subject: [PATCH] [IMP] web: hide export button when selected records

Part of task 2234547

Co-authored-by: Mohammed Shekha <msh@odoo.com>
Co-authored-by: Aaron Bohy <aab@odoo.com>
---
 .../src/js/views/list/list_controller.js      |  1 +
 addons/web/static/tests/views/list_tests.js   | 24 +++++++++++++++++++
 .../static/tests/widgets/data_export_tests.js |  2 --
 3 files changed, 25 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 5dc5515173ed..110fab8e897c 100644
--- a/addons/web/static/src/js/views/list/list_controller.js
+++ b/addons/web/static/src/js/views/list/list_controller.js
@@ -812,6 +812,7 @@ var ListController = BasicController.extend({
         this.selectedRecords = ev.data.selection;
         this.isPageSelected = ev.data.allChecked;
         this.isDomainSelected = false;
+        this.$('.o_list_export_xlsx').toggle(!this.selectedRecords.length);
         this._updateSelectionBox();
         this._updateControlPanel();
     },
diff --git a/addons/web/static/tests/views/list_tests.js b/addons/web/static/tests/views/list_tests.js
index 985662cf27b5..785b3864e8d9 100644
--- a/addons/web/static/tests/views/list_tests.js
+++ b/addons/web/static/tests/views/list_tests.js
@@ -253,6 +253,30 @@ QUnit.module('Views', {
         list.destroy();
     });
 
+    QUnit.test('export button in list view', async function (assert) {
+        assert.expect(5);
+
+        const list = await createView({
+            View: ListView,
+            model: 'foo',
+            data: this.data,
+            arch: '<tree><field name="foo"/></tree>',
+        });
+
+        assert.containsN(list, '.o_data_row', 4);
+        assert.isVisible(list.$('.o_list_export_xlsx'));
+
+        await testUtils.dom.click(list.$('tbody td.o_list_record_selector:first input'));
+
+        assert.isNotVisible(list.$('.o_list_export_xlsx'));
+        assert.containsOnce(list.$('.o_cp_buttons'), '.o_list_selection_box');
+
+        await testUtils.dom.click(list.$('tbody td.o_list_record_selector:first input'));
+        assert.isVisible(list.$('.o_list_export_xlsx'));
+
+        list.destroy();
+    });
+
     QUnit.test('simple editable rendering', async function (assert) {
         assert.expect(15);
 
diff --git a/addons/web/static/tests/widgets/data_export_tests.js b/addons/web/static/tests/widgets/data_export_tests.js
index 9a6f23b815b2..e7fb9864791c 100644
--- a/addons/web/static/tests/widgets/data_export_tests.js
+++ b/addons/web/static/tests/widgets/data_export_tests.js
@@ -325,8 +325,6 @@ QUnit.module('widgets', {
             },
         });
 
-        // select a record => should not be taken into account
-        await testUtils.dom.click(list.$('.o_data_row .o_list_record_selector input')[0]);
         // Download
         await testUtils.dom.click(list.$buttons.find('.o_list_export_xlsx'));
 
-- 
GitLab