diff options
| author | Lucas Lefèvre <lul@odoo.com> | 2019-09-18 12:06:42 +0200 |
|---|---|---|
| committer | Yannick Tivisse <yti@odoo.com> | 2019-09-20 16:18:35 +0200 |
| commit | 5c4544fb2943e63fc1e0f5ae1e7e250a5a2b2cf1 (patch) | |
| tree | b7a9df3d595a8a28632535dc343f8cab1b1bf3cb /addons/web/static/tests/widgets | |
| parent | 2849b5cb395175c286ddebc269c7b16e7f97e9e6 (diff) | |
[IMP] web: Export grouped list view in xls file
PURPOSE
=======
Add the support of grouped exports.
Allow the user to export all records in one click from
the listview, without having to go through the export modal,
taking into account the domain, groupbys, and visible fields.
SPECIFICATION
=============
When exporting (whether it is from the modal or from the shortcut),
any groupby(s) set on the listview should be taken into account (all unfolded)
- UNLESS the export is import-compatible
- each subgroup header has an indentation compared to its parent
- the 'group headers' in the exported file should contain the
same info (label, field aggregates) as it has in the listview.
New secondary button on the tree view with label 'EXPORT' (to be confirmed...)
- the export shortcut disregard the selected records, it exports all records
according to the domain.
- the button is visible even if there is no selected records.
- essentially the export shortcut does the same thing as the following:
- select all records
- hit 'action' then 'export'
- hit 'export'
Define a boolean attribute on <tree> to specify whether or not the export shortcut should be displayed
Task 2072910
Diffstat (limited to 'addons/web/static/tests/widgets')
| -rw-r--r-- | addons/web/static/tests/widgets/data_export_tests.js | 116 |
1 files changed, 114 insertions, 2 deletions
diff --git a/addons/web/static/tests/widgets/data_export_tests.js b/addons/web/static/tests/widgets/data_export_tests.js index 6d29e8e888d..c9c51219571 100644 --- a/addons/web/static/tests/widgets/data_export_tests.js +++ b/addons/web/static/tests/widgets/data_export_tests.js @@ -14,12 +14,22 @@ QUnit.module('widgets', { partner: { fields: { foo: {string: "Foo", type: "char"}, + bar: {string: "Bar", type: "char"}, }, records: [ { id: 1, foo: "yop", - }, + bar: "bar-blup", + }, { + id: 2, + foo: "yop", + bar: "bar-yop", + }, { + id: 3, + foo: "blup", + bar: "bar-blup", + } ] }, 'ir.exports': { @@ -239,7 +249,7 @@ QUnit.module('widgets', { }, }); // Open the export modal - await testUtils.dom.click(list.$('.o_data_row .o_list_record_selector input')); + await testUtils.dom.click(list.$('thead .o_list_record_selector input')); await testUtils.dom.click(list.sidebar.$('.o_dropdown_toggler_btn:contains(Action)')); await testUtils.dom.click(list.sidebar.$('a:contains(Export)')); @@ -257,6 +267,108 @@ QUnit.module('widgets', { assert.strictEqual($('.modal .o_fields_list li').length, 1, "There should be only one field in list"); list.destroy(); }); + + QUnit.test('Direct export button invisible', async function (assert) { + assert.expect(1) + + let list = await createView({ + View: ListView, + model: 'partner', + data: this.data, + arch: `<tree export_xlsx="0"><field name="foo"/></tree>`, + }); + assert.containsNone(list, '.o_list_export_xlsx') + list.destroy(); + }); + + QUnit.test('Direct export list ', async function (assert) { + assert.expect(2) + + let list = await createView({ + View: ListView, + model: 'partner', + data: this.data, + arch: ` + <tree export_xlsx="1"> + <field name="foo"/> + <field name="bar"/> + </tree>`, + domain: [['bar', '!=', 'glou']], + session: { + get_file(args) { + let data = JSON.parse(args.data.data); + assert.strictEqual(args.url, '/web/export/xlsx', "should call get_file with the correct url"); + assert.deepEqual(data, { + context: {}, + model: 'partner', + domain: [['bar', '!=', 'glou']], + groupby: [], + ids: false, + import_compat: false, + fields: [{ + name: 'foo', + label: 'Foo', + }, { + name: 'bar', + label: 'Bar', + }] + }, "should be called with correct params") + args.complete(); + }, + }, + }); + + // 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')); + + list.destroy(); + }); + + QUnit.test('Direct export grouped list ', async function (assert) { + assert.expect(2) + + let list = await createView({ + View: ListView, + model: 'partner', + data: this.data, + debug: true, + arch: ` + <tree> + <field name="foo"/> + <field name="bar"/> + </tree>`, + groupBy: ['foo', 'bar'], + domain: [['bar', '!=', 'glou']], + session: { + get_file(args) { + let data = JSON.parse(args.data.data); + assert.strictEqual(args.url, '/web/export/xlsx', "should call get_file with the correct url"); + assert.deepEqual(data, { + context: {}, + model: 'partner', + domain: [['bar', '!=', 'glou']], + groupby: ['foo', 'bar'], + ids: false, + import_compat: false, + fields: [{ + name: 'foo', + label: 'Foo', + }, { + name: 'bar', + label: 'Bar', + }] + }, "should be called with correct params") + args.complete(); + }, + }, + }); + + await testUtils.dom.click(list.$buttons.find('.o_list_export_xlsx')); + + list.destroy(); + }); }); }); |
