From 11d2e6dde50a73b5a2a9b39f09246a6bf46c470c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Thu, 4 Mar 2021 12:35:36 +0000 Subject: [PATCH] [FIX] web: properly apply onchange in some cases MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A previous commit (8dbd1efef899fb637acca3c318ae99cb23838b8f) fixed a part of the basicmodel that used _.each to iterate on an object with field names as keys, which does not work when a field is named "length". To fix it, I simply used a native for ... in statement. However, I missed the fact that there was a second 'return' statement in the body of the closure given to _.each, so the onchange method returned prematurely. The fix is to simply use the continue statement in that case. closes odoo/odoo#67267 X-original-commit: d9834e65ee57511f4850fa2d74287eb0b67087b9 Signed-off-by: Aaron Bohy (aab) Signed-off-by: Géry Debongnie (ged) --- .../static/src/js/views/basic/basic_model.js | 3 +- .../static/tests/views/basic_model_tests.js | 36 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/js/views/basic/basic_model.js b/addons/web/static/src/js/views/basic/basic_model.js index 2524ff2ab02..b8211b2f048 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -1779,7 +1779,8 @@ var BasicModel = AbstractModel.extend({ } else { var fieldInfo = record.fieldsInfo[viewType][name]; if (!fieldInfo) { - return; // ignore changes of x2many not in view + // ignore changes of x2many not in view + continue; } var view = fieldInfo.views && fieldInfo.views[fieldInfo.mode]; list = self._makeDataPoint({ diff --git a/addons/web/static/tests/views/basic_model_tests.js b/addons/web/static/tests/views/basic_model_tests.js index 909cdfaa905..dd802790210 100644 --- a/addons/web/static/tests/views/basic_model_tests.js +++ b/addons/web/static/tests/views/basic_model_tests.js @@ -127,6 +127,42 @@ odoo.define('web.basic_model_tests', function (require) { form.destroy(); }); + QUnit.test('can process x2many commands (with multiple fields)', async function (assert) { + assert.expect(1); + + this.data.partner.fields.product_ids.default = [[0, 0, { category: [] }]]; + + const form = await createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: ` +
+ + + `, + archs: { + 'product,false,list': ` + + + + + `, + }, + mockRPC(route, args) { + if (args.method === "create") { + const product_ids = args.args[0].product_ids; + const values = product_ids[0][2]; + assert.strictEqual(values.active, true, "active field should be set"); + } + return this._super.apply(this, arguments); + }, + }); + + await testUtils.form.clickSave(form); + form.destroy(); + }); + QUnit.test('can load a record', async function (assert) { assert.expect(7);