Ir al contenido
Odoo Menú
  • Identificarse
  • Pruébalo gratis
  • Aplicaciones
    Finanzas
    • Contabilidad
    • Facturación
    • Gastos
    • Hoja de cálculo (BI)
    • Documentos
    • Firma electrónica
    Ventas
    • CRM
    • Ventas
    • TPV para tiendas
    • TPV para restaurantes
    • Suscripciones
    • Alquiler
    Sitios web
    • Creador de sitios web
    • Comercio electrónico
    • Blog
    • Foro
    • Chat en directo
    • e-learning
    Cadena de suministro
    • Inventario
    • Fabricación
    • PLM
    • Compra
    • Mantenimiento
    • Calidad
    Recursos Humanos
    • Empleados
    • Reclutamiento
    • Ausencias
    • Evaluación
    • Referencias
    • Flota
    Marketing
    • Marketing social
    • Marketing por correo electrónico
    • Marketing por SMS
    • Eventos
    • Automatización de marketing
    • Encuestas
    Servicios
    • Proyecto
    • Partes de horas
    • Servicio de campo
    • Servicio de asistencia
    • Planificación
    • Citas
    Productividad
    • Conversaciones
    • Aprobaciones
    • IoT
    • VoIP
    • Conocimientos
    • WhatsApp
    Aplicaciones de terceros Studio de Odoo Plataforma de Odoo Cloud
  • Industrias
    Comercio al por menor
    • Librería
    • Tienda de ropa
    • Tienda de muebles
    • Tienda de ultramarinos
    • Ferretería
    • Juguetería
    Alimentación y hostelería
    • Bar y taberna
    • Restaurante
    • Comida rápida
    • Casa de huéspedes
    • Distribuidor de bebidas
    • Hotel
    Inmueble
    • Agencia inmobiliaria
    • Estudio de arquitectura
    • Construcción
    • Gestión inmobiliaria
    • Jardinería
    • Asociación de propietarios
    Consultoría
    • Empresa contable
    • Partner de Odoo
    • Agencia de marketing
    • Bufete de abogados
    • Adquisición de talentos
    • Auditorías y certificaciones
    Fabricación
    • Textil
    • Metal
    • Muebles
    • Alimentos
    • Brewery
    • Regalos de empresas
    Salud y bienestar
    • Club deportivo
    • Óptica
    • Gimnasio
    • Terapeutas
    • Farmacia
    • Peluquería
    Oficios
    • Handyman
    • Hardware y asistencia informática
    • Sistemas de energía solar
    • Zapatero
    • Servicios de limpieza
    • Servicios de calefacción, ventilación y aire acondicionado
    Otros
    • Organización sin ánimo de lucro
    • Agencia de protección del medio ambiente
    • Alquiler de paneles publicitarios
    • Estudio fotográfico
    • Alquiler de bicicletas
    • Distribuidor de software
    Explorar todos los sectores
  • Comunidad
    Aprender
    • Tutoriales
    • Documentación
    • Certificaciones
    • Formación
    • Blog
    • Podcast
    Potenciar la educación
    • Programa de formación
    • Scale Up! El juego empresarial
    • Visita Odoo
    Obtener el software
    • Descargar
    • Comparar ediciones
    • Versiones
    Colaborar
    • GitHub
    • Foro
    • Eventos
    • Traducciones
    • Convertirse en partner
    • Servicios para partners
    • Registrar tu empresa contable
    Obtener servicios
    • Encontrar un partner
    • Encontrar un asesor fiscal
    • Contacta con un experto
    • Servicios de implementación
    • Referencias de clientes
    • Ayuda
    • Actualizaciones
    GitHub YouTube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Solicitar una demostración
  • Precios
  • Ayuda

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

  • CRM
  • e-Commerce
  • Contabilidad
  • Inventario
  • PoS
  • Proyecto
  • MRP
All apps
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Ayuda

Cannot find the definition of component

Suscribirse

Reciba una notificación cuando haya actividad en esta publicación

Se marcó esta pregunta
javascriptdevelopmentOwl18.2
4 Respuestas
2044 Vistas
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
Descartar
Avatar
Cybrosys Techno Solutions Pvt.Ltd
Mejor respuesta

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
Descartar
Avatar
Abdelrahman Sadat
Autor Mejor respuesta

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
Descartar
Avatar
Bit Level Code
Mejor respuesta

    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
    Descartar
    Avatar
    Damien Hick
    Mejor respuesta

    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
    Descartar
    ¿Le interesa esta conversación? ¡Participe en ella!

    Cree una cuenta para poder utilizar funciones exclusivas e interactuar con la comunidad.

    Inscribirse
    Publicaciones relacionadas Respuestas Vistas Actividad
    How can I use my only web url domain using odoo?
    javascript development
    Avatar
    Avatar
    1
    sept 25
    1509
    How to Load Related Many2Many Data (pos.ticket.type) into the Frontend?
    javascript development
    Avatar
    0
    jun 25
    1824
    Odoo 18 POS - Discount Button Group Permissions Not Working
    javascript development
    Avatar
    Avatar
    2
    jun 25
    1986
    ¿Cómo puedo crear un Dashboard con KPIs y gráficos con Chart.js?
    javascript development
    Avatar
    0
    abr 25
    1953
    Odoo icon change Resuelto
    javascript development
    Avatar
    Avatar
    2
    ene 25
    2502
    Comunidad
    • Tutoriales
    • Documentación
    • Foro
    Código abierto
    • Descargar
    • GitHub
    • Runbot
    • Traducciones
    Servicios
    • Alojamiento Odoo.sh
    • Ayuda
    • Actualizar
    • Desarrollos personalizados
    • Educación
    • Encontrar un asesor fiscal
    • Encontrar un partner
    • Convertirse en partner
    Sobre nosotros
    • Nuestra empresa
    • Activos de marca
    • Contacta con nosotros
    • Puestos de trabajo
    • Eventos
    • Podcast
    • Blog
    • Clientes
    • Información legal • Privacidad
    • Seguridad
    الْعَرَبيّة 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 es un conjunto de aplicaciones de código abierto que cubren todas las necesidades de tu empresa: CRM, comercio electrónico, contabilidad, inventario, punto de venta, gestión de proyectos, etc.

    La propuesta única de valor de Odoo es ser muy fácil de usar y totalmente integrado.

    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