[FIX] web: editable list: do not discard row on m2o blur

Let's assume an editable list with a many2one field. The user types
something in the many2one and then clicks outside (mousedown, not
mouseup, and thus click, yet). A dialog opens to ask the user if he
wants to quickcreate a record.

Before this commit, the dialog and the row disappeared as soon as
he released the click, because the click was considered by the
list renderer as an "external click", and the row was discarded
(alongside the many2one it contained).

Task 2411029

closes odoo/odoo#64053

X-original-commit: 7d04ec7cca4f355295a06c1ce6f112b6cc533c87
Signed-off-by: Géry Debongnie (ged) <ged@openerp.com>
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
Aaron Bohy
2021-01-05 09:15:47 +00:00
parent defa46715e
commit 766c9a5d57
2 changed files with 51 additions and 5 deletions
@@ -1805,12 +1805,12 @@ ListRenderer.include({
return;
}
// ignore clicks in modals, except if the list is in a modal, and the
// click is performed in that modal
var $clickModal = $(event.target).closest('.modal');
if ($clickModal.length) {
// ignore clicks if there is a modal, except if the list is in the last
// (active) modal
var $modal = $('.modal:last');
if ($modal.length) {
var $listModal = this.$el.closest('.modal');
if ($clickModal.prop('id') !== $listModal.prop('id')) {
if ($modal.prop('id') !== $listModal.prop('id')) {
return;
}
}
@@ -8206,6 +8206,52 @@ QUnit.module('Views', {
list.destroy();
});
QUnit.test('editable list with many2one: click out does not discard the row', async function (assert) {
// In this test, we simulate a long click by manually triggering a mousedown and later on
// mouseup and click events
assert.expect(5);
this.data.bar.fields.m2o = {string: "M2O field", type: "many2one", relation: "foo"};
const form = await createView({
View: FormView,
model: 'foo',
data: this.data,
arch: `
<form>
<field name="display_name"/>
<field name="o2m">
<tree editable="bottom">
<field name="m2o" required="1"/>
</tree>
</field>
</form>`,
});
assert.containsNone(form, '.o_data_row');
await testUtils.dom.click(form.$('.o_field_x2many_list_row_add > a'));
assert.containsOnce(form, '.o_data_row');
// focus and write something in the m2o
form.$('.o_field_many2one input').focus().val('abcdef').trigger('keyup');
await testUtils.nextTick();
// then simulate a mousedown outside
form.$('.o_field_widget[name="display_name"]').focus().trigger('mousedown');
await testUtils.nextTick();
assert.containsOnce(document.body, '.modal', "should ask confirmation to create a record");
// trigger the mouseup and the click
form.$('.o_field_widget[name="display_name"]').trigger('mouseup').trigger('click');
await testUtils.nextTick();
assert.containsOnce(document.body, '.modal', "modal should still be displayed");
assert.containsOnce(form, '.o_data_row', "the row should still be there");
form.destroy();
});
QUnit.test('list grouped by date:month', async function (assert) {
assert.expect(1);