From 019e11bb93c1ca29b1e7359992fa2f9d95e35627 Mon Sep 17 00:00:00 2001 From: "Julien Carion (juca)" Date: Tue, 21 Nov 2023 13:26:53 +0100 Subject: [PATCH] [FIX] web: m2o: always display 'No records' if no result found This commit fixes an issue where if one sets no_create_edit and no_quick_create to true on a m2o while no_create is unset, no dropdown is shown to tell the user that no record was found. Since the quick create and create and edit options are disabled by default when create is false, we no longer need it in the condition and can only rely on quick create and create and edit. task-3599696 closes odoo/odoo#143202 X-original-commit: 9da78c1b2bdd85f06e8682b99c8c481e91546ec7 Signed-off-by: Mathieu Duckerts-Antoine (dam) --- .../src/views/fields/relational_utils.js | 2 +- .../views/fields/many2one_field_tests.js | 35 +++++++++++++++++-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/addons/web/static/src/views/fields/relational_utils.js b/addons/web/static/src/views/fields/relational_utils.js index 268a9432653..4222fc95518 100644 --- a/addons/web/static/src/views/fields/relational_utils.js +++ b/addons/web/static/src/views/fields/relational_utils.js @@ -340,7 +340,7 @@ export class Many2XAutocomplete extends Component { }); } - if (!records.length && !this.activeActions.create) { + if (!records.length && !this.activeActions.createEdit && !this.props.quickCreate) { options.push({ label: _t("No records"), classList: "o_m2o_no_result", diff --git a/addons/web/static/tests/views/fields/many2one_field_tests.js b/addons/web/static/tests/views/fields/many2one_field_tests.js index 17a3cbe479a..e9ba4b51088 100644 --- a/addons/web/static/tests/views/fields/many2one_field_tests.js +++ b/addons/web/static/tests/views/fields/many2one_field_tests.js @@ -1117,14 +1117,45 @@ QUnit.module("Fields", (hooks) => { assert.containsOnce( target.querySelector(".o_field_many2one[name='trululu'] .dropdown-menu"), "li.o_m2o_start_typing", - "autocomplete should contains start typing option" + "autocomplete should contain start typing option" ); await click(target, ".o_field_many2one[name='product_id'] input"); assert.containsNone( target.querySelector(".o_field_many2one[name='product_id'] .dropdown-menu"), "li.o_m2o_start_typing", - "autocomplete should contains start typing option" + "autocomplete should not contain start typing option" + ); + }); + + QUnit.test("many2one with no_create_edit and no_quick_create options should show no records when no result match", async function (assert) { + assert.expect(2); + + await makeView({ + type: "form", + resModel: "partner", + serverData, + arch: ` +
+ + + + + +
`, + }); + + await click(target, ".o_field_many2one[name='product_id'] input"); + assert.containsNone( + target.querySelector(".o_field_many2one[name='product_id'] .dropdown-menu"), + "li.o_m2o_no_result", + "autocomplete should not contain the no records option" + ); + await editInput(target, ".o_field_many2one[name='product_id'] input", "aze"); + assert.containsOnce( + target.querySelector(".o_field_many2one[name='product_id'] .dropdown-menu"), + "li.o_m2o_no_result", + "autocomplete should contain the no records option" ); });