[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) <dam@odoo.com>
This commit is contained in:
Julien Carion (juca)
2023-11-23 01:20:11 +00:00
parent 4e7787b6f4
commit 019e11bb93
2 changed files with 34 additions and 3 deletions
@@ -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",
@@ -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: `
<form>
<sheet>
<group>
<field name="product_id" options="{'no_create_edit': 1, 'no_quick_create': 1}" />
</group>
</sheet>
</form>`,
});
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"
);
});