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č

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

Naroči se

Get notified when there's activity on this post

This question has been flagged
javascriptrpcgeolocationOWLodoo17
2740 Prikazi
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
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
Learn OWL framework
javascript js OWL v17 odoo17
Avatar
Avatar
Avatar
2
jul. 25
3358
How can I listen to the onFieldChange event in Odoo 17 using JavaScript?
javascript selected owl OWL odoo17
Avatar
0
mar. 25
1712
Odoo17 Integrating Javascript with Python Solved
javascript python integration rpc odoo17
Avatar
1
sep. 24
3102
py.eval in Javascript
javascript OWL
Avatar
0
jan. 25
1906
odoo client error
javascript odoo17
Avatar
0
nov. 24
1994
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