Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

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

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

Displaying Latitude and Longitude using js, in odoo 11 form.

Subscriure's

Get notified when there's activity on this post

This question has been flagged
xmljspython3odoo11
2 Respostes
8004 Vistes
Avatar
Dev P

I am new to odoo, so please pardon if the question goes silly. I am trying to display latitude and longitude using a JS script. I'll need to fetch them for future use. I wanted them to get displayed in the text field and save them in my odoo form, But they are displayed in some random field.  If my approach is wrong please let me know the correct way, i'll surely implement that immediately.  

This is my view.xml file.

<record model="ir.ui.view" id="mobile_attendance.form">

      <field name="name">mobile_attendance form</field>

      <field name="model">mobile_attendance.mobile_attendance</field>

      <field name="arch" type="xml">

        <form id="geo_form">

          <sheet>

            <separator string="" colspan="4" col="6"/>

              <group string="Log Your Attendance">

                <field name="employee"/>

                <field name="datetime"/>

                <p id="demo1">

                  <field name="latitude"/>

                  <field name="longitude"/>

                </p>  

                <field name="google_map_partner" widget="map"/>


                <div>

                  <template id="geolocate" inherit_id="web.assets_backend" name="GeoLocation">

                    <xpath expr="." position="inside">

                      <!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"> </script> -->

                      <script type="text/javascript" xmlns:h="http://www.w3.org/1999/xhtml">

                        <![CDATA[

                        "use strict";

                        alert('Hello');


                        var x = document.getElementById("demo1").onclick = function() 

                        {getLocation()};


                        function getLocation()

                        {

                          if (navigator.geolocation) 

                          {

                            navigator.geolocation.getCurrentPosition(showPosition);

                          }

                          else

                          {

                            x.innerHTML = "Geolocation is not supported by this browser.";

                          }

                        }


                        function showPosition(position)

                        {

                          x.innerHTML = "Latitude: " + position.coords.latitude + "<br>Longitude: " + position.coords.longitude; 


                          latitude = position.coords.latitude<br>;

                          longitude = position.coords.longitude;


                          // trying to print location.


                        

                          document.getElementById("latitude").innerHTML = position.coords.latitude;

                          document.getElementById("longitude").innerHTML = position.coords.longitude;

                          //console.log(latitude);

                          //console.log(longitude);

                          }

                        ]]>

                      </script>

                    </xpath>

                  </template>

                  <button id="add_location" onclick="geolocate" string="Add Location" class="oe_highlight" type="object"/>

                </div>

              </group>

          </sheet>

        </form>

      </field>

    </record>


This is my python file.

import json

from odoo import models, fields, api

from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT

from datetime import datetime


class mobile_attendance(models.Model):

    _name = 'mobile_attendance.mobile_attendance'

    


    def _default_employee(self):

        return self.env['hr.employee'].search([('user_id', '=', self.env.uid)], limit=1)


    employee = fields.Many2one('hr.employee', string="Employee", default=_default_employee, required=True, ondelete='cascade', index=True)

    datetime = fields.Datetime('Datetime', default=lambda self: fields.Datetime.now(), readonly=True)



    latitude = fields.Char(string='Geo Latitude', digits=(16,5))

    longitude = fields.Char(string='Geo Longitude', digits=(16,5))

    google_map_partner = fields.Char(string="Map")

I see this error after the js is being loaded.

Uncaught TypeError: Cannot set property 'onclick' of null


I have added google map from now because, I also need to display those latitude and longitude on the google map.

1
Avatar
Descartar
Manish Bohra

Hello you find any solution related to this problem?

Avatar
DHA Medic
Best Answer

/your_module/your_path/test.js

odoo.define('web.mattendance', function(require) {
    "use strict";

$(document).on('change', 'input[name=ogtpql]' , function(e){
        alert("test");//this is input onchange, you try to find for button
    });
});



0
Avatar
Descartar
Dev P
Autor

Thank You for replying DHA Medic.

Can you please let me for what you have used 'input[name=ogtpql]' ?

Avatar
Cybrosys Techno Solutions Pvt.Ltd
Best Answer

Hi,

I think you should try jquery for capturing the click. It will be something like below,

$(document).ready(function(){
$('#demo1').click(function(){
//your code.
});
});


Thanks

0
Avatar
Descartar
Dev P
Autor

Thank You for your reply, but one more issue is that how to display it in odoo form. What can be done for that?

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Registrar-se
Related Posts Respostes Vistes Activitat
Is there any possible way to send notifications to discuss tab from an object based on conditions?
xml python3 odoo11 discuss
Avatar
Avatar
1
de nov. 18
3579
How to show specific users related to a service?
xml res.users python3 odoo11
Avatar
Avatar
2
de març 18
5347
How to set a filter as default filter in odoo Solved
python3 odoo11
Avatar
Avatar
Avatar
2
de febr. 24
16669
How to set default stage to when recruitement record is created Solved
python3 odoo11
Avatar
Avatar
1
de des. 22
5783
How to change the value of a field which depends on other fields automatically ? Solved
python3 odoo11
Avatar
Avatar
Avatar
2
de des. 22
15612
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة 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 és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

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