diff --git a/addons/web/static/src/views/fields/relational_utils.js b/addons/web/static/src/views/fields/relational_utils.js index 30b25d893b2..7cd890f2573 100644 --- a/addons/web/static/src/views/fields/relational_utils.js +++ b/addons/web/static/src/views/fields/relational_utils.js @@ -146,7 +146,15 @@ export class Many2XAutocomplete extends Component { fieldString, onClose: () => { const autoCompleteInput = autoCompleteContainer.el.querySelector("input"); - autoCompleteInput.value = ""; + + // There are two cases: + // 1. Value is the same as the input: it means the autocomplete has re-rendered with the right value + // This is in case we saved the record, triggering all the interface to update. + // 2. Value is different from the input: it means the input has a manually entered value and nothing + // happened, that is, we discarded the changes + if (this.props.value !== autoCompleteInput.value) { + autoCompleteInput.value = ""; + } autoCompleteInput.focus(); }, }); 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 2bf3046c82d..fbb9a585ccb 100644 --- a/addons/web/static/tests/views/fields/many2one_field_tests.js +++ b/addons/web/static/tests/views/fields/many2one_field_tests.js @@ -669,6 +669,54 @@ QUnit.module("Fields", (hooks) => { assert.strictEqual($("tr.o_data_row").length, 0, "should display 0 records"); }); + QUnit.test( + "many2ones in list views: create in dialog keeps the input", + async function (assert) { + serverData.views = { + "partner,false,form": ` +
`, + }; + + await makeView({ + type: "list", + resModel: "partner", + serverData, + arch: ` +