From b988fcdf061d76232b11ce07dd1679ad705a63ce Mon Sep 17 00:00:00 2001 From: Mohammed Shekha Date: Fri, 30 Apr 2021 12:06:33 +0000 Subject: [PATCH] [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) --- addons/web/static/src/js/fields/relational_fields.js | 10 ++-------- .../fields/relational_fields/field_many2one_tests.js | 9 +++++---- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/addons/web/static/src/js/fields/relational_fields.js b/addons/web/static/src/js/fields/relational_fields.js index 18d818c9418..40f16de2f22 100644 --- a/addons/web/static/src/js/fields/relational_fields.js +++ b/addons/web/static/src/js/fields/relational_fields.js @@ -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 diff --git a/addons/web/static/tests/fields/relational_fields/field_many2one_tests.js b/addons/web/static/tests/fields/relational_fields/field_many2one_tests.js index b892f28e0f2..bd3fa6d14d2 100644 --- a/addons/web/static/tests/fields/relational_fields/field_many2one_tests.js +++ b/addons/web/static/tests/fields/relational_fields/field_many2one_tests.js @@ -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 () { '', }); - 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(); });