From 040410e5cc3d3ed2e27f9b3772768e825d81372f Mon Sep 17 00:00:00 2001 From: Pierre Rousseau Date: Tue, 17 Jan 2023 14:29:02 +0000 Subject: [PATCH] [FIX] spreadsheet: correctly migrate date offset field matching MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Steps to reproduce: - Edit CRM -> Leads dashboard - Edit filter "Period" => There is no period offset for the pivot 2, 4 and 6, despite the fact that these pivots have a period offset defined in the json data This is because the field matching migration was not correct. It did not take "offset" field into account. Task-id 3138590 closes odoo/odoo#110221 X-original-commit: 2217c10ba771ece4a4d0d0485ce2f24b13754244 Signed-off-by: Rémi Rahir (rar) Signed-off-by: Pierre Rousseau (pro) --- .../static/src/o_spreadsheet/migration.js | 9 +++ .../static/tests/migrations/migrations.js | 66 +++++++++++++++++++ 2 files changed, 75 insertions(+) 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);