Skip to content

Commit

Permalink
Widget map first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
drkpkg committed Aug 14, 2024
1 parent ab9e6ba commit 0d82be7
Show file tree
Hide file tree
Showing 17 changed files with 907 additions and 0 deletions.
3 changes: 3 additions & 0 deletions web_widget_map/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-

from . import models
28 changes: 28 additions & 0 deletions web_widget_map/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
# Copyright 2024-2024 Felix Coca
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
'name': "Widget Map",
'summary': "Allow to use a map location as widget on the form views.",
"version": "17.0.1.0.0",
"license": "AGPL-3",
'author': "Felix Coca",
'website': "https://grandbastion.dev",
'category': 'Web',
'depends': ['web'],
'assets': {
'web.assets_backend': [
'map_field/static/src/components/**/*',
'map_field/static/src/css/map.scss',
],
'web.assets_common': [

],
'web.qunit_suite_tests': [
#'map_field/static/src/js/webclient_tests.js',
]
},
'license': 'AGPL-3',
}

3 changes: 3 additions & 0 deletions web_widget_map/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-

from . import map
52 changes: 52 additions & 0 deletions web_widget_map/models/map.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# -*- coding: utf-8 -*-

from odoo.fields import Field


class Map(Field):
"""
Map Widget
This new field type is used to store a Google Map location.
The field is stored as a text field in the database, and the value is a string in the format:
"latitude,longitude"
where latitude and longitude are float values.
The field is displayed as a map in the form view, and the user can click on the map to set the location.
The field is displayed as a link in the tree view, and the user can click on the link to open the location in Google Maps.
The field is displayed as a map in the Kanban view, and the user can click on the map to set the location.
"""

type = "point"
# Postgresql column type https://www.postgresql.org/docs/current/datatype.html
column_type = ("point", "point")

def _get_attrs(self, model_class, name):
res = super()._get_attrs(model_class, name)
return res

def convert_to_record(self, value, record, validate=True):
return value or None

def _update(self, records, value):
cache = records.env.cache
for record in records:
cache.set(record, self, value.id or None)

def convert_to_export(self, value, record):
return value or None

@staticmethod
def to_lat_lon(value: str):
"""
Parse the value "(latitude, longitude)" to a tuple (latitude, longitude)
"""
if value:
res = value.replace("(").replace(")").split(",")
return float(res[0]), float(res[1])
return None
3 changes: 3 additions & 0 deletions web_widget_map/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added web_widget_map/static/lib/leaflet/images/layers.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 0d82be7

Please sign in to comment.