diff --git a/addons/spreadsheet/static/src/o_spreadsheet/migration.js b/addons/spreadsheet/static/src/o_spreadsheet/migration.js index 4998f8b1bf5..46c8099a542 100644 --- a/addons/spreadsheet/static/src/o_spreadsheet/migration.js +++ b/addons/spreadsheet/static/src/o_spreadsheet/migration.js @@ -144,6 +144,9 @@ function migrate4to5(data) { data.pivots[id].fieldMatching = {}; } data.pivots[id].fieldMatching[filter.id] = { chain: fm.field, type: fm.type }; + if ("offset" in fm) { + data.pivots[id].fieldMatching[filter.id].offset = fm.offset; + } } delete filter.pivotFields; @@ -156,6 +159,9 @@ function migrate4to5(data) { data.lists[id].fieldMatching = {}; } data.lists[id].fieldMatching[filter.id] = { chain: fm.field, type: fm.type }; + if ("offset" in fm) { + data.lists[id].fieldMatching[filter.id].offset = fm.offset; + } } delete filter.listFields; @@ -178,6 +184,9 @@ function migrate4to5(data) { figure.data.fieldMatching = {}; } figure.data.fieldMatching[filter.id] = { chain: fm.field, type: fm.type }; + if ("offset" in fm) { + figure.data.fieldMatching[filter.id].offset = fm.offset; + } } delete filter.graphFields; } diff --git a/addons/spreadsheet/static/tests/migrations/migrations.js b/addons/spreadsheet/static/tests/migrations/migrations.js index d73c66fa5dc..6ce3b2102b4 100644 --- a/addons/spreadsheet/static/tests/migrations/migrations.js +++ b/addons/spreadsheet/static/tests/migrations/migrations.js @@ -226,6 +226,72 @@ QUnit.test("fieldMatchings are moved from filters to their respective datasource }); }); +QUnit.test("fieldMatchings offsets are correctly preserved after migration", (assert) => { + const data = { + globalFilters: [ + { + id: "Filter", + label: "MyFilter1", + type: "relation", + listFields: { + 1: { + field: "parent_id", + type: "date", + offset: "-1", + }, + }, + pivotFields: { + 1: { + field: "parent_id", + type: "date", + offset: "-1", + }, + }, + graphFields: { + fig1: { + field: "parent_id", + type: "date", + offset: "-1", + }, + }, + }, + ], + pivots: { + 1: { + name: "Name", + }, + }, + lists: { + 1: { + name: "Name", + }, + }, + sheets: [ + { + figures: [ + { + id: "fig1", + tag: "chart", + data: { + type: "odoo_bar", + }, + }, + ], + }, + ], + }; + const migratedData = migrate(data); + assert.deepEqual(migratedData.pivots["1"].fieldMatching, { + Filter: { chain: "parent_id", type: "date", offset: "-1" }, + }); + assert.deepEqual(migratedData.lists["1"].fieldMatching, { + Filter: { chain: "parent_id", type: "date", offset: "-1" }, + }); + assert.deepEqual(migratedData.sheets[0].figures[0].data.fieldMatching, { + Filter: { chain: "parent_id", type: "date", offset: "-1" }, + }); +}); + QUnit.test("Odoo version is exported", (assert) => { const model = new Model(); assert.strictEqual(model.exportData().odooVersion, ODOO_VERSION);