From c0809dd41d9866c072822b36eae6b57cbc918cc9 Mon Sep 17 00:00:00 2001 From: Martin Geubelle Date: Wed, 25 Apr 2018 13:53:37 +0200 Subject: [PATCH] [FIX] web: reload progressbar values after archiving records Before this, the progressbar values were not updated (both count and progress) after archiving all the records of a column. Multiple things have been done here to update it. Firstly, a optimization had been done to avoid reloading the progressbar when updating a column ; this optimization was not correct due to this precise use case. This will update the progressbar. Secondly, the `aggregateValues` are reset when putting empty groups back in the datapoint. This attribute is used to compute the counter if a `sum_field` is set on the progressbar widget. It needs to be reset because the loop that computes it won't iterate on empty groups. Eventually, the mockRPC of the progressbar route was not taking the `group_by` argument into account (probably a typo). --- .../static/src/js/views/basic/basic_model.js | 4 ++ .../src/js/views/kanban/kanban_model.js | 8 +--- .../web/static/tests/helpers/mock_server.js | 2 +- addons/web/static/tests/views/kanban_tests.js | 41 +++++++++++++++++++ 4 files changed, 48 insertions(+), 7 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 e311378eee4..9d4dc877473 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -3842,6 +3842,10 @@ var BasicModel = AbstractModel.extend({ var emptyGroupsIDs = _.difference(_.pluck(previousGroups, 'id'), list.data); _.each(emptyGroupsIDs, function (groupID) { list.data.push(groupID); + var emptyGroup = self.localData[groupID]; + // this attribute hasn't been updated in the previous + // loop for empty groups + emptyGroup.aggregateValues = {}; }); } return $.when.apply($, defs).then(function () { 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 427d10f6032..b12984dc876 100644 --- a/addons/web/static/src/js/views/kanban/kanban_model.js +++ b/addons/web/static/src/js/views/kanban/kanban_model.js @@ -348,9 +348,8 @@ var KanbanModel = BasicModel.extend({ return $.when(); }, /** - * Reloads all progressbar data if the given id is a record's one. This is - * done after given deferred and insures that the given deferred's result is - * not lost. + * Reloads all progressbar data. This is done after given deferred and + * insures that the given deferred's result is not lost. * * @private * @param {string} recordID @@ -359,9 +358,6 @@ var KanbanModel = BasicModel.extend({ */ _reloadProgressBarGroupFromRecord: function (recordID, def) { var element = this.localData[recordID]; - if (element.type !== 'record') { - return def; - } // If we updated a record, then we must potentially update columns' // progressbars, so we need to load groups info again diff --git a/addons/web/static/tests/helpers/mock_server.js b/addons/web/static/tests/helpers/mock_server.js index 5955bae6af7..a47cd71fe48 100644 --- a/addons/web/static/tests/helpers/mock_server.js +++ b/addons/web/static/tests/helpers/mock_server.js @@ -740,7 +740,7 @@ var MockServer = Class.extend({ */ _mockReadProgressBar: function (model, kwargs) { var domain = kwargs.domain; - var groupBy = kwargs.groupBy; + var groupBy = kwargs.group_by; var progress_bar = kwargs.progress_bar; var records = this._getRecords(model, domain || []); diff --git a/addons/web/static/tests/views/kanban_tests.js b/addons/web/static/tests/views/kanban_tests.js index 03a6e31ad8e..b3bbc5ecb05 100644 --- a/addons/web/static/tests/views/kanban_tests.js +++ b/addons/web/static/tests/views/kanban_tests.js @@ -2550,6 +2550,47 @@ QUnit.module('Views', { kanban.destroy(); }); + QUnit.test('column progressbars on archiving records update counter', function (assert) { + assert.expect(4); + + // add active field on partner model and make all records active + this.data.partner.fields.active = {string: 'Active', type: 'char', default: true}; + + var kanban = createView({ + View: KanbanView, + model: 'partner', + data: this.data, + arch: + '' + + '' + + '' + + '' + + '' + + '' + + '
' + + '' + + '
' + + '
' + + '
', + groupBy: ['bar'], + }); + + assert.strictEqual(kanban.$('.o_kanban_group:eq(1) .o_kanban_counter_side').text(), "36", + "counter should contain the correct value"); + assert.strictEqual(kanban.$('.o_kanban_group:eq(1) .o_kanban_counter_progress > .progress-bar:first').data('originalTitle'), "1 yop", + "the counter progressbars should be correctly displayed"); + + // archive all records of the second columns + kanban.$('.o_kanban_group:eq(1) .o_column_archive').click(); + + assert.strictEqual(kanban.$('.o_kanban_group:eq(1) .o_kanban_counter_side').text(), "0", + "counter should contain the correct value"); + assert.strictEqual(kanban.$('.o_kanban_group:eq(1) .o_kanban_counter_progress > .progress-bar:first').data('originalTitle'), "0 yop", + "the counter progressbars should have been correctly updated"); + + kanban.destroy(); + }); + QUnit.test('drag & drop records grouped by m2o with progressbar', function (assert) { assert.expect(4);