From 6be7d3ee4aefb44116dfe6d339e063197a7a1ec4 Mon Sep 17 00:00:00 2001 From: Lucas Perais Date: Mon, 1 Aug 2022 14:40:33 +0000 Subject: [PATCH] [FIX] web: views: basic relational model: can save without any dirty translatable fields Be in another language, edit and save a record which has translatable fields. Before this commit, there was a crash because no changes were done on the record, making a programming error. After this commit, we can edit and save a record with translatable fields without changes. closes odoo/odoo#97240 Signed-off-by: Aaron Bohy (aab) --- .../src/views/basic_relational_model.js | 8 +++-- .../tests/views/form/form_view_tests.js | 36 +++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/addons/web/static/src/views/basic_relational_model.js b/addons/web/static/src/views/basic_relational_model.js index bb855ab51eb..28e233eda71 100644 --- a/addons/web/static/src/views/basic_relational_model.js +++ b/addons/web/static/src/views/basic_relational_model.js @@ -286,9 +286,11 @@ export class Record extends DataPoint { } get dirtyFields() { - return Object.keys(this.model.__bm__.localData[this.__bm_handle__]._changes).map( - (change) => this.activeFields[change] - ); + const changes = this.model.__bm__.localData[this.__bm_handle__]._changes; + if (!changes) { + return []; + } + return Object.keys(changes).map((change) => this.activeFields[change]); } get translatableFields() { diff --git a/addons/web/static/tests/views/form/form_view_tests.js b/addons/web/static/tests/views/form/form_view_tests.js index 69e857c31a9..12bf7a5fe93 100644 --- a/addons/web/static/tests/views/form/form_view_tests.js +++ b/addons/web/static/tests/views/form/form_view_tests.js @@ -7844,6 +7844,42 @@ QUnit.module("Views", (hooks) => { ); }); + QUnit.test("can save without any dirty translatable fields", async function (assert) { + serverData.models.partner.fields.foo.translate = true; + + patchWithCleanup(localization, { + multiLang: true, + }); + + await makeView({ + type: "form", + resModel: "partner", + serverData, + arch: ` +
+ + `, + resId: 1, + mockRPC(route, args) { + assert.step(args.method); + }, + }); + + assert.verifySteps(["get_views", "read"]); + await clickEdit(target); + assert.containsOnce(target, ".o_form_editable"); + // o_field_translate is on the input and on the translate button + assert.containsN(target, "div[name='foo'] > .o_field_translate", 2); + await clickSave(target); + assert.containsNone( + target, + ".alert .o_field_translate", + "should not have a translation alert" + ); + assert.containsOnce(target, ".o_form_readonly"); + assert.verifySteps([]); + }); + QUnit.test("translation alerts are preserved on pager change", async function (assert) { serverData.models.partner.fields.foo.translate = true;