[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
This commit is contained in:
Adrien Schoffeniels
2023-01-20 06:21:02 +01:00
parent 1358d9a115
commit 71d90f15b9
2 changed files with 40 additions and 3 deletions
@@ -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,
};
@@ -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": `
<form>
<field name="foo" />
</form>`,
};
await makeView({
type: "form",
resModel: "partner",
serverData,
arch: `
<form>
<sheet>
<field name="trululu" options="{'create_name_field': 'foo'}" />
</sheet>
</form>`,
});
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" },