[FIX] web: trigger a warning modal when deleting a line while editing in a one2many

In a one2many, if the user clicked the trash button while editing another line,
the row was not unselected.
Thus the modal was not triggered, which entailed that the currently edited line
was always saved.
In particular, it allowed to give empty values to required fields.

opw 1834346
This commit is contained in:
len-odoo
2018-07-06 07:52:52 +02:00
committed by len-odoo
parent 896e3f4c1e
commit c8474c8ab4
2 changed files with 46 additions and 2 deletions
@@ -841,8 +841,16 @@ ListRenderer.include({
*/
_onTrashIconClick: function (event) {
event.stopPropagation();
var id = $(event.target).closest('tr').data('id');
this.trigger_up('list_record_delete', {id: id});
var $row = $(event.target).closest('tr')
var id = $row.data('id');
if ($row.hasClass('o_selected_row')) {
this.trigger_up('list_record_delete', {id: id});
} else {
var self = this;
this.unselectRow().then(function () {
self.trigger_up('list_record_delete', {id: id});
});
}
},
/**
* When a click happens outside the list view, or outside a currently
@@ -3067,6 +3067,42 @@ QUnit.module('Views', {
form.destroy();
});
QUnit.test('delete a line in a one2many while editing another line triggers a warning', function (assert) {
assert.expect(3);
this.data.partner.records[0].p = [1, 2];
var form = createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form>' +
'<field name="p">' +
'<tree editable="bottom">' +
'<field name="display_name" required="True"/>' +
'</tree>' +
'</field>' +
'</form>',
res_id: 1,
});
form.$buttons.find('.o_form_button_edit').click();
form.$('.o_data_cell').first().click(); // edit first row
form.$('input').val('').trigger('input');
form.$('.fa-trash-o').eq(1).click(); // delete second row
assert.strictEqual($('.modal').find('.modal-title').first().text(), "Warning",
"Clicking out of a dirty line while editing should trigger a warning modal.");
$('.modal').find('.btn-primary').click(); // discard changes
assert.strictEqual(form.$('.o_data_cell').first().text(), "first record",
"Value should have been reset to what it was before editing began.");
assert.strictEqual(form.$('.o_data_row').length, 1,
"The other line should have been deleted.");
form.destroy();
});
QUnit.test('properly apply onchange on many2many fields', function (assert) {
assert.expect(14);