Passa al contenuto
Odoo Menu
  • Accedi
  • Provalo gratis
  • App
    Finanze
    • Contabilità
    • Fatturazione
    • Note spese
    • Fogli di calcolo (BI)
    • Documenti
    • Firma
    Vendite
    • CRM
    • Vendite
    • Punto vendita Negozio
    • Punto vendita Ristorante
    • Abbonamenti
    • Noleggi
    Siti web
    • Configuratore sito web
    • E-commerce
    • Blog
    • Forum
    • Live chat
    • E-learning
    Supply chain
    • Magazzino
    • Produzione
    • PLM
    • Acquisti
    • Manutenzione
    • Qualità
    Risorse umane
    • Dipendenti
    • Assunzioni
    • Ferie
    • Valutazioni
    • Referral dipendenti
    • Parco veicoli
    Marketing
    • Social marketing
    • E-mail marketing
    • SMS marketing
    • Eventi
    • Marketing automation
    • Sondaggi
    Servizi
    • Progetti
    • Fogli ore
    • Assistenza sul campo
    • Helpdesk
    • Pianificazione
    • Appuntamenti
    Produttività
    • Comunicazioni
    • Approvazioni
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    App di terze parti Odoo Studio Piattaforma cloud Odoo
  • Settori
    Retail
    • Libreria
    • Negozio di abbigliamento
    • Negozio di arredamento
    • Alimentari
    • Ferramenta
    • Negozio di giocattoli
    Cibo e ospitalità
    • Bar e pub
    • Ristorante
    • Fast food
    • Pensione
    • Grossista di bevande
    • Hotel
    Agenzia immobiliare
    • Agenzia immobiliare
    • Studio di architettura
    • Edilizia
    • Gestione immobiliare
    • Impresa di giardinaggio
    • Associazione di proprietari immobiliari
    Consulenza
    • Società di contabilità
    • Partner Odoo
    • Agenzia di marketing
    • Studio legale
    • Selezione del personale
    • Audit e certificazione
    Produzione
    • Tessile
    • Metallo
    • Arredamenti
    • Alimentare
    • Birrificio
    • Ditta di regalistica aziendale
    Benessere e sport
    • Club sportivo
    • Negozio di ottica
    • Centro fitness
    • Centro benessere
    • Farmacia
    • Parrucchiere
    Commercio
    • Tuttofare
    • Hardware e assistenza IT
    • Ditta di installazione di pannelli solari
    • Calzolaio
    • Servizi di pulizia
    • Servizi di climatizzazione
    Altro
    • Organizzazione non profit
    • Ente per la tutela ambientale
    • Agenzia di cartellonistica pubblicitaria
    • Studio fotografico
    • Punto noleggio di biciclette
    • Rivenditore di software
    Carica tutti i settori
  • Community
    Apprendimento
    • Tutorial
    • Documentazione
    • Certificazioni 
    • Formazione
    • Blog
    • Podcast
    Potenzia la tua formazione
    • Programma educativo
    • Scale Up! Business Game
    • Visita Odoo
    Ottieni il software
    • Scarica
    • Versioni a confronto
    • Note di versione
    Collabora
    • Github
    • Forum
    • Eventi
    • Traduzioni
    • Diventa nostro partner
    • Servizi per partner
    • Registra la tua società di contabilità
    Ottieni servizi
    • Trova un partner
    • Trova un contabile
    • Incontra un esperto
    • Servizi di implementazione
    • Testimonianze dei clienti
    • Supporto
    • Aggiornamenti
    GitHub Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Richiedi una demo
  • Prezzi
  • Aiuto

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

  • CRM
  • e-Commerce
  • Contabilità
  • Magazzino
  • PoS
  • Progetti
  • MRP
All apps
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
Assistenza

Fetching User's Location and Updating it Dynamically in Odoo 17 JavaScript Component

Iscriviti

Ricevi una notifica quando c'è un'attività per questo post

La domanda è stata contrassegnata
javascriptrpcgeolocationOWLodoo17
2750 Visualizzazioni
Avatar
Shawn Rodrigo

Hi all,

I’m working on a custom Odoo module to get the user's device location and update it on the server periodically. I’m using JavaScript with Odoo 17’s OWL framework and the useService hook for RPC calls. However, the functions in my component are not triggered as expected. I’d like to know if this is the correct approach or if there’s a recommended method for setting up periodic location updates in Odoo.

Here is my current code:

Javascript Component (location_updater.js)


/** @odoo-module */

