[IMP] web: clear no_create enabled m2o field on focusout

Before this commit: if many2one field has no_create=True and user write
something to many2one field which does not exist and focusout of many2one
field then the text remain there on many2one input field, it creates
consution, it looks new record is created and set, so to avoid this
many2one field should be cleared if there is unmatch string and it has
no_create=True.

After this commit: if many2one has no_create=True and user types string
which does not have any match then on focusout many2one input element
will be cleared.

task-2517593

closes odoo/odoo#70173

Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
Mohammed Shekha
2021-05-28 10:39:32 +00:00
parent 50cb0f3276
commit b988fcdf06
2 changed files with 7 additions and 12 deletions
@@ -825,6 +825,8 @@ var FieldMany2One = AbstractField.extend({
this.reinitialize({ id: firstValue.id, display_name: firstValue.name });
} else if (this.can_create) {
new M2ODialog(this, this.string, this.$input.val()).open();
} else {
this.$input.val("");
}
},
/**
@@ -859,14 +861,6 @@ var FieldMany2One = AbstractField.extend({
this._updateExternalButton();
}
},
/**
* @override
* @private
*/
_onKeydown: function () {
this.floating = false;
this._super.apply(this, arguments);
},
/**
* @private
* @param {OdooEvent} event
@@ -2503,7 +2503,7 @@ QUnit.module('fields', {}, function () {
});
QUnit.test('no_create option on a many2one', async function (assert) {
assert.expect(1);
assert.expect(2);
var form = await createView({
View: FormView,
@@ -2516,10 +2516,11 @@ QUnit.module('fields', {}, function () {
'</form>',
});
await testUtils.fields.editAndTrigger(form.$('.o_field_many2one input'),
'new partner', ['keyup', 'focusout']);
await testUtils.nextTick();
await testUtils.fields.editInput(form.$('.o_field_many2one input'), 'new partner');
form.$('.o_field_many2one input').trigger('keyup').trigger('focusout');
assert.strictEqual($('.modal').length, 0, "should not display the create modal");
assert.strictEqual(form.$('.o_field_many2one input').val(), "",
"many2one value should cleared on focusout if many2one is no_create");
form.destroy();
});