[FIX] web: ignore default_* on group creation

When a column is created in the kanban view, the context of the window
action is fully given but it may contain default_{field_name} context
keys that are intended for the action model.

eg. on a product.product view we could have {default_type:'product'} in
the context, if we grouped by company_id and created a new company, we
would the context is propagated and we would try to set type='product'
on the company (which causes an error).

Without the change, the added test fails with:

  default_* should be removed from context, actual: "true", expected: "false"

opw-1879064
closes #26676
This commit is contained in:
Nicolas Lempereur
2018-09-04 11:03:15 +02:00
parent 15c81d74a3
commit 4cb585ab4f
2 changed files with 42 additions and 1 deletions
@@ -60,11 +60,15 @@ var KanbanModel = BasicModel.extend({
if (!groupByField || groupByField.type !== 'many2one') {
return $.Deferred().reject(); // only supported when grouped on m2o
}
// ignore action default which may be for another model
var context = _.pick(parent.context, function (value, key) {
return key.slice(0,8) !== 'default_';
});
return this._rpc({
model: groupByField.relation,
method: 'name_create',
args: [name],
context: parent.context, // todo: combine with view context
context: context, // todo: combine with view context
})
.then(function (result) {
var newGroup = self._makeDataPoint({
@@ -665,6 +665,43 @@ QUnit.module('Views', {
kanban.destroy();
});
QUnit.test('m2o group record created does not use action defaults', function (assert) {
assert.expect(1);
var kanban = createView({
View: KanbanView,
model: 'partner',
data: this.data,
arch: '<kanban class="o_kanban_test" on_create="quick_create">' +
'<templates><t t-name="kanban-box">' +
'<div>' +
'<field name="foo"/>' +
'</div>' +
'</t></templates>' +
'</kanban>',
groupBy: ['product_id'],
mockRPC: function (route, args) {
if (args.method === 'name_create') {
assert.notOk(_.has(args.kwargs.context, 'default_name'),
"default_* should be removed from context");
}
return this._super.apply(this, arguments);
},
viewOptions: {
context: {
default_name: 'default name partner',
},
},
});
kanban.renderButtons();
kanban.$('.o_column_quick_create input').val('new product');
kanban.$('.o_column_quick_create button.o_kanban_add').click();
kanban.destroy();
});
QUnit.test('quick create fail in grouped', function (assert) {
assert.expect(7);