[FIX] web: do not change pager when discarding changes

Here is a scenario that could happen before this commit:
1. go to a list view with more than one record, say 3
2. click on the 3rd record to open the form view
3. the pager says 3/3
4. click on edit button
5. click on discard button
6. the pager says 1/3 (but the record displayed is still the same)

It is often necessary to restore the offset for the sub records, because
the number of pages in a one2many could have changed.  However, it is
not a good idea to do that for the main record, since it interferes with
the usual flow of operations.
This commit is contained in:
Géry Debongnie
2018-04-19 17:15:26 +02:00
parent 6c97aeee8d
commit b8bf945335
2 changed files with 32 additions and 0 deletions
@@ -347,6 +347,7 @@ var BasicModel = AbstractModel.extend({
var element = this.localData[id];
var isNew = this.isNew(id);
var rollback = 'rollback' in options ? options.rollback : isNew;
var initialOffset = element.offset;
this._visitChildren(element, function (elem) {
if (rollback && elem._savePoint) {
if (elem._savePoint instanceof Array) {
@@ -365,6 +366,7 @@ var BasicModel = AbstractModel.extend({
delete elem.tempLimitIncrement;
}
});
element.offset = initialOffset;
},
/**
* Duplicate a record (by calling the 'copy' route)
@@ -6525,5 +6525,35 @@ QUnit.module('Views', {
testUtils.unpatch(mixins.ParentedMixin);
});
QUnit.test('do not change pager when discarding current record', function (assert) {
assert.expect(2);
var form = createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form string="Partners">' +
'<field name="foo"/>' +
'</form>',
viewOptions: {
ids: [1, 2],
index: 0,
},
res_id: 2,
});
assert.strictEqual(form.pager.$('.o_pager_counter').text().trim(), '2 / 2',
'pager should indicate that we are on second record');
form.$buttons.find('.o_form_button_edit').click();
form.$buttons.find('.o_form_button_cancel').click();
assert.strictEqual(form.pager.$('.o_pager_counter').text().trim(), '2 / 2',
'pager should not have changed');
form.destroy();
});
});
});