From c3f2638edf679d114e67b3f979f9b74f67c6abc7 Mon Sep 17 00:00:00 2001 From: FrancoisGe Date: Fri, 28 Oct 2022 09:55:59 +0000 Subject: [PATCH] [FIX] web: "export all" exports the columns in the wrong order Before this commit, in the list view, clicking on the "export all" button created an xslx file that did not reproduce the order of the columns in the view. Why is this? The order used was based on the data fetched by a rpc("/web/export/get_fields". Solution: Do not do a rpc("/web/export/get_fields") and use the order of the columns in archInfo. How to reproduce: - Go to a list view - Click on the "export all" button Before this commit: The order of the columns in the created file may be different from the order in the list view. After this commit: The order of the columns in the created file is the same as in the list view. closes odoo/odoo#104541 X-original-commit: 734eee368d548fddc6c516ff559d09e853d1ab74 Signed-off-by: Luca Vitali --- .../static/src/views/list/list_controller.js | 13 +++--- .../view_dialogs/export_data_dialog_tests.js | 45 +------------------ 2 files changed, 8 insertions(+), 50 deletions(-) diff --git a/addons/web/static/src/views/list/list_controller.js b/addons/web/static/src/views/list/list_controller.js index 47b78c8b98d..8431f198222 100644 --- a/addons/web/static/src/views/list/list_controller.js +++ b/addons/web/static/src/views/list/list_controller.js @@ -328,7 +328,7 @@ export class ListController extends Component { name: field.name || field.id, label: field.label || field.string, store: field.store, - type: field.field_type, + type: field.field_type || field.type, })); if (import_compat) { exportedFields.unshift({ name: "id", label: this.env._t("External ID") }); @@ -379,12 +379,11 @@ export class ListController extends Component { * @private */ async onDirectExportData() { - const fields = await this.getExportedFields(this.model.root.resModel, true); - await this.downloadExport( - fields.filter((field) => this.model.root.activeFields[field.id]), - false, - "xlsx" - ); + const fields = this.props.archInfo.columns + .filter((col) => col.type === "field") + .map((col) => this.props.fields[col.name]) + .filter((field) => field.exportable !== false); + await this.downloadExport(fields, false, "xlsx"); } /** * Called when clicking on 'Archive' or 'Unarchive' in the sidebar. diff --git a/addons/web/static/tests/views/view_dialogs/export_data_dialog_tests.js b/addons/web/static/tests/views/view_dialogs/export_data_dialog_tests.js index e7405b04d72..6233a03f0fc 100644 --- a/addons/web/static/tests/views/view_dialogs/export_data_dialog_tests.js +++ b/addons/web/static/tests/views/view_dialogs/export_data_dialog_tests.js @@ -43,11 +43,6 @@ QUnit.module("ViewDialogs", (hooks) => { display_name: { string: "Displayed name", type: "char" }, foo: { string: "Foo", type: "char" }, bar: { string: "Bar", type: "boolean" }, - instrument: { - string: "Instruments", - type: "many2one", - relation: "instrument", - }, }, records: [ { id: 1, foo: "blip", display_name: "blipblip", bar: true }, @@ -55,32 +50,6 @@ QUnit.module("ViewDialogs", (hooks) => { { id: 3, foo: "piou piou", display_name: "Jack O'Neill", bar: true }, ], }, - instrument: { - fields: { - name: { string: "name", type: "char" }, - badassery: { - string: "level", - type: "many2many", - relation: "badassery", - domain: [["level", "=", "Awsome"]], - }, - }, - }, - - badassery: { - fields: { - level: { string: "level", type: "char" }, - }, - records: [{ id: 1, level: "Awsome" }], - }, - - product: { - fields: { - name: { string: "name", type: "char" }, - partner: { string: "Doors", type: "one2many", relation: "partner" }, - }, - records: [{ id: 1, name: "The end" }], - }, "ir.exports": { fields: { name: { string: "Name", type: "char" }, @@ -692,7 +661,7 @@ QUnit.module("ViewDialogs", (hooks) => { { name: "bar", label: "Bar", - type: "char", + type: "boolean", }, ], }, @@ -712,11 +681,6 @@ QUnit.module("ViewDialogs", (hooks) => { `, domain: [["bar", "!=", "glou"]], - mockRPC(route) { - if (route === "/web/export/get_fields") { - return Promise.resolve(fetchedFields.root); - } - }, }); await click(target.querySelector(".o_list_export_xlsx")); @@ -749,7 +713,7 @@ QUnit.module("ViewDialogs", (hooks) => { { name: "bar", label: "Bar", - type: "char", + type: "boolean", }, ], }, @@ -769,11 +733,6 @@ QUnit.module("ViewDialogs", (hooks) => { `, groupBy: ["foo", "bar"], domain: [["bar", "!=", "glou"]], - mockRPC(route) { - if (route === "/web/export/get_fields") { - return Promise.resolve(fetchedFields.root); - } - }, }); await click(target.querySelector(".o_list_export_xlsx"));