From eb6810d1b5303dc5c665993ad7b9f47e4bed4f22 Mon Sep 17 00:00:00 2001 From: nurefexc Date: Mon, 29 Nov 2021 11:25:49 +0000 Subject: [PATCH] [FIX] web: missing context during resequence Problem 1: The context was not passed when calling the resequence function. Problem 2: Also, the subsequent read operation did not pass the full context, but only the context of the user, not the context of the action. A test has been added for the basic model to check that the context is properly given after a resequence. closes odoo/odoo#81726 X-original-commit: 75bbec4f7fe14aa9d9c310ffcbd500bd1f70b14f Signed-off-by: Luca Vitali Signed-off-by: Aaron Bohy (aab) --- .../src/legacy/js/views/basic/basic_model.js | 2 ++ .../tests/legacy/views/basic_model_tests.js | 35 +++++++++++++++++++ .../static/tests/legacy/views/list_tests.js | 4 +++ 3 files changed, 41 insertions(+) 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 dd1dd3e4b40..9187e6a965d 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 @@ -1039,6 +1039,7 @@ var BasicModel = AbstractModel.extend({ var params = { model: modelName, ids: resIDs, + context: data.getContext(), }; if (options.offset) { params.offset = options.offset; @@ -1062,6 +1063,7 @@ var BasicModel = AbstractModel.extend({ model: modelName, method: 'read', args: [resIDs, [field]], + context: data.getContext(), }).then(function (records) { if (data.data.length) { var dataType = self.localData[data.data[0]].type; diff --git a/addons/web/static/tests/legacy/views/basic_model_tests.js b/addons/web/static/tests/legacy/views/basic_model_tests.js index a9ee71393bc..884ae73295f 100644 --- a/addons/web/static/tests/legacy/views/basic_model_tests.js +++ b/addons/web/static/tests/legacy/views/basic_model_tests.js @@ -81,6 +81,41 @@ odoo.define('web.basic_model_tests', function (require) { }, function () { QUnit.module('BasicModel'); + QUnit.test('context is given when using a resequence', async function (assert) { + assert.expect(2); + delete this.params["res_id"]; + this.data.product.fields.sequence = {string: "Sequence", type: "integer"}; + + const model = await createModel({ + Model: BasicModel, + data: this.data, + mockRPC: function (route, args) { + if (route === '/web/dataset/resequence') { + assert.deepEqual(args.context, { active_field: 2 }, + "context should be correct after a resequence"); + } + else if (args.method === "read") { + assert.deepEqual(args.kwargs.context, { active_field: 2 }, + "context should be correct after a 'read' RPC"); + } + return this._super.apply(this, arguments); + }, + }); + const params = _.extend(this.params, { + context: { active_field: 2 }, + groupedBy: ['product_id'], + fieldNames: ['foo'], + }); + + model.load(params) + .then(function (stateID) { + return model.resequence('product', [41, 37], stateID); + }) + .then(function () { + model.destroy(); + }); + }); + QUnit.test('can process x2many commands', async function (assert) { assert.expect(6); diff --git a/addons/web/static/tests/legacy/views/list_tests.js b/addons/web/static/tests/legacy/views/list_tests.js index 069bc17f448..e13882d2408 100644 --- a/addons/web/static/tests/legacy/views/list_tests.js +++ b/addons/web/static/tests/legacy/views/list_tests.js @@ -7270,6 +7270,7 @@ QUnit.module('Views', { if (route === '/web/dataset/resequence') { if (moves === 0) { assert.deepEqual(args, { + context: {}, model: "foo", ids: [4, 3], offset: 13, @@ -7278,6 +7279,7 @@ QUnit.module('Views', { } if (moves === 1) { assert.deepEqual(args, { + context: {}, model: "foo", ids: [4, 2], offset: 12, @@ -7286,6 +7288,7 @@ QUnit.module('Views', { } if (moves === 2) { assert.deepEqual(args, { + context: {}, model: "foo", ids: [2, 4], offset: 12, @@ -7294,6 +7297,7 @@ QUnit.module('Views', { } if (moves === 3) { assert.deepEqual(args, { + context: {}, model: "foo", ids: [4, 2], offset: 12,