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
    • Guest House
    • Distributeur de boissons
    • Hotel
    Real Estate
    • Real Estate Agency
    • Cabinet d'architecture
    • Construction
    • Gestion immobilière
    • Jardinage
    • Association de copropriétaires
    Consulting
    • Accounting Firm
    • Partenaire Odoo
    • Agence Marketing
    • Cabinet d'avocats
    • Aquisition de talents
    • Audit & Certification
    Fabrication
    • Textile
    • Metal
    • Furnitures
    • Food
    • 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
    • Solar Energy Systems
    • Cordonnier
    • Services de nettoyage
    • HVAC Services
    Others
    • Nonprofit Organization
    • 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

OWL : TypeError: this is undefined - ODOO 16 CE

S'inscrire

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

Cette question a été signalée
javascriptodooowl
1 Répondre
5934 Vues
Avatar
Nisanth N

Dear All,

I am getting an error when load a function. The intial page is loading without issue, after clicking the card-body, i am getting result in console.log(FloorId); 

My problem is when i pass the

this.state.tokenFloorId = FloorId; inside async selectFloor(data),
i am getting "Error fetching floor list: TypeError: this is undefined".



here is my function:

/** @odoo-module */

import { registry } from '@web/core/registry';
import { Component, useState, onMounted,onWillStart } from "@odoo/owl";
import rpc from 'web.rpc';

export class CallingToken extends Component {
setup() {
super.setup();
this.state = useState({
tokenTypeId: null,
tokenFloorId: null,
departmentId: null,
});
onMounted(this.fetchInitialData.bind(this));
//onWillStart(this.onWillStart);
}

async fetchInitialData() {
try {
const initialTokenTypeId = await rpc.query({
model: "token.issue.station.wizard",
method: 'fetch_token_type',
args: [1],
});
this.state.tokenTypeId = initialTokenTypeId;
} catch (error) {
console.error("Error fetching initial tokenTypeId:", error);
}
}

async selectFloor(data) {
try {
const FloorId = await rpc.query({
model: "token.issue.station.wizard",
method: 'fetch_floor_type',
args: [1, data],
});
console.log(FloorId);
this.state.tokenFloorId = FloorId;
} catch (error) {
console.error("Error fetching floor list:", error);
}
}
}

CallingToken.template = 'queue_management.CallingToken';
registry.category('actions').add('queue_management.action_call_token_js', CallingToken);

My template is :

t-name="queue_management.CallingToken" owl="1">
class="container-fluid bg-gradient">
class="row">

Token Issuing Page


class="row justify-content-center" name="token_table">
t-if="state.tokenTypeId">

Stations here
class="col-lg-6 col-md-8 col-sm-10 col-12 text-center">
t-foreach="state.tokenTypeId" t-as="data" t-key="data.rec_id">
class="tile mb-3">
class="card" t-on-click="() => selectFloor(data.rec_id)">
class="card-body" t-att-code="data.rec_id">
class="card-title">t-esc="data.token_type_name"/>

class="card-text">
t-esc="data.token_type_name"/>












t-if="state.tokenFloorId">

Select Floor
class="col-lg-6 col-md-8 col-sm-10 col-12 text-center">
t-foreach="state.tokenFloorId" t-as="floor" t-key="floor.rec_id">
class="card">
class="card-body">
class="card-title">t-esc="floor.floor_name"/>

class="card-text">
t-esc="floor.floor_name"/>








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

Hi,

In your case 'this' is not properly bound to your class's instance. it seems that 'this' is not correctly bound within the 'selectFloor' function. To ensure 'this' is correctly bound, you can use an arrow function for the 'selectFloor' method. You make sure that your class instance is correctly bound to 'this,'
import { registry } from '@web/core/registry';
import { Component, useState, onMounted } from "@odoo/owl";
import rpc from 'web.rpc';

export class CallingToken extends Component {
    setup() {
        super.setup();
        this.state = useState({
            tokenTypeId: null,
            tokenFloorId: null,
            departmentId: null,
        });
        onMounted(this.fetchInitialData.bind(this));
    }

    async fetchInitialData() {
        try {
            const initialTokenTypeId = await rpc.query({
                model: "token.issue.station.wizard",
                method: 'fetch_token_type',
                args: [1],
            });
            this.state.tokenTypeId = initialTokenTypeId;
        } catch (error) {
            console.error("Error fetching initial tokenTypeId:", error);
        }
    }

    selectFloor = async (data) => { // Use an arrow function
        try {
            const FloorId = await rpc.query({
                model: "token.issue.station.wizard",
                method: 'fetch_floor_type',
                args: [1, data],
            });
            console.log(FloorId);
            this.state.tokenFloorId = FloorId;
        } catch (error) {
            console.error("Error fetching floor list:", error);
        }
    }
}

CallingToken.template = 'queue_management.CallingToken';
registry.category('actions').add('queue_management.action_call_token_js', CallingToken);


Hope it helps

1
Avatar
Ignorer
Nisanth N
Auteur

Thank you.. working...

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é
Inherit the RewardButton class Js point of sale
javascript point_of_sale odoo owl
Avatar
Avatar
1
déc. 23
2352
Override Javascript Function in Odoo15
javascript odoo owl v15
Avatar
Avatar
1
oct. 23
4498
Save and get the value of variable from backend
javascript odoo
Avatar
0
août 23
194
Odoo use which javascript framework? Résolu
javascript odoo
Avatar
Avatar
1
févr. 22
3611
how to assign javascript value to odoo fields
javascript odoo
Avatar
0
août 18
6572
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