[FIX] web: x2m: properly reset limit/offset to initial value
When we discard an element, we want to make sure that the new state is not corrupted by previous user operations. In our case, we possibly had a limit and an offset values modified by the user. This could lead to unpleasant situations, with incorrect data displayed on the form view. Note that this actually fixes a new bug introduced by commit https://github.com/odoo/odoo/commit/e7fab234201e357da52c3576ad2e8fc9ceee9359 (this is the commit that introduces the tempLimitIncrement attribute)
This commit is contained in:
@@ -359,6 +359,11 @@ var BasicModel = AbstractModel.extend({
|
||||
elem._changes = null;
|
||||
elem._isDirty = false;
|
||||
}
|
||||
elem.offset = 0;
|
||||
if (elem.tempLimitIncrement) {
|
||||
elem.limit -= elem.tempLimitIncrement;
|
||||
delete elem.tempLimitIncrement;
|
||||
}
|
||||
});
|
||||
},
|
||||
/**
|
||||
|
||||
@@ -4361,6 +4361,39 @@ QUnit.module('relational_fields', {
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('editable one2many list, adding line, then discarding', function (assert) {
|
||||
assert.expect(1);
|
||||
|
||||
this.data.turtle.records.push({id:4, turtle_foo: 'stephen hawking'});
|
||||
this.data.partner.records[0].turtles = [1,2,3,4];
|
||||
|
||||
var form = createView({
|
||||
View: FormView,
|
||||
model: 'partner',
|
||||
data: this.data,
|
||||
arch: '<form string="Partners">' +
|
||||
'<field name="turtles">' +
|
||||
'<tree editable="bottom" limit="3">' +
|
||||
'<field name="turtle_foo"/>' +
|
||||
'</tree>' +
|
||||
'</field>' +
|
||||
'</form>',
|
||||
res_id: 1,
|
||||
});
|
||||
|
||||
// add a record, then discard
|
||||
form.$buttons.find('.o_form_button_edit').click();
|
||||
form.$('.o_field_x2many_list_row_add a').click();
|
||||
form.$buttons.find('.o_form_button_cancel').click();
|
||||
|
||||
// confirm the discard operation
|
||||
$('.modal .modal-footer .btn-primary').click(); // click on confirm
|
||||
|
||||
assert.strictEqual(form.$('.o_cp_pager').text().trim(), '1-3 / 4',
|
||||
"pager should still be visible");
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('editable one2many list, required field and pager', function (assert) {
|
||||
assert.expect(1);
|
||||
|
||||
@@ -4438,6 +4471,47 @@ QUnit.module('relational_fields', {
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('editable one2many list, adding, discarding, and pager', function (assert) {
|
||||
assert.expect(2);
|
||||
|
||||
this.data.partner.records[0].turtles = [1];
|
||||
|
||||
var form = createView({
|
||||
View: FormView,
|
||||
model: 'partner',
|
||||
data: this.data,
|
||||
arch: '<form string="Partners">' +
|
||||
'<field name="turtles">' +
|
||||
'<tree editable="bottom" limit="3">' +
|
||||
'<field name="turtle_foo"/>' +
|
||||
'</tree>' +
|
||||
'</field>' +
|
||||
'</form>',
|
||||
res_id: 1,
|
||||
});
|
||||
|
||||
// add a 4 records record (to make the pager appear)
|
||||
form.$buttons.find('.o_form_button_edit').click();
|
||||
form.$('.o_field_x2many_list_row_add a').click();
|
||||
form.$('.o_field_x2many_list_row_add a').click();
|
||||
form.$('.o_field_x2many_list_row_add a').click();
|
||||
form.$('.o_field_x2many_list_row_add a').click();
|
||||
|
||||
// go on next page
|
||||
form.$('.o_pager_next').click();
|
||||
|
||||
// discard
|
||||
form.$buttons.find('.o_form_button_cancel').click();
|
||||
$('.modal .modal-footer .btn-primary').click();
|
||||
|
||||
assert.strictEqual(form.$('tr.o_data_row').length, 1,
|
||||
"should have 1 data row");
|
||||
assert.ok(!form.$('.o_cp_pager').is(':visible'),
|
||||
"pager should not be visible");
|
||||
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('unselecting a line with missing required data', function (assert) {
|
||||
assert.expect(5);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user