Good evening everyone, I have very little knowledge of JavaScript and I am new to Odoo 17.
I want to modify the following value:
const canCreate = options.no_create ? false : hasCreatePermission;
which is found here
export const many2OneField = {
component: Many2OneField,
displayName: _t("Many2one"),
supportedOptions: [
{
label: _t("Disable opening"),
name: "no_open",
type: "boolean",
},
{
label: _t("Disable creation"),
name: "no_create",
type: "boolean",
help: _t(
"If checked, users won't be able to create records through the autocomplete dropdown at all."
),
},
{
label: _t("Disable 'Create' option"),
name: "no_quick_create",
type: "boolean",
help: _t(
"If checked, users will not be able to create records based on the text input; they will still be able to create records via a popup form."
),
},
{
label: _t("Disable 'Create and Edit' option"),
name: "no_create_edit",
type: "boolean",
help: _t(
"If checked, users will not be able to create records based through a popup form; they will still be able to create records based on the text input."
),
},
],
supportedTypes: ["many2one"],
extractProps({ attrs, context, decorations, options, string }, dynamicInfo) {
const hasCreatePermission = attrs.can_create ? evaluateBooleanExpr(attrs.can_create) : true;
const hasWritePermission = attrs.can_write ? evaluateBooleanExpr(attrs.can_write) : true;
const canCreate = options.no_create ? false : hasCreatePermission;
return {
placeholder: attrs.placeholder,
canOpen: !options.no_open,
canCreate,
canWrite: hasWritePermission,
canQuickCreate: canCreate && !options.no_quick_create,
canCreateEdit: canCreate && !options.no_create_edit,
context: context,
decorations,
domain: dynamicInfo.domain,
nameCreateField: options.create_name_field,
canScanBarcode: !!options.can_scan_barcode,
string,
};
},
};
The code is located in odoo\addons\web\static\src\views\fields\many2one\many2one_field.js.
While researching, I came across discussions that recommend using patching to extend the object.
My patching code:
/** @odoo-module **/
import {many2OneField} from "@web/views/fields/many2one/many2one_field";
import { patch } from "@web/core/utils/patch";
patch(many2OneField, {
extractProps() {
let pros = super.extractProps()
pros.options.canCreate = true
return pros;
},
});
I don't know why it doesn't work, any help is welcome.
Thank you.
Check this references https://www.cybrosys.com/blog/how-to-patch-existing-owl-component-in-odoo-17