From 87ac617eb1418d5d5edba2e0aae99adb506c0f78 Mon Sep 17 00:00:00 2001 From: Martin Geubelle Date: Wed, 12 Apr 2017 17:19:36 +0200 Subject: [PATCH] [FIX] web: Kanban: edit the kanban color The method has not been correctly ported to the new view (in the new model in this case). The change (on the color) needs to be notified to the model before updating the record. --- .../src/js/views/kanban/kanban_controller.js | 9 ++- addons/web/static/tests/views/kanban_tests.js | 56 +++++++++++++++++++ 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/addons/web/static/src/js/views/kanban/kanban_controller.js b/addons/web/static/src/js/views/kanban/kanban_controller.js index 875f1042403..ab0f4cb6d07 100644 --- a/addons/web/static/src/js/views/kanban/kanban_controller.js +++ b/addons/web/static/src/js/views/kanban/kanban_controller.js @@ -363,9 +363,14 @@ var KanbanController = BasicController.extend({ * @param {OdooEvent} event */ _onUpdateRecord: function (event) { + var self = this; var record = event.target; - this.alive(this.model.save(record.db_id, event.data)) - .then(record.update.bind(record)); + this.model.notifyChanges(record.db_id, event.data).then(function () { + self.model.save(record.db_id).then(function () { + var state = self.model.get(record.db_id); + record.update(state); + }); + }); }, }); diff --git a/addons/web/static/tests/views/kanban_tests.js b/addons/web/static/tests/views/kanban_tests.js index 1f8900bf1bf..951afc8e112 100644 --- a/addons/web/static/tests/views/kanban_tests.js +++ b/addons/web/static/tests/views/kanban_tests.js @@ -1063,6 +1063,62 @@ QUnit.module('Views', { kanban.destroy(); }); + QUnit.test('edit the kanban color with the colorpicker', function (assert) { + assert.expect(5); + + var writeOnColor; + + var kanban = createView({ + View: KanbanView, + model: 'category', + data: this.data, + debug: true, + arch: '' + + '' + + '' + + '' + + '
' + + '' + + '' + + '
' + + '
' + + '
' + + '
', + mockRPC: function (route, args) { + if (args.method === 'write' && 'color' in args.args[1]) { + writeOnColor = true; + } + return this._super.apply(this, arguments); + }, + }); + + var $first_record = kanban.$('.o_kanban_record:first()'); + + assert.strictEqual($first_record.find('.oe_kanban_color_10').length, 0, + "no record should have the color 10"); + assert.strictEqual($first_record.find('.oe_kanban_colorpicker').length, 1, + "there should be a color picker"); + assert.strictEqual($first_record.find('.oe_kanban_colorpicker').children().length, 10, + "the color picker should have 10 children (the colors)"); + + // set the last color + $first_record.find('.oe_kanban_colorpicker a.oe_kanban_color_9').click(); + assert.ok(writeOnColor, "should write on the color field"); + assert.strictEqual($first_record.find('.oe_kanban_color_9').length, 1, + "one record should have the color 10"); + + kanban.destroy(); + }); + }); });