diff --git a/addons/spreadsheet/static/src/list/plugins/list_core_plugin.js b/addons/spreadsheet/static/src/list/plugins/list_core_plugin.js index d84c606ea9d..785352eb6e0 100644 --- a/addons/spreadsheet/static/src/list/plugins/list_core_plugin.js +++ b/addons/spreadsheet/static/src/list/plugins/list_core_plugin.js @@ -332,11 +332,7 @@ export default class ListCorePlugin extends spreadsheet.CorePlugin { context: list.context, orderBy: list.orderBy, }, - /** - * As we are not able to migrate the json, we have to fallback - * in the case where the name is not yet present - */ - name: list.name || list.model, + name: list.name, }; this._addList(id, definition, this.uuidGenerator.uuidv4()); } diff --git a/addons/spreadsheet/static/src/o_spreadsheet/migration.js b/addons/spreadsheet/static/src/o_spreadsheet/migration.js index d2ceb149ebb..ba09a8f3771 100644 --- a/addons/spreadsheet/static/src/o_spreadsheet/migration.js +++ b/addons/spreadsheet/static/src/o_spreadsheet/migration.js @@ -4,7 +4,7 @@ import spreadsheet from "./o_spreadsheet_extended"; const { load, CorePlugin, tokenize, parse, convertAstNodes, astToFormula } = spreadsheet; const { corePluginRegistry } = spreadsheet.registries; -export const ODOO_VERSION = 3; +export const ODOO_VERSION = 4; const MAP = { PIVOT: "ODOO.PIVOT", @@ -29,6 +29,9 @@ export function migrate(data) { if (version < 3) { _data = migrate2to3(_data); } + if (version < 4) { + _data = migrate3to4(_data); + } return _data; } @@ -110,6 +113,23 @@ function migrate2to3(data) { return data; } +/** + * Migration of list/pivot names + */ +function migrate3to4(data) { + if (data.lists) { + for (const list of Object.values(data.lists)) { + list.name = list.name || list.model; + } + } + if (data.pivots) { + for (const pivot of Object.values(data.pivots)) { + pivot.name = pivot.name || pivot.model; + } + } + return data; +} + /** * Convert pivot formulas days parameters from day/month/year * format to the standard spreadsheet month/day/year format. @@ -121,7 +141,7 @@ function migratePivotDaysParameters(formulaString) { const ast = parse(formulaString); const convertedAst = convertAstNodes(ast, "FUNCALL", (ast) => { if (["ODOO.PIVOT", "ODOO.PIVOT.HEADER"].includes(ast.value.toUpperCase())) { - for (let subAst of ast.args) { + for (const subAst of ast.args) { if (subAst.type === "STRING") { const date = subAst.value.match(dmyRegex); if (date) { diff --git a/addons/spreadsheet/static/src/pivot/plugins/pivot_core_plugin.js b/addons/spreadsheet/static/src/pivot/plugins/pivot_core_plugin.js index a99f2933b2f..663570f0010 100644 --- a/addons/spreadsheet/static/src/pivot/plugins/pivot_core_plugin.js +++ b/addons/spreadsheet/static/src/pivot/plugins/pivot_core_plugin.js @@ -443,11 +443,7 @@ export default class PivotCorePlugin extends CorePlugin { domain: pivot.domain, context: pivot.context, }, - /** - * As we are not able to migrate the json, we have to fallback - * in the case where the name is not yet present - */ - name: pivot.name || pivot.model, + name: pivot.name, }; this._addPivot(id, definition, this.uuidGenerator.uuidv4()); } diff --git a/addons/spreadsheet/static/tests/migrations/migrations.js b/addons/spreadsheet/static/tests/migrations/migrations.js index 1d47f8bde84..146974c38d1 100644 --- a/addons/spreadsheet/static/tests/migrations/migrations.js +++ b/addons/spreadsheet/static/tests/migrations/migrations.js @@ -164,6 +164,42 @@ QUnit.test("Global filters: list and graph fields are added", (assert) => { }); }); +QUnit.test("List name default is model name", (assert) => { + const data = { + lists: { + 1: { + name: "Name", + model: "Model", + }, + 2: { + model: "Model", + }, + }, + }; + const migratedData = migrate(data); + assert.strictEqual(Object.values(migratedData.lists).length, 2); + assert.strictEqual(migratedData.lists["1"].name, "Name"); + assert.strictEqual(migratedData.lists["2"].name, "Model"); +}); + +QUnit.test("Pivot name default is model name", (assert) => { + const data = { + pivots: { + 1: { + name: "Name", + model: "Model", + }, + 2: { + model: "Model", + }, + }, + }; + const migratedData = migrate(data); + assert.strictEqual(Object.values(migratedData.pivots).length, 2); + assert.strictEqual(migratedData.pivots["1"].name, "Name"); + assert.strictEqual(migratedData.pivots["2"].name, "Model"); +}); + QUnit.test("Odoo version is exported", (assert) => { const model = new Model(); assert.strictEqual(model.exportData().odooVersion, ODOO_VERSION);