Se rendre au contenu
Odoo Menu
  • Se connecter
  • Essai gratuit
  • Applications
    Finance
    • Comptabilité
    • Facturation
    • Notes de frais
    • Feuilles de calcul (BI)
    • Documents
    • Signature
    Ventes
    • CRM
    • Ventes
    • PdV Boutique
    • PdV Restaurant
    • Abonnements
    • Location
    Sites web
    • Site Web
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Chaîne d'approvisionnement
    • Inventaire
    • Fabrication
    • PLM
    • Achats
    • Maintenance
    • Qualité
    Ressources Humaines
    • Employés
    • Recrutement
    • Congés
    • Évaluations
    • Recommandations
    • Parc automobile
    Marketing
    • Marketing Social
    • E-mail Marketing
    • SMS Marketing
    • Événements
    • Marketing Automation
    • Sondages
    Services
    • Projet
    • Feuilles de temps
    • Services sur Site
    • Assistance
    • Planification
    • Rendez-vous
    Productivité
    • Discussion
    • Validations
    • Internet des Objets
    • VoIP
    • Connaissances
    • WhatsApp
    Applications tierces Odoo Studio Plateforme Cloud d'Odoo
  • Industries
    Commerce de détail
    • Librairie
    • Magasin de vêtements
    • Magasin de meubles
    • Épicerie
    • Quincaillerie
    • Magasin de jouets
    Food & Hospitality
    • Bar et Pub
    • Restaurant
    • Fast-food
    • Maison d’hôtes
    • Distributeur de boissons
    • Hôtel
    Immobilier
    • Agence immobilière
    • Cabinet d'architecture
    • Construction
    • Gestion immobilière
    • Jardinage
    • Association de copropriétaires
    Consultance
    • Cabinet d'expertise comptable
    • Partenaire Odoo
    • Agence Marketing
    • Cabinet d'avocats
    • Aquisition de talents
    • Audit & Certification
    Fabrication
    • Textile
    • Métal
    • Meubles
    • Alimentation
    • Brewery
    • Cadeaux d'entreprise
    Santé & Fitness
    • Club de sports
    • Opticien
    • Salle de fitness
    • Praticiens bien-être
    • Pharmacie
    • Salon de coiffure
    Trades
    • Bricoleur
    • Matériel informatique et support
    • Systèmes photovoltaïques
    • Cordonnier
    • Services de nettoyage
    • Services CVC
    Autres
    • Organisation à but non lucratif
    • Agence environnementale
    • Location de panneaux d'affichage
    • Photographie
    • Leasing de vélos
    • Revendeur de logiciel
    Browse all Industries
  • Communauté
    Apprenez
    • Tutoriels
    • Documentation
    • Certifications
    • Formation
    • Blog
    • Podcast
    Renforcer l'éducation
    • Programme éducatif
    • Business Game Scale-Up!
    • Rendez-nous visite
    Obtenir le logiciel
    • Téléchargement
    • Comparez les éditions
    • Versions
    Collaborer
    • Github
    • Forum
    • Événements
    • Traductions
    • Devenez partenaire
    • Services for Partners
    • Enregistrer votre cabinet comptable
    Nos Services
    • Trouver un partenaire
    • Trouver un comptable
    • Rencontrer un conseiller
    • Services de mise en œuvre
    • Références clients
    • Assistance
    • Mises à niveau
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obtenir une démonstration
  • Tarification
  • Aide

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

  • CRM
  • e-Commerce
  • Comptabilité
  • Inventaire
  • PoS
  • Projet
  • MRP
All apps
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Aide

Cannot find the definition of component

S'inscrire

Recevez une notification lorsqu'il y a de l'activité sur ce poste

Cette question a été signalée
javascriptdevelopmentOwl18.2
4 Réponses
2034 Vues
Avatar
Abdelrahman Sadat

I'm creating an Owl component that I'd like to use to extend(inherit) to a contacts view. However, whenever I try to load the relevant page that has my new component, I get an error  UncaughtPromiseError > OwlError  Cannot find the definition of component "DialButton"​. And I'm not sure what might be missing.

 
My code looks like this

The xml:

