[FIX] web: use optionalActiveFields for direct export
Steps to reproduce ================== - Go to project - Switch to the list view - Remove some optional fields - Click on the export all button next to the "New Button" The optional fields configuration are ignored and all fields are exported. Cause of the issue ================== The `optionalActiveFields` are not taken into account when computing the `defaultExportList`. This was the case in 15.0 opw-3452459 closes odoo/odoo#131594 X-original-commit: 2a397cb5bb89d1a10e7ac765ff9035c102fbb436 Signed-off-by: Luca Vitali (luvi) <luvi@odoo.com> Signed-off-by: Hubert Van De Walle <huvw@odoo.com>
This commit is contained in:
@@ -61,6 +61,8 @@ export class ListController extends Component {
|
||||
this.hasMousedownDiscard = false;
|
||||
this.nextActionAfterMouseup = null;
|
||||
|
||||
this.optionalActiveFields = [];
|
||||
|
||||
onWillStart(async () => {
|
||||
this.isExportEnable = await this.userService.hasGroup("base.group_allow_export");
|
||||
});
|
||||
@@ -400,10 +402,15 @@ export class ListController extends Component {
|
||||
return list.isGrouped ? list.recordCount : list.count;
|
||||
}
|
||||
|
||||
onOptionalFieldsChanged(optionalActiveFields) {
|
||||
this.optionalActiveFields = optionalActiveFields;
|
||||
}
|
||||
|
||||
get defaultExportList() {
|
||||
return unique(
|
||||
this.props.archInfo.columns
|
||||
.filter((col) => col.type === "field")
|
||||
.filter((col) => !col.optional || this.optionalActiveFields[col.name])
|
||||
.map((col) => this.props.fields[col.name])
|
||||
.filter((field) => field.exportable !== false)
|
||||
);
|
||||
|
||||
@@ -69,7 +69,7 @@
|
||||
</t>
|
||||
</div>
|
||||
</t>
|
||||
<t t-component="props.Renderer" list="model.root" activeActions="activeActions" archInfo="archInfo" allowSelectors="props.allowSelectors" editable="editable" openRecord.bind="openRecord" noContentHelp="props.info.noContentHelp" onAdd.bind="createRecord"/>
|
||||
<t t-component="props.Renderer" list="model.root" activeActions="activeActions" archInfo="archInfo" allowSelectors="props.allowSelectors" editable="editable" openRecord.bind="openRecord" noContentHelp="props.info.noContentHelp" onAdd.bind="createRecord" onOptionalFieldsChanged.bind="onOptionalFieldsChanged"/>
|
||||
</Layout>
|
||||
</div>
|
||||
</t>
|
||||
|
||||
@@ -1031,6 +1031,9 @@ export class ListRenderer extends Component {
|
||||
this.optionalActiveFields[col.name] = col.optional === "show";
|
||||
}
|
||||
}
|
||||
if (this.props.onOptionalFieldsChanged) {
|
||||
this.props.onOptionalFieldsChanged(this.optionalActiveFields);
|
||||
}
|
||||
}
|
||||
|
||||
onClickSortColumn(column) {
|
||||
@@ -1808,6 +1811,9 @@ export class ListRenderer extends Component {
|
||||
|
||||
async toggleOptionalField(fieldName) {
|
||||
this.optionalActiveFields[fieldName] = !this.optionalActiveFields[fieldName];
|
||||
if (this.props.onOptionalFieldsChanged) {
|
||||
this.props.onOptionalFieldsChanged(this.optionalActiveFields);
|
||||
}
|
||||
this.state.columns = this.getActiveColumns(this.props.list);
|
||||
this.saveOptionalActiveFields(
|
||||
this.allColumns.filter((col) => this.optionalActiveFields[col.name] && col.optional)
|
||||
@@ -2106,6 +2112,7 @@ ListRenderer.props = [
|
||||
"editable?",
|
||||
"noContentHelp?",
|
||||
"nestedKeyOptionalFieldsData?",
|
||||
"onOptionalFieldsChanged?",
|
||||
];
|
||||
ListRenderer.defaultProps = { hasSelectors: false, cycleOnTab: true };
|
||||
|
||||
|
||||
@@ -1219,4 +1219,45 @@ QUnit.module("ViewDialogs", (hooks) => {
|
||||
"subfield has been found with its technical name and is displayed"
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test(
|
||||
"Direct export list take optional fields into account",
|
||||
async function (assert) {
|
||||
assert.expect(3);
|
||||
|
||||
mockDownload(({ url, data }) => {
|
||||
assert.strictEqual(
|
||||
url,
|
||||
"/web/export/xlsx",
|
||||
"should call get_file with the correct url"
|
||||
);
|
||||
assert.deepEqual(JSON.parse(data.data).fields, [
|
||||
{ label: "Bar", name: "bar", type: "boolean" },
|
||||
]);
|
||||
return Promise.resolve();
|
||||
});
|
||||
|
||||
await makeView({
|
||||
serverData,
|
||||
type: "list",
|
||||
resModel: "partner",
|
||||
arch: `
|
||||
<tree>
|
||||
<field name="foo" optional="show"/>
|
||||
<field name="bar" optional="show"/>
|
||||
</tree>`,
|
||||
});
|
||||
|
||||
await click(target, "table .o_optional_columns_dropdown .dropdown-toggle");
|
||||
await click(target, "div.o_optional_columns_dropdown span.dropdown-item:first-child");
|
||||
assert.containsN(
|
||||
target,
|
||||
"th",
|
||||
3,
|
||||
"should have 3 th, 1 for selector, 1 for columns, 1 for optional columns"
|
||||
);
|
||||
|
||||
await exportAllAction(target);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user