[FIX] web: navigate through records in Kanban with progressbar

Recently, rev. c0809dd41 removed a protection in the reload of
Kanban views with progressbars. This protection ensured that the
manual reload of the progressbars was only done when one of the
records of the Kanban view was updated (and not when a column, or
the whole view was).

However, removing it highlighted a bug linked to the manual reload
of progressbars, which messed up the list of ids in the
environment. As a consequence, for instance, if the user archived
the records of a column, and then opendc a record in form view,
it couldn't use the pager anymore.

Besides fixing this bug, this rev. re-introduces the protection,
and refines it to prevent 2 useless RPCs when the whole Kanban
view was reloaded.

opw~1841276
opw~1841342
This commit is contained in:
Aaron Bohy
2018-05-08 08:39:23 +02:00
parent 9d6ea8ef3e
commit 013baed413
3 changed files with 96 additions and 5 deletions
@@ -3864,11 +3864,13 @@ var BasicModel = AbstractModel.extend({
});
}
return $.when.apply($, defs).then(function () {
// generate the res_ids of the main list, being the concatenation
// of the fetched res_ids in each group
list.res_ids = _.flatten(_.map(arguments, function (group) {
return group ? group.res_ids : [];
}));
if (!options || !options.onlyGroups) {
// generate the res_ids of the main list, being the concatenation
// of the fetched res_ids in each group
list.res_ids = _.flatten(_.map(arguments, function (group) {
return group ? group.res_ids : [];
}));
}
return list;
});
});
@@ -358,6 +358,11 @@ var KanbanModel = BasicModel.extend({
*/
_reloadProgressBarGroupFromRecord: function (recordID, def) {
var element = this.localData[recordID];
if (element.type === 'list' && !element.parentID) {
// we are reloading the whole view, so there is no need to manually
// reload the progressbars
return def;
}
// If we updated a record, then we must potentially update columns'
// progressbars, so we need to load groups info again
@@ -2591,6 +2591,90 @@ QUnit.module('Views', {
kanban.destroy();
});
QUnit.test('kanban with progressbars: correctly update env when archiving records', function (assert) {
assert.expect(3);
// 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:
'<kanban>' +
'<field name="active"/>' +
'<field name="bar"/>' +
'<field name="int_field"/>' +
'<progressbar field="foo" colors=\'{"yop": "success", "gnap": "warning", "blip": "danger"}\' sum_field="int_field"/>' +
'<templates><t t-name="kanban-box">' +
'<div>' +
'<field name="name"/>' +
'</div>' +
'</t></templates>' +
'</kanban>',
groupBy: ['bar'],
intercepts: {
env_updated: function (ev) {
assert.step(ev.data.ids);
},
},
});
// archive all records of the first column
kanban.$('.o_kanban_group:first .o_column_archive').click();
assert.verifySteps([
[1, 2, 3, 4],
[1, 2, 3],
]);
kanban.destroy();
});
QUnit.test('RPCs when (re)loading kanban view progressbars', function (assert) {
assert.expect(9);
var kanban = createView({
View: KanbanView,
model: 'partner',
data: this.data,
arch:
'<kanban>' +
'<field name="bar"/>' +
'<field name="int_field"/>' +
'<progressbar field="foo" colors=\'{"yop": "success", "gnap": "warning", "blip": "danger"}\' sum_field="int_field"/>' +
'<templates><t t-name="kanban-box">' +
'<div>' +
'<field name="name"/>' +
'</div>' +
'</t></templates>' +
'</kanban>',
groupBy: ['bar'],
mockRPC: function (route, args) {
assert.step(args.method || route);
return this._super.apply(this, arguments);
},
});
kanban.reload();
assert.verifySteps([
// initial load
'read_group',
'/web/dataset/search_read',
'/web/dataset/search_read',
'read_progress_bar',
// reload
'read_group',
'/web/dataset/search_read',
'/web/dataset/search_read',
'read_progress_bar',
]);
kanban.destroy();
});
QUnit.test('drag & drop records grouped by m2o with progressbar', function (assert) {
assert.expect(4);