<?xml version="1.0" encoding="UTF-8"?>

<templates xml:space="preserve">

    <t t-name="efcx.DialButton">

      <a class="ms-3 d-inline-flex align-items-center">

        <i class="fa fa-phone"></i><small class="fw-bold ms-1">Call efcx</small>

      </a>

    </t>

</templates>


The JS:

/** @odoo-module **/

import { registry } from "@web/core/registry";

import { Component } from "@odoo/owl";


export class DialButton extends Component {  

  static template = "efcx.DialButton";

   setup() {

      super.setup(...arguments);

   }

   _dial(){

      console.log("Dialing...");

   }

}

export const fieldButton = { Component: DialButton, };

registry.add("DialButton", fieldButton);

console.log(registry.get("DialButton"))


The inheritance view (to extend the contact view):

<templates xml:space="preserve">

    <t t-inherit="web.PhoneField" t-inherit-mode="extension">

        <xpath expr="//div[hasclass('o_phone_content')]//a" position="after">

            <DialButton/>

        </xpath>

    </t>

    <t t-inherit="web.FormPhoneField" t-inherit-mode="extension">

        <xpath expr="//div[hasclass('o_phone_content')]" position="inside">

            <DialButton/>

        </xpath>

    </t>

</templates>


And finally, the portions of the manifest where I'm adding the files:

