Overslaan naar inhoud
Odoo Menu
  • Aanmelden
  • Probeer het gratis
  • Apps
    Financiën
    • Boekhouding
    • Facturatie
    • Onkosten
    • Spreadsheet (BI)
    • Documenten
    • Ondertekenen
    Verkoop
    • CRM
    • Verkoop
    • Kassasysteem winkel
    • Kassasysteem Restaurant
    • Abonnementen
    • Verhuur
    Websites
    • Websitebouwer
    • E-commerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Bevoorradingsketen
    • Voorraad
    • Productie
    • PLM
    • Inkoop
    • Onderhoud
    • Kwaliteit
    Personeelsbeheer
    • Werknemers
    • Werving & Selectie
    • Verlof
    • Evaluaties
    • Aanbevelingen
    • Wagenpark
    Marketing
    • Sociale media-marketing
    • E-mailmarketing
    • Sms-marketing
    • Evenementen
    • Marketingautomatisering
    • Enquêtes
    Diensten
    • Project
    • Urenstaten
    • Buitendienst
    • Helpdesk
    • Planning
    • Afspraken
    Productiviteit
    • Chat
    • Goedkeuringen
    • IoT
    • VoIP
    • Kennis
    • WhatsApp
    Apps van derden Odoo Studio Odoo Cloud Platform
  • Bedrijfstakken
    Detailhandel
    • Boekhandel
    • kledingwinkel
    • Meubelzaak
    • Supermarkt
    • Bouwmarkt
    • Speelgoedwinkel
    Food & Hospitality
    • Bar en Pub
    • Restaurant
    • Fastfood
    • Gastenverblijf
    • Drankenhandelaar
    • Hotel
    Vastgoed
    • Makelaarskantoor
    • Architectenbureau
    • Bouw
    • Vastgoedbeheer
    • Tuinieren
    • Vereniging van eigenaren
    Consulting
    • Accountantskantoor
    • Odoo Partner
    • Marketingbureau
    • Advocatenkantoor
    • Talentenwerving
    • Audit & Certificering
    Productie
    • Textiel
    • Metaal
    • Meubels
    • Eten
    • Brewery
    • Relatiegeschenken
    Gezondheid & Fitness
    • Sportclub
    • Opticien
    • Fitnesscentrum
    • Wellness-medewerkers
    • Apotheek
    • Kapper
    Trades
    • Klusjesman
    • IT-hardware & support
    • Zonne-energiesystemen
    • Schoenmaker
    • Schoonmaakdiensten
    • HVAC-diensten
    Andere
    • Non-profitorganisatie
    • Milieuagentschap
    • Verhuur van Billboards
    • Fotograaf
    • Fietsleasing
    • Softwareverkoper
    Browse all Industries
  • Community
    Leren
    • Tutorials
    • Documentatie
    • Certificeringen
    • Training
    • Blog
    • Podcast
    Versterk het onderwijs
    • Onderwijs- programma
    • Scale Up! Business Game
    • Bezoek Odoo
    Download de Software
    • Downloaden
    • Vergelijk edities
    • Releases
    Werk samen
    • Github
    • Forum
    • Evenementen
    • Vertalingen
    • Word een Partner
    • Services for Partners
    • Registreer je accountantskantoor
    Diensten
    • Vind een partner
    • Vind een boekhouder
    • Een adviseur ontmoeten
    • Implementatiediensten
    • Klantreferenties
    • Ondersteuning
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Vraag een demo aan
  • Prijzen
  • Help

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

  • CRM
  • e-Commerce
  • Boekhouding
  • Voorraad
  • PoS
  • Project
  • MRP
All apps
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Alle posts Personen Badges
Labels (Bekijk alle)
odoo accounting v14 pos v15
Over dit forum
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Alle posts Personen Badges
Labels (Bekijk alle)
odoo accounting v14 pos v15
Over dit forum
Help

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

Inschrijven

Ontvang een bericht wanneer er activiteit is op deze post

Deze vraag is gerapporteerd
xmljspython3odoo11
2 Antwoorden
8169 Weergaven
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
Annuleer
Manish Bohra

Hello you find any solution related to this problem?

Avatar
DHA Medic
Beste antwoord

/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
Annuleer
Dev P
Auteur

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
Beste antwoord

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
Annuleer
Dev P
Auteur

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

Geniet je van het gesprek? Blijf niet alleen lezen, doe ook mee!

Maak vandaag nog een account aan om te profiteren van exclusieve functies en deel uit te maken van onze geweldige community!

Aanmelden
Gerelateerde posts Antwoorden Weergaven Activiteit
Is there any possible way to send notifications to discuss tab from an object based on conditions?
xml python3 odoo11 discuss
Avatar
Avatar
1
nov. 18
3652
How to show specific users related to a service?
xml res.users python3 odoo11
Avatar
Avatar
2
mrt. 18
5457
How to set a filter as default filter in odoo Opgelost
python3 odoo11
Avatar
Avatar
Avatar
2
feb. 24
16933
How to set default stage to when recruitement record is created Opgelost
python3 odoo11
Avatar
Avatar
1
dec. 22
5896
How to change the value of a field which depends on other fields automatically ? Opgelost
python3 odoo11
Avatar
Avatar
Avatar
2
dec. 22
15836
Community
  • Tutorials
  • Documentatie
  • Forum
Open Source
  • Downloaden
  • Github
  • Runbot
  • Vertalingen
Diensten
  • Odoo.sh Hosting
  • Ondersteuning
  • Upgrade
  • Gepersonaliseerde ontwikkelingen
  • Onderwijs
  • Vind een boekhouder
  • Vind een partner
  • Word een Partner
Over ons
  • Ons bedrijf
  • Merkelementen
  • Neem contact met ons op
  • Vacatures
  • Evenementen
  • Podcast
  • Blog
  • Klanten
  • Juridisch • Privacy
  • Beveiliging
الْعَرَبيّة 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 een suite van open source zakelijke apps die aan al je bedrijfsbehoeften voldoet: CRM, E-commerce, boekhouding, inventaris, kassasysteem, projectbeheer, enz.

Odoo's unieke waardepropositie is om tegelijkertijd zeer gebruiksvriendelijk en volledig geïntegreerd te zijn.

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