[FIX] web: reset expanded fields on import compatibility switch

Steps to reproduce
==================

- Go to users
- Open the export dialog
- Expand the Groups field
- Add the Groups > Groups/Access Controls field
- Check the import compatibility option
- Expand the Groups field again
=> `TypeError: this.knownFields[id] is undefined`

Solution
========

The expandedFields were not reset. We also need to update the t-key to
take the compatibility state into account.

opw-3378834

closes odoo/odoo#146116

X-original-commit: d2f52abb8ce1b7e5291e0de7d4ea7788f39115bd
Signed-off-by: Luca Vitali (luvi) <luvi@odoo.com>
This commit is contained in:
Hubert Van De Walle
2023-12-13 15:53:00 +00:00
parent 95f12b4667
commit 63a4481ad4
3 changed files with 42 additions and 1 deletions
@@ -204,6 +204,7 @@ export class ExportDataDialog extends Component {
async fetchFields() {
this.state.search = [];
this.knownFields = {};
this.expandedFields = {};
await this.loadFields();
await this.setDefaultExportList();
if (this.searchRef.el) {
@@ -42,7 +42,7 @@
<div class="o_left_field_panel h-100 overflow-auto border">
<div class="o_field_tree_structure">
<t t-if="fieldsAvailable">
<t t-foreach="rootFields" t-as="field" t-key="field.id + '_' + state.search.length">
<t t-foreach="rootFields" t-as="field" t-key="field.id + '_' + state.search.length + '_' + state.isCompatible">
<ExportDataItem
exportList="state.exportList"
field="field"
@@ -647,6 +647,46 @@ QUnit.module("ViewDialogs", (hooks) => {
await click(target, ".o_select_button");
});
QUnit.test("toggling import compatibility after adding an expanded field", async function (assert) {
assert.expect(1);
mockDownload(({ url, data }) => {
assert.ok(
JSON.parse(data.data)["import_compat"],
"request to generate the file must have 'import_compat' as true"
);
return Promise.resolve();
});
await makeView({
serverData,
type: "list",
resModel: "partner",
arch: `<tree><field name="foo"/></tree>`,
actionMenus: {},
mockRPC(route, args) {
if (route === "/web/export/formats") {
return Promise.resolve([
{ tag: "csv", label: "CSV" },
]);
}
if (route === "/web/export/get_fields") {
if (!args.parent_field) {
return Promise.resolve(fetchedFields.root);
}
return Promise.resolve(fetchedFields[args.prefix]);
}
},
});
await openExportDataDialog();
await click(target, "[data-field_id='activity_ids']");
await click(target, "[data-field_id='activity_ids/partner_ids'] .o_add_field");
await click(target, ".o_import_compat input");
await click(target, "[data-field_id='activity_ids']");
await click(target, ".o_select_button");
});
QUnit.test("Export dialog: many2many fields are extendable", async function (assert) {
await makeView({
serverData,