Map on Form XML

How do I show Map in my form XML, i should be able to use Openstreetmap right?

So I make static js and html inside my module to show camera and this is my xml, but somehow it’s FORBIDDEN.

<?xml version="1.0"?>
<!-- This file is part of Tryton.  The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<form>
    <label name="company"/>
    <field name="company"/>
    <newline/>
    <label name="address"/>
    <field name="address"/>
    <newline/>
    <label name ="longitude"/>
    <field name="longitude"/>
    <label name ="latitude"/>
    <field name="latitude"/>
    <newline/>
    <label name="html_map"/>
    <field name="html_map" widget="html" readonly="1"/>
</form>

And this is the class from html_map in geolocation.py

class CompanyGeo(ModelSingleton, ModelSQL, ModelView):
    'Company Geo'
    __name__ = 'company.geo'

    company = fields.Many2One('company.company', "Company", required=True,
        help="The company the geolocation is associated with.")
    address = fields.Char('Address')
    longitude = fields.Float('Longitude', readonly =True )
    latitude = fields.Float('Latitude', readonly =True)
    max_distance = fields.Float('Max Distance (meters)', required=True,
        help="Maximum allowed distance in meters for face recognition.")
    html_map = fields.Function(fields.Char('Map'), 'get_html_map')

    @fields.depends('address')
    def on_change_with_coordinates(self):
        if not self.address:
            self.longitude = None
            self.latitude = None
            return

        geolocator = Nominatim(user_agent="attendanceapp")
        try:
            location = geolocator.geocode(self.address)
            if location:
                self.longitude = location.longitude
                self.latitude = location.latitude
            else:
                self.longitude = None
                self.latitude = None
        except GeocoderTimedOut:
            print("Geocoding service timed out. Try again later.")
            self.longitude = None
            self.latitude = None
        except Exception as e:
            print(f"An error occurred: {e}")
            self.longitude = None
            self.latitude = None
   

    def get_html_map(self, name):
        return '''
        <div id="map" style="height: 400px;"></div>
        <script src="https://unpkg.com/leaflet/dist/leaflet.js"></script>
        <link rel="stylesheet" href="https://unpkg.com/leaflet/dist/leaflet.css" />
        <script>
            var map = L.map('map').setView([%(latitude)s, %(longitude)s], 13);
            L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
                attribution: '&copy; OpenStreetMap contributors'
            }).addTo(map);
            var marker = L.marker([%(latitude)s, %(longitude)s]).addTo(map)
                .bindPopup('%(address)s')
                .openPopup();
        </script>
        ''' % {'latitude': self.latitude or 0, 'longitude': self.longitude or 0, 'address': self.address or ''}

The html widget is rendered as a button which open the HTML editor in the browser with the content of the field to be edited.

I already change the xml and it showed this.

This is my field in geolocation.py

    @classmethod
    def open_map(cls, records):
        return {
            'type': 'ir.actions.act_url',
            'url': '/modules/attendance/static/html/map.html',
            'target': 'new'
        }

This is my static map.html:


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Map</title>
    <link rel="stylesheet" href="https://unpkg.com/leaflet/dist/leaflet.css" />
    <style>
        #map {
            height: 400px;
            width: 100%;
        }
    </style>
</head>
<body>
    <div id="map"></div>
    <script src="https://unpkg.com/leaflet/dist/leaflet.js"></script>
    <script src="../js/map.js"></script>
</body>
</html>

and this is my map.js

var map = L.map('map').setView([0, 0], 2);

L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
    attribution: 'Map data &copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);

// Add marker if coordinates are available
if (longitude !== null && latitude !== null) {
    L.marker([latitude, longitude]).addTo(map);
}

trytond does not serve its own code as static page. You have to define explicit route or serve from another server.

I am sorry, I am kinda new in this field. What does this mean? Does it mean like making new web app?

First Tryton is not a web app, it is a business application which happens to have a web client.
So there is no real facilities to build web app directly in Tryton.

If you want to serve a web app, the simplest way is to serve it from your own web server. Usually Tryton is run behind a reverse-proxy which could probably be used to serve also your web application.

If you really want to serve the web application from Tryton, the simplest solution is to put your static pages in the [web] root folder (like sao).

Ah, I understand now. I was trying to geolocate my company to earn the latitude and the longitude, and i was going to show map in the user interface. i saw someone do it in tryton-discussion (i forgot where is it), but i cant find the way

There is GIS backend but there is no widget for the client.
Of course you can wrote client plugin to support them but it is not an easy task.