Я использую odoo 11 для этого. Я хочу отобразить геолокации по широте и долготе, которые будут получены с помощью кода JS. Сейчас мой JS-код загружается, но я не знаю, как напечатать его в форме, так как мне нужно сохранить местоположение в базе данных для дальнейшего использования. Я хочу отобразить широту и долготу в текстовом поле. Как будет .py файл соответственно? Мои извинения, поскольку я новичок здесь и в odoo.
Это мой код .xml.
<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="geolocation" 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="getLocation" string="Add Location" class="oe_highlight" type="object"/>
</div>
</group>
</sheet>
</form>
</field>
</record>
Это мой .py код.
импорт JSON
из odoo импортируем модели, поля, api
из odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT
с даты и времени импорта дата и время
класс 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")