Skip to Content
Odoo Menu
  • Prijavi
  • Try it free
  • Aplikacije
    Finance
    • Knjigovodstvo
    • Obračun
    • Stroški
    • Spreadsheet (BI)
    • Dokumenti
    • Podpisovanje
    Prodaja
    • CRM
    • Prodaja
    • POS Shop
    • POS Restaurant
    • Naročnine
    • Najem
    Spletne strani
    • Website Builder
    • Spletna trgovina
    • Blog
    • Forum
    • Pogovor v živo
    • eUčenje
    Dobavna veriga
    • Zaloga
    • Proizvodnja
    • PLM
    • Nabava
    • Vzdrževanje
    • Kakovost
    Kadri
    • Kadri
    • Kadrovanje
    • Odsotnost
    • Ocenjevanja
    • Priporočila
    • Vozni park
    Marketing
    • Družbeno Trženje
    • Email Marketing
    • SMS Marketing
    • Dogodki
    • Avtomatizacija trženja
    • Ankete
    Storitve
    • Projekt
    • Časovnice
    • Storitve na terenu
    • Služba za pomoč
    • Načrtovanje
    • Termini
    Produktivnost
    • Razprave
    • Odobritve
    • IoT
    • Voip
    • Znanje
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industrije
    Trgovina na drobno
    • Book Store
    • Trgovina z oblačili
    • Trgovina s pohištvom
    • Grocery Store
    • Trgovina s strojno opremo računalnikov
    • Trgovina z igračami
    Food & Hospitality
    • Bar and Pub
    • Restavracija
    • Hitra hrana
    • Guest House
    • Beverage Distributor
    • Hotel
    Nepremičnine
    • Real Estate Agency
    • Arhitekturno podjetje
    • Gradbeništvo
    • Estate Management
    • Vrtnarjenje
    • Združenje lastnikov nepremičnin
    Svetovanje
    • Računovodsko podjetje
    • Odoo Partner
    • Marketinška agencija
    • Law firm
    • Pridobivanje talentov
    • Audit & Certification
    Proizvodnja
    • Tekstil
    • Metal
    • Pohištvo
    • Hrana
    • Brewery
    • Poslovna darila
    Health & Fitness
    • Športni klub
    • Trgovina z očali
    • Fitnes center
    • Wellness Practitioners
    • Lekarna
    • Frizerski salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Sistemi sončne energije
    • Izdelovalec čevljev
    • Čistilne storitve
    • HVAC Services
    Ostali
    • Neprofitna organizacija
    • Agencija za okolje
    • Najem oglasnih panojev
    • Fotografija
    • Najem koles
    • Prodajalec programske opreme
    Browse all Industries
  • Skupnost
    Learn
    • Tutorials
    • Dokumentacija
    • Certifikati
    • Šolanje
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Prenesi
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Dogodki
    • Prevodi
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Sklici kupca
    • Podpora
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Določanje cen
  • Pomoč

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Knjigovodstvo
  • Zaloga
  • PoS
  • Projekt
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
Pomoč

How to extend an object using the patch function?

Naroči se

Get notified when there's activity on this post

This question has been flagged
javascriptpatchodoo17
2 Odgovori
4654 Prikazi
Avatar
Afri Kreto

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.



0
Avatar
Opusti
Mily Shajan

Check this references https://www.cybrosys.com/blog/how-to-patch-existing-owl-component-in-odoo-17

Avatar
Cybrosys Techno Solutions Pvt.Ltd
Best Answer

Hi,

Please refer to the following blog for an understanding of the workings of patching, with an example:

https://www.cybrosys.com/blog/how-to-patch-existing-owl-component-in-odoo-17


Hope this helps.

0
Avatar
Opusti
Avatar
imam
Best Answer

Hello, 
In newer odoo, native javascript module, you can extend the option using extends keywords as you extends javascript class. 


For example here:

/** @odoo-module **/  // -> This indicate it's an odoo module. REQUIRED FOR ODOO MODULE.
import { registry } from '@web/core/registry'; //-> Use registry to register new fields
import {Many2OneField} from "@web/views/fields/many2one/many2one_field";; //-> Fields that's we inherite

export class YourNewField extends Many2OneField { //-> In here, we inherit the fields
​ extractProps({ attrs, context, decorations, options, string }, dynamicInfo) {
res = ​super.extractProps()
​ ​​res['canCreate'] = true
​} }
// After that don't forget to register your new widget
registry.category("fields").add("YourNewField", YourNewField);
0
Avatar
Opusti
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Prijavi
Related Posts Odgovori Prikazi Aktivnost
odoo client error
javascript odoo17
Avatar
0
nov. 24
1982
Extend _applyReward() in module pos_loyalty
javascript pos odoo17
Avatar
Avatar
2
jan. 25
1950
Save odoo website form content
javascript templates odoo17
Avatar
0
nov. 24
2289
Patch JS function that doesn't belong to a class Solved
javascript js patch
Avatar
1
nov. 24
6220
Odoo v17-18: Can you override a patch on another module in js on Solved
javascript pos patch Odoo 18
Avatar
Avatar
Avatar
2
sep. 25
1835
Community
  • Tutorials
  • Dokumentacija
  • Forum
Open Source
  • Prenesi
  • Github
  • Runbot
  • Prevodi
Services
  • Odoo.sh Hosting
  • Podpora
  • Nadgradnja
  • Custom Developments
  • Izobraževanje
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Sredstva blagovne znamke
  • Kontakt
  • Zaposlitve
  • Dogodki
  • Podcast
  • Blog
  • Stranke
  • Pravno • Zasebnost
  • Varnost
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now