From c915373920abcba0bbc9b4cd2251150dcadf122f Mon Sep 17 00:00:00 2001 From: "Nicolas (vin)" Date: Fri, 4 Feb 2022 13:45:43 +0000 Subject: [PATCH] [FIX] web: BasicModel: contexts order When combining the context for an RPC, the additional context is being added before the raw context. Because of this, a use case such as: - A o2m field with a context {'field': 'a'} with a tree editable view below it - That view defines controls to create lines, which would change the context key 'field' to another value. => The field context key would take precedence on the creates key, making it impossible to override that key in specific circumstances. closes odoo/odoo#83996 Signed-off-by: Aaron Bohy (aab) --- .../src/legacy/js/views/basic/basic_model.js | 6 +-- .../relational_fields/field_one2many_tests.js | 40 +++++++++++++++++++ 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/addons/web/static/src/legacy/js/views/basic/basic_model.js b/addons/web/static/src/legacy/js/views/basic/basic_model.js index c36a74147ab..0093e3d41d4 100644 --- a/addons/web/static/src/legacy/js/views/basic/basic_model.js +++ b/addons/web/static/src/legacy/js/views/basic/basic_model.js @@ -3503,9 +3503,6 @@ var BasicModel = AbstractModel.extend({ } } } - if (options.additionalContext) { - context.add(options.additionalContext); - } if (element.rawContext) { var rawContext = new Context(element.rawContext); var evalContext = this._getEvalContext(this.localData[element.parentID]); @@ -3513,6 +3510,9 @@ var BasicModel = AbstractModel.extend({ rawContext.set_eval_context(evalContext); context.add(rawContext); } + if (options.additionalContext) { + context.add(options.additionalContext); + } return context.eval(); }, diff --git a/addons/web/static/tests/legacy/fields/relational_fields/field_one2many_tests.js b/addons/web/static/tests/legacy/fields/relational_fields/field_one2many_tests.js index 1fe0307449a..fca2bbd3975 100644 --- a/addons/web/static/tests/legacy/fields/relational_fields/field_one2many_tests.js +++ b/addons/web/static/tests/legacy/fields/relational_fields/field_one2many_tests.js @@ -10092,6 +10092,46 @@ QUnit.module('fields', {}, function () { form.destroy(); assert.verifySteps(["willUnmount 1"]); }); + + QUnit.test('combine contexts on o2m field and create tags', async function (assert) { + assert.expect(1); + + const form = await createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: ` +
+ + + + + + + + + +
+ `, + mockRPC: function (route, args) { + if (args.method === 'onchange') { + if (args.model === 'turtle') { + assert.deepEqual(args.kwargs.context, { + default_turtle_foo: 'soft', + default_turtle_bar: true, + default_turtle_int: 2, + }, + 'combined context should have the default_turtle_foo value from the '); + } + } + return this._super.apply(this, arguments); + } + }); + + await testUtils.dom.click(form.$('.o_field_x2many_list_row_add a:eq(0)')); + + form.destroy(); + }); }); }); });