[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) <dle@odoo.com> Signed-off-by: Hubert Van De Walle <huvw@odoo.com>
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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: `
|
||||
<form>
|
||||
<sheet>
|
||||
<field name="product_id" options="{'no_create': 1}" readonly="0" />
|
||||
</sheet>
|
||||
</form>`,
|
||||
});
|
||||
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",
|
||||
|
||||
Reference in New Issue
Block a user