From 4cb585ab4f880147fbe35eb988c3c1da9728f624 Mon Sep 17 00:00:00 2001 From: Nicolas Lempereur Date: Wed, 29 Aug 2018 17:38:23 +0200 Subject: [PATCH] [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 --- .../src/js/views/kanban/kanban_model.js | 6 ++- addons/web/static/tests/views/kanban_tests.js | 37 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/js/views/kanban/kanban_model.js b/addons/web/static/src/js/views/kanban/kanban_model.js index 7d47a081b0a..40c78ef9efc 100644 --- a/addons/web/static/src/js/views/kanban/kanban_model.js +++ b/addons/web/static/src/js/views/kanban/kanban_model.js @@ -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({ diff --git a/addons/web/static/tests/views/kanban_tests.js b/addons/web/static/tests/views/kanban_tests.js index 921cf3655da..8ccb421eb89 100644 --- a/addons/web/static/tests/views/kanban_tests.js +++ b/addons/web/static/tests/views/kanban_tests.js @@ -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: '' + + '' + + '
' + + '' + + '
' + + '
' + + '
', + 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);