'assets': {

​'web.assets_backend': [

​ ​'efcx/static/src/js/dial_button.js',

​ ​'efcx/static/src/xml/dial_button.xml',

​ ​'efcx/static/src/views/fields/phone_field.xml',

​]


Is the component not added to the registry properly? Do I need to update the manifest? I would appreciate any help pointing out the issue 🙏



0
Avatar
Ignorer
Avatar
Cybrosys Techno Solutions Pvt.Ltd
Meilleure réponse

Hi,


You are registering your DialButton with:

       registry.add("DialButton", fieldButton);


but you didn't specify which registry.

By default, registry is a collection of registries like category("fields"), category("components"), category("views"), etc.


For OWL components, you must register inside a specific category, normally "components".


Here is updated JS Code:



/** @odoo-module **/


import { registry } from "@web/core/registry";

import { Component } from "@odoo/owl";


export class DialButton extends Component {

    static template = "efcx.DialButton";


    setup() {

        super.setup(...arguments);

    }


    _dial() {

        console.log("Dialing...");

    }

}


// CORRECT way: register inside the "components" category

registry.category("components").add("DialButton", DialButton);



Hope this helps

0
Avatar
Ignorer
Avatar
Abdelrahman Sadat
Auteur Meilleure réponse

Solved by adding a js file to patch the component I was trying to extend:
See the Reference->Web Framework->Patching Code section in the documentation (can't paste link due to low karma).

Added code looks something like this:

/** @odoo-module **/

// taken from @sms/static/src/components/phone_field/phone_field.js


import { patch } from "@web/core/utils/patch";

import { PhoneField, phoneField, formPhoneField } from "@web/views/fields/phone/phone_field";

import { DialButton } from './dial_button.js';


patch(PhoneField, {

    components: {

        ...PhoneField.components,

        DialButton

    },

    defaultProps: {

        ...PhoneField.defaultProps,

    },

    props: {

        ...PhoneField.props,

    },

});


const patchDescr = () => ({

    extractProps() {

        const props = super.extractProps(...arguments);

        return props;

    },

    supportedOptions: [],

});


patch(phoneField, patchDescr());

patch(formPhoneField, patchDescr());

0
Avatar
Ignorer
Avatar
Bit Level Code
Meilleure réponse

    Main Issues

    • Component Registration: You're registering the component in the wrong way. For Owl components used in views, you need to register them differently.
    • Component Import: Your inheritance view is trying to use <DialButton/> directly, but it needs to be properly imported and registered to be available.
    • XML Namespace: The XML files need to ensure proper namespacing so Odoo can find your component.
  • Here's how to fix these issues:

    First, let's modify your dial_button.js file:

javascript

/** @odoo-module **/

import { registry } from "@web/core/registry";
import { Component } from "@odoo/owl";

export class DialButton extends Component {
    static template = "efcx.DialButton";
    
    setup() {
        // Note: You don't need super.setup() for Component
    }
    
    dial() {
        console.log("Dialing...");
    }
}

// Register the component in the component registry (not as a field)
registry.category("components").add("DialButton", DialButton);

Next, you need to make sure your XML inheritance properly imports the component:

xml

<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
    <t t-extend="web.PhoneField" t-inherit-mode="extension">
        <xpath expr="//div[hasclass('o_phone_content')]//a" position="after">
            <t t-component="components.DialButton"/>
        </xpath>
    </t>
    <t t-extend="web.FormPhoneField" t-inherit-mode="extension">
        <xpath expr="//div[hasclass('o_phone_content')]" position="inside">
            <t t-component="components.DialButton"/>
        </xpath>
    </t>
</templates>

Additionally, you might need to create a separate JS file to import and register the component for your views:

javascript

/** @odoo-module **/

import { registry } from "@web/core/registry";
import { DialButton } from "./dial_button";

// Make the component available to templates
const components = registry.category("components");
if (!components.contains("DialButton")) {
    components.add("DialButton", DialButton);
}

Make sure your manifest includes all these files in the correct order:

python

'assets': {
    'web.assets_backend': [
        'efcx/static/src/js/dial_button.js',
        'efcx/static/src/js/register_components.js',  # Add this new file
        'efcx/static/src/xml/dial_button.xml',
        'efcx/static/src/views/fields/phone_field.xml',
    ],
}

If you're still encountering issues, try these additional debugging steps:

    • Check the browser console to see if your console.log(registry.get("DialButton")) is showing your component
    • Try accessing it as registry.category("components").get("DialButton")
    • Make sure you've cleared your browser cache or used incognito mode to test
    • Restart the Odoo server to ensure all assets are properly rebuilt
  • 0
    Avatar
    Ignorer
    Avatar
    Damien Hick
    Meilleure réponse

    Hi,

    i'm not sure to correctly respond to the whole problem but i thought that in all view it was compulsary to define the starting and ending xml "balise".
    You define your empty "balise" in a way that i'm not sure Odoo loves it :

    <DialButton/>

    I can suggest to try first with a starting and ending, like here :

    <DialButton></DialButton>

    Hope it'll help.

    0
    Avatar
    Ignorer
    Vous appréciez la discussion ? Ne vous contentez pas de lire, rejoignez-nous !

    Créez un compte dès aujourd'hui pour profiter de fonctionnalités exclusives et échanger avec notre formidable communauté !

    S'inscrire
    Publications associées Réponses Vues Activité
    How can I use my only web url domain using odoo?
    javascript development
    Avatar
    Avatar
    1
    sept. 25
    1488
    How to Load Related Many2Many Data (pos.ticket.type) into the Frontend?
    javascript development
    Avatar
    0
    juin 25
    1809
    Odoo 18 POS - Discount Button Group Permissions Not Working
    javascript development
    Avatar
    Avatar
    2
    juin 25
    1971
    ¿Cómo puedo crear un Dashboard con KPIs y gráficos con Chart.js?
    javascript development
    Avatar
    0
    avr. 25
    1948
    Odoo icon change Résolu
    javascript development
    Avatar
    Avatar
    2
    janv. 25
    2493
    Communauté
    • Tutoriels
    • Documentation
    • Forum
    Open Source
    • Téléchargement
    • Github
    • Runbot
    • Traductions
    Services
    • Hébergement Odoo.sh
    • Assistance
    • Migration
    • Développements personnalisés
    • Éducation
    • Trouver un comptable
    • Trouver un partenaire
    • Devenez partenaire
    À propos
    • Notre société
    • Actifs de la marque
    • Contactez-nous
    • Emplois
    • Événements
    • Podcast
    • Blog
    • Clients
    • Informations légales • Confidentialité
    • Sécurité.
    الْعَرَبيّة 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 est une suite d'applications open source couvrant tous les besoins de votre entreprise : CRM, eCommerce, Comptabilité, Inventaire, Point de Vente, Gestion de Projet, etc.

    Le positionnement unique d'Odoo est d'être à la fois très facile à utiliser et totalement intégré.

    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