[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 <luvi@odoo.com>
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
nurefexc
2021-12-21 12:55:01 +00:00
committed by luvi
parent fbb5b074f7
commit eb6810d1b5
3 changed files with 41 additions and 0 deletions
@@ -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;
@@ -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);
@@ -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,