import { useService } from '@web/core/utils/hooks';
import { Component } from '@odoo/owl';
import { registry } from "@web/core/registry";

export class LocationUpdater extends Component {
    static template = "odoo_live_location.location_updater_template";

    setup() {
        console.log("setup");
        this.rpc = useService("rpc");
        this.getAndUpdateLocation(1);
    }

    async updateLocationOnServer(latitude, longitude, recordId) {
        console.log("Updating location on server...");
        const response = await this.rpc({
            model: 'location.info',
            method: 'update_location',
            args: [[recordId], {
                'partner_latitude': latitude,
                'partner_longitude': longitude,
            }],
        });
        console.log("Location updated:", response);
    }

    async getAndUpdateLocation(recordId) {
        console.log("Fetching location...");
        if (navigator.geolocation) {
            navigator.geolocation.getCurrentPosition(async (position) => {
                const latitude = position.coords.latitude;
                const longitude = position.coords.longitude;
                await this.updateLocationOnServer(latitude, longitude, recordId);
                console.log('Location updated successfully!');
            }, (error) => {
                console.error("Error fetching location:", error);
            });
        } else {
            console.error("Geolocation is not supported by this browser.");
        }
    }
}

registry.category("actions").add("LocationUpdater", LocationUpdater);


Python Model (location_info.py)

from odoo import models, fields
class LocationInfo(models.Model):
​_name = 'location.info'
​_description = 'Location Information'

​partner_latitude = fields.Float("Latitude")
​partner_longitude = fields.Float("Longitude")

​def update_location(self, latitude, longitude): self.write({ 'partner_latitude': latitude, 'partner_longitude': longitude }) return True



XML View (location_info_view.xml)

<?xml version="1.0" encoding="UTF-8"?>
<odoo> <record id="view_location_info_form" model="ir.ui.view"> <field name="name">location.info.form</field> <field name="model">location.info</field> <field name="arch" type="xml"> <form string="Location Info"> <sheet> <group> <field name="partner_latitude"/> <field name="partner_longitude"/> </group> </sheet> </form> </field> </record> <record id="location_info_action" model="ir.actions.act_window"> <field name="name">Location Info</field> <field name="res_model">location.info</field> <field name="view_mode">form</field> </record> <menuitem id="location_info_menu" name="Location Info" action="location_info_action" /> </odoo>

The JavaScript functions in setup() are not triggering as expected. I don’t see any of the console log outputs from setup() or the subsequent methods.

I have also tried using registry.category("action_manager") instead of registry.category("actions") to register the component but didn’t see a difference.

Could anyone advise if there is something missing or if a different approach is recommended for this use case?

Thanks in advance!

0
Avatar
Abbandona
Ti stai godendo la conversazione? Non leggere soltanto, partecipa anche tu!

Crea un account oggi per scoprire funzionalità esclusive ed entrare a far parte della nostra fantastica community!

Registrati
Post correlati Risposte Visualizzazioni Attività
Learn OWL framework
javascript js OWL v17 odoo17
Avatar
Avatar
Avatar
2
lug 25
3377
How can I listen to the onFieldChange event in Odoo 17 using JavaScript?
javascript selected owl OWL odoo17
Avatar
0
mar 25
1721
Odoo17 Integrating Javascript with Python Risolto
javascript python integration rpc odoo17
Avatar
1
set 24
3116
py.eval in Javascript
javascript OWL
Avatar
0
gen 25
1908
odoo client error
javascript odoo17
Avatar
0
nov 24
2006
Community
  • Tutorial
  • Documentazione
  • Forum
Open source
  • Scarica
  • Github
  • Runbot
  • Traduzioni
Servizi
  • Hosting Odoo.sh
  • Supporto
  • Aggiornamenti
  • Sviluppi personalizzati
  • Formazione
  • Trova un contabile
  • Trova un partner
  • Diventa nostro partner
Chi siamo
  • La nostra azienda
  • Branding
  • Contattaci
  • Lavora con noi
  • Eventi
  • Podcast
  • Blog
  • Clienti
  • Note legali • Privacy
  • Sicurezza
الْعَرَبيّة 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 è un gestionale di applicazioni aziendali open source pensato per coprire tutte le esigenze della tua azienda: CRM, Vendite, E-commerce, Magazzino, Produzione, Fatturazione elettronica, Project Management e molto altro.

Il punto di forza di Odoo è quello di offrire un ecosistema unico di app facili da usare, intuitive e completamente integrate tra loro.

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