From b87e54bce4d7e148cc8978ce4150284520c1a1cc Mon Sep 17 00:00:00 2001 From: "Hubert Van de Walle (huvw)" Date: Mon, 9 Oct 2023 14:21:44 +0000 Subject: [PATCH] [FIX] web: no_create option ignored for many2one + many2many_tags fields Steps to reproduce ================== - Install purchase_product_matrix,web_studio - Go to purchase - Click on a record - Open studio - Click on the "Products" tab > Edit List view - Edit the product field - Widget: Many2one - Disable creation: enabled - Close studio - Create a new record - Add a new line - Type some random text in the product field -> The option create is available Cause of the issue ================== When the can_create attribute is not passed, the `canCreate` ends up undefined. This means the default value of true is used and the `no_create` option is ignored. The can_create attribute should actually be passed and there is a bug in python in the `_editable_tag_field` function, but it is not something we can change in stable due to the fact it it requires an explicit change in some views to pass the validation and thus, this requires an addon upgrade (`-u ...`). See https://github.com/odoo/odoo/pull/138032 opw-3432903 closes odoo/odoo#139068 X-original-commit: 4b6756e1775488e230bc25767adf5744f0ea9149 Signed-off-by: Denis Ledoux (dle) Signed-off-by: Hubert Van De Walle --- .../many2many_tags/many2many_tags_field.js | 2 +- .../views/fields/many2one/many2one_field.js | 2 +- .../views/fields/many2one_field_tests.js | 24 +++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/addons/web/static/src/views/fields/many2many_tags/many2many_tags_field.js b/addons/web/static/src/views/fields/many2many_tags/many2many_tags_field.js index 69e83eef398..9bea8be11e2 100644 --- a/addons/web/static/src/views/fields/many2many_tags/many2many_tags_field.js +++ b/addons/web/static/src/views/fields/many2many_tags/many2many_tags_field.js @@ -224,7 +224,7 @@ export const many2ManyTagsField = { }, extractProps({ attrs, options, string }, dynamicInfo) { const noCreate = Boolean(options.no_create); - const canCreate = attrs.can_create && evaluateBooleanExpr(attrs.can_create) && !noCreate; + const canCreate = noCreate ? false : attrs.can_create && evaluateBooleanExpr(attrs.can_create); const noQuickCreate = Boolean(options.no_quick_create); const noCreateEdit = Boolean(options.no_create_edit); return { 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 5db091a6d84..174263bceb3 100644 --- a/addons/web/static/src/views/fields/many2one/many2one_field.js +++ b/addons/web/static/src/views/fields/many2one/many2one_field.js @@ -366,7 +366,7 @@ export const many2OneField = { supportedTypes: ["many2one"], extractProps({ attrs, context, decorations, options, string }, dynamicInfo) { const canCreate = - attrs.can_create && evaluateBooleanExpr(attrs.can_create) && !options.no_create; + options.no_create ? false : attrs.can_create && evaluateBooleanExpr(attrs.can_create); return { placeholder: attrs.placeholder, canOpen: !options.no_open, 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 770a9bfa2da..65f81dfbd0a 100644 --- a/addons/web/static/tests/views/fields/many2one_field_tests.js +++ b/addons/web/static/tests/views/fields/many2one_field_tests.js @@ -3178,6 +3178,30 @@ QUnit.module("Fields", (hooks) => { ); }); + QUnit.test("no_create option on a many2one when can_create is absent", async function (assert) { + serverData.models.partner.fields.product_id.readonly = true; + await makeView({ + type: "form", + resModel: "partner", + serverData, + arch: ` +
+ + + +
`, + }); + await editInput(target, ".o_field_many2one input", "new partner"); + await triggerEvent(target, ".o_field_many2one input", "blur"); + + assert.containsNone(target, ".modal", "should not display the create modal"); + assert.strictEqual( + target.querySelector(".o_field_many2one input").value, + "", + "many2one value should cleared on focusout if many2one is no_create" + ); + }); + QUnit.test("can_create and can_write option on a many2one", async function (assert) { serverData.models.product.options = { can_create: "false",