[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 <luvi@odoo.com>
This commit is contained in:
FrancoisGe
2022-10-28 22:44:39 +02:00
parent fe1b5913cf
commit c3f2638edf
2 changed files with 8 additions and 50 deletions
@@ -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.
@@ -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) => {
<field name="bar"/>
</tree>`,
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) => {
</tree>`,
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"));