summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorLucas Perais (lpe) <lpe@odoo.com>2019-03-08 12:57:02 +0000
committerLucas Perais (lpe) <lpe@odoo.com>2019-03-08 13:30:30 +0000
commit6b676f62352ca133723bf9cc9bafa8d05728eb0e (patch)
tree26537a892b05533db89e65ad687027b70dbf4ba6 /addons
parent4524dcd69158763575124e5867a7e1d295ebe034 (diff)
[FIX] web: record datapoint context without group_by or orderedBy
Have a list view, apply a group_by and a filter with a sort parameter Click on one record to access the form view Have a x2m within it Before this commit, the x2m records were loaded with a context containing the keys orderedBy and group_by It seems harmless at first, but even conceptually those keys should not be here - they apply on a list of records, and not to individual ones - they may contain field names not existing in the x2m model Hence, when accessing another list view through an action button, the list will try to be orderedBy or group_by with the given context Which is plain wrong in the first place and may cause crashes After this commit, the context of a record datapoint (representing a single record) is stripped from the keys Read the opw for a concrete use case OPW 1943583 closes odoo/odoo#31706 Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
Diffstat (limited to 'addons')
-rw-r--r--addons/web/static/src/js/views/basic/basic_model.js6
-rw-r--r--addons/web/static/tests/views/form_tests.js43
2 files changed, 48 insertions, 1 deletions
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 1a6e21c4049..1a4f1574ac8 100644
--- a/addons/web/static/src/js/views/basic/basic_model.js
+++ b/addons/web/static/src/js/views/basic/basic_model.js
@@ -3295,6 +3295,7 @@ var BasicModel = AbstractModel.extend({
var res_id, value;
var res_ids = params.res_ids || [];
var data = params.data || (type === 'record' ? {} : []);
+ var context = params.context;
if (type === 'record') {
res_id = params.res_id || (params.data && params.data.id);
if (res_id) {
@@ -3302,6 +3303,9 @@ var BasicModel = AbstractModel.extend({
} else {
res_id = _.uniqueId('virtual_');
}
+ // it doesn't make sense for a record datapoint to have those keys
+ // besides, it will mess up x2m and actions down the line
+ context = _.omit(context, ['orderedBy', 'group_by']);
} else {
var isValueArray = params.value instanceof Array;
res_id = isValueArray ? params.value[0] : undefined;
@@ -3319,7 +3323,7 @@ var BasicModel = AbstractModel.extend({
_domains: {},
_rawChanges: {},
aggregateValues: params.aggregateValues || {},
- context: params.context,
+ context: context,
count: params.count || res_ids.length,
data: data,
domain: params.domain || [],
diff --git a/addons/web/static/tests/views/form_tests.js b/addons/web/static/tests/views/form_tests.js
index 1a23f18e792..b3a87e29ba6 100644
--- a/addons/web/static/tests/views/form_tests.js
+++ b/addons/web/static/tests/views/form_tests.js
@@ -6650,6 +6650,49 @@ QUnit.module('Views', {
form.destroy();
});
+ QUnit.test('Form view from ordered, grouped list view correct context', function (assert) {
+ assert.expect(9);
+ this.data.partner.records[0].timmy = [12];
+
+ var form = createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch: '<form>' +
+ '<field name="foo"/>' +
+ '<field name="timmy"/>' +
+ '</form>',
+ archs: {
+ 'partner_type,false,list':
+ '<list>' +
+ '<field name="name"/>' +
+ '</list>',
+ },
+ viewOptions: {
+ // Simulates coming from a list view with a groupby and filter
+ context: {
+ orderedBy: [{name: 'foo', asc:true}],
+ group_by: ['foo'],
+ }
+ },
+ res_id: 1,
+ mockRPC: function (route, args) {
+ assert.step(args.method + '_' + args.model);
+ if (args.method === 'read') {
+ assert.ok(args.kwargs.context, 'context is present');
+ assert.notOk('orderedBy' in args.kwargs.context,
+ 'orderedBy not in context');
+ assert.notOk('group_by' in args.kwargs.context,
+ 'group_by not in context');
+ }
+ return this._super.apply(this, arguments);
+ }
+ });
+
+ assert.verifySteps(['read_partner', 'read_partner_type']);
+
+ form.destroy();
+ });
});
});