[FIX] web: FormView: don't modify record's context
Before this rev., some keys were added to the context of a record if there were x2many fields in the form view with a context defined on their node (containing *_view_ref keys, specifying the fields_view to load to display the relational data). Those keys should not be added to the main record's context, and it may cause errors (e.g. click on the 'Procurements' stat button in the Product form view).
This commit is contained in:
@@ -354,7 +354,7 @@ var ViewManager = Widget.extend(ControlPanelMixin, {
|
||||
var self = this;
|
||||
var arch = view.fields_view.arch;
|
||||
var View = this.registry.get(arch.attrs.js_class || view.type);
|
||||
var params = _.extend({}, view_options);
|
||||
var params = _.extend({}, view_options, {userContext: this.getSession().user_context});
|
||||
if (view.type === "form" && ((this.action.target === 'new' || this.action.target === 'inline') ||
|
||||
(view_options && view_options.mode === 'edit'))) {
|
||||
params.mode = params.initial_mode || 'edit';
|
||||
|
||||
@@ -102,6 +102,8 @@ var AbstractView = Class.extend({
|
||||
if (params.modelName) {
|
||||
this.loadParams.modelName = params.modelName;
|
||||
}
|
||||
|
||||
this.userContext = params.userContext;
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
@@ -64,16 +64,16 @@ var FormView = BasicView.extend({
|
||||
attrs.limit = attrs.mode === "tree" ? 80 : 40;
|
||||
|
||||
if (attrs.Widget.prototype.useSubview && !(attrs.invisible && JSON.parse(attrs.invisible)) && !attrs.views[attrs.mode]) {
|
||||
var context = {};
|
||||
var regex = /'([a-z]*_view_ref)' *: *'(.*?)'/g;
|
||||
var matches;
|
||||
while (matches = regex.exec(attrs.context)) {
|
||||
self.loadParams.context[matches[1]] = matches[2];
|
||||
context[matches[1]] = matches[2];
|
||||
}
|
||||
defs.push(parent.loadViews(
|
||||
field.relation,
|
||||
new Context(self.loadParams.context),
|
||||
[[null, attrs.mode === 'tree' ? 'list' : attrs.mode]],
|
||||
{})
|
||||
new Context(context, self.userContext),
|
||||
[[null, attrs.mode === 'tree' ? 'list' : attrs.mode]])
|
||||
.then(function (views) {
|
||||
for (var viewName in views) {
|
||||
attrs.views[viewName] = views[viewName];
|
||||
|
||||
@@ -3084,7 +3084,7 @@ QUnit.module('Views', {
|
||||
|
||||
QUnit.test('*_view_ref in context are passed correctly', function (assert) {
|
||||
var done = assert.async();
|
||||
assert.expect(1);
|
||||
assert.expect(4);
|
||||
|
||||
createAsyncView({
|
||||
View: FormView,
|
||||
@@ -3095,15 +3095,30 @@ QUnit.module('Views', {
|
||||
'<field name="p" context="{\'tree_view_ref\':\'module.tree_view_ref\'}"/>' +
|
||||
'</sheet>' +
|
||||
'</form>',
|
||||
res_id: 1,
|
||||
intercepts: {
|
||||
load_views: function (event) {
|
||||
assert.strictEqual(event.data.context.eval().tree_view_ref,
|
||||
'module.tree_view_ref',
|
||||
var context = event.data.context.eval();
|
||||
assert.strictEqual(context.tree_view_ref, 'module.tree_view_ref',
|
||||
"context should contain tree_view_ref");
|
||||
assert.notOk('some_context' in context,
|
||||
"should not send record's context to load p's fields_view");
|
||||
event.data.on_success();
|
||||
}
|
||||
}
|
||||
},
|
||||
viewOptions: {
|
||||
context: {some_context: false},
|
||||
},
|
||||
mockRPC: function (route, args) {
|
||||
if (args.method === 'read') {
|
||||
assert.deepEqual(args.kwargs.context, {some_context: false},
|
||||
"record's context shouldn't have been modified");
|
||||
}
|
||||
return this._super.apply(this, arguments);
|
||||
},
|
||||
}).then(function (form) {
|
||||
// reload to check that the record's context hasn't been modified
|
||||
form.reload();
|
||||
form.destroy();
|
||||
done();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user