From 71d90f15b92c7c7ca19eee44e4bc02a24413ab23 Mon Sep 17 00:00:00 2001 From: Adrien Schoffeniels Date: Thu, 12 Jan 2023 08:13:21 +0000 Subject: [PATCH] [FIX] web: fix `create_name_field` option of many2one field component Purpose: ======== The `create_name_field` option of many2one fields in form views does not work: when setting it, the value entered in the many2one field is copied in the default `name` field, instead of in the field set, when clicking on the "Create and Edit" button. This is because an incorrect prop is used: the many2one component uses a prop named `createNameField` for that purpose, but passes a prop called `nameCreateField` to the Many2XAutocomplete component. This commit renames the `createNameField` prop of the many2one field to `nameCreateField`, to match the prop used in many2many_tags_field and in Many2XAutocomplete. Task-3113954 X-original-commit: c0ff0824d964cd702470076d31c066c5443ce9ca Part-of: odoo/odoo#110474 --- .../views/fields/many2one/many2one_field.js | 6 +-- .../views/fields/many2one_field_tests.js | 37 +++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/addons/web/static/src/views/fields/many2one/many2one_field.js b/addons/web/static/src/views/fields/many2one/many2one_field.js index 7141a89807b..ffeb238a9cc 100644 --- a/addons/web/static/src/views/fields/many2one/many2one_field.js +++ b/addons/web/static/src/views/fields/many2one/many2one_field.js @@ -257,7 +257,7 @@ Many2OneField.props = { canWrite: { type: Boolean, optional: true }, canQuickCreate: { type: Boolean, optional: true }, canCreateEdit: { type: Boolean, optional: true }, - createNameField: { type: String, optional: true }, + nameCreateField: { type: String, optional: true }, searchLimit: { type: Number, optional: true }, relation: { type: String, optional: true }, string: { type: String, optional: true }, @@ -270,7 +270,7 @@ Many2OneField.defaultProps = { canWrite: true, canQuickCreate: true, canCreateEdit: true, - createNameField: "name", + nameCreateField: "name", searchLimit: 7, string: "", canScanBarcode: false, @@ -298,7 +298,7 @@ Many2OneField.extractProps = ({ attrs, field }) => { canCreateEdit: canCreate && !noCreateEdit, relation: field.relation, string: attrs.string || field.string, - createNameField: attrs.options.create_name_field, + nameCreateField: attrs.options.create_name_field, canScanBarcode: canScanBarcode, openTarget: attrs.open_target, }; 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 468520b5a59..edab16595e1 100644 --- a/addons/web/static/tests/views/fields/many2one_field_tests.js +++ b/addons/web/static/tests/views/fields/many2one_field_tests.js @@ -3222,6 +3222,43 @@ QUnit.module("Fields", (hooks) => { assert.containsNone(target, ".modal", "should not display the create modal"); }); + QUnit.test("create_name_field option on a many2one", async function (assert) { + // when the 'create_name_field' option is set, the value entered in the + // many2one input should be used to populate this specified field, + // instead of the generic 'name' field. + serverData.views = { + "partner,false,form": ` +
+ + `, + }; + + await makeView({ + type: "form", + resModel: "partner", + serverData, + arch: ` +
+ + + +
`, + }); + + const input = target.querySelector(".o_field_widget[name=trululu] input"); + input.value = "yz"; + await triggerEvent(input, null, "input"); + await click(target, ".o_field_widget[name=trululu] input"); + await selectDropdownItem(target, "trululu", "Create and edit..."); + + assert.strictEqual( + target.querySelector(".o_field_widget[name=foo] input").value, + "yz" + ); + + await clickDiscard(target.querySelector(".modal")); + }); + QUnit.test("propagate can_create onto the search popup", async function (assert) { serverData.models.product.records = [ { id: 1, name: "Tromblon1" },