Skip to content

Commit

Permalink
[ADD] google_maps_drawing
Browse files Browse the repository at this point in the history
  • Loading branch information
brian10048 committed Mar 16, 2021
1 parent 4d8a964 commit cee1315
Show file tree
Hide file tree
Showing 17 changed files with 656 additions and 0 deletions.
35 changes: 35 additions & 0 deletions web_widget_google_map_drawing/README.rst
@@ -0,0 +1,35 @@
**This file is going to be generated by oca-gen-addon-readme.**

*Manual changes will be overwritten.*

Please provide content in the ``readme`` directory:

* **DESCRIPTION.rst** (required)
* INSTALL.rst (optional)
* CONFIGURE.rst (optional)
* **USAGE.rst** (optional, highly recommended)
* DEVELOP.rst (optional)
* ROADMAP.rst (optional)
* HISTORY.rst (optional, recommended)
* **CONTRIBUTORS.rst** (optional, highly recommended)
* CREDITS.rst (optional)

Content of this README will also be drawn from the addon manifest,
from keys such as name, authors, maintainers, development_status,
and license.

A good, one sentence summary in the manifest is also highly recommended.


Automatic changelog generation
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

`HISTORY.rst` can be auto generated using `towncrier <https://pypi.org/project/towncrier>`_.

Just put towncrier compatible changelog fragments into `readme/newsfragments`
and the changelog file will be automatically generated and updated when a new fragment is added.

Please refer to `towncrier` documentation to know more.

NOTE: the changelog will be automatically generated when using `/ocabot merge $option`.
If you need to run it manually, refer to `OCA/maintainer-tools README <https://github.com/OCA/maintainer-tools>`_.
1 change: 1 addition & 0 deletions web_widget_google_map_drawing/__init__.py
@@ -0,0 +1 @@
from . import models
25 changes: 25 additions & 0 deletions web_widget_google_map_drawing/__manifest__.py
@@ -0,0 +1,25 @@
{
'name': 'Google Map View Drawing Mixin',
'summary': 'Add drawing tools to Google Map view in Odoo',
'version': '12.0.1.0.0',
'author': 'Yopi Angi, Odoo Community Association (OCA)',
'website': 'https://github.com/OCA/geospatial',
'license': 'AGPL-3',
'category': 'Extra Tools',
'depends': [
'web_view_google_map',
],
'images': ['static/description/thumbnails.png'],
'data': [
'data/google_maps_library.xml',
'views/template.xml',
'views/res_config_settings_views.xml',
'security/ir.model.access.csv',
],
'qweb': ['static/src/xml/drawing.xml'],
'installable': True,
'maintainers': [
'gityopie',
'brian10048',
],
}
5 changes: 5 additions & 0 deletions web_widget_google_map_drawing/data/google_maps_library.xml
@@ -0,0 +1,5 @@
<odoo>
<data noupdate="1">
<function model="ir.config_parameter" name="set_param" eval="('google.maps_libraries', 'geometry,places,drawing')"/>
</data>
</odoo>
2 changes: 2 additions & 0 deletions web_widget_google_map_drawing/models/__init__.py
@@ -0,0 +1,2 @@
from . import res_config_settings
from . import drawing_mixin
24 changes: 24 additions & 0 deletions web_widget_google_map_drawing/models/drawing_mixin.py
@@ -0,0 +1,24 @@
from odoo import api, fields, models
from odoo.tools import safe_eval


class GoogleMapDrawingShapeMixin(models.AbstractModel):
_name = 'google.map.drawing.shape.mixin'
_description = 'Google Maps Shape Mixin'
_rec_name = 'shape_name'

shape_name = fields.Char(string='Name')
shape_area = fields.Float(string='Area')
shape_radius = fields.Float(string='Radius')
shape_description = fields.Text(string='Description')
shape_type = fields.Selection([
('circle', 'Circle'),
('polygon', 'Polygon'),
('rectangle', 'Rectangle')],
string='Type', default='polygon', required=True)
shape_paths = fields.Text(string='Paths')

@api.multi
def decode_shape_paths(self):
self.ensure_one()
return safe_eval(self.shape_paths)
41 changes: 41 additions & 0 deletions web_widget_google_map_drawing/models/res_config_settings.py
@@ -0,0 +1,41 @@
from odoo import api, models, fields


class ResConfigSettings(models.TransientModel):
_inherit = 'res.config.settings'

google_maps_drawing = fields.Boolean(string='Drawing')

@api.multi
def set_values(self):
super(ResConfigSettings, self).set_values()
ICPSudo = self.env['ir.config_parameter'].sudo()
libraries = self._set_google_maps_drawing()
ICPSudo.set_param('google.maps_libraries', libraries)

@api.model
def get_values(self):
res = super(ResConfigSettings, self).get_values()
lib_drawing = self._get_google_maps_drawing()
res['google_maps_drawing'] = lib_drawing
return res

@api.model
def _get_google_maps_drawing(self):
ICPSudo = self.env['ir.config_parameter'].sudo()
google_maps_libraries = ICPSudo.get_param(
'google.maps_libraries', default='')
libraries = google_maps_libraries.split(',')
return 'drawing' in libraries

@api.multi
def _set_google_maps_drawing(self):
ICPSudo = self.env['ir.config_parameter'].sudo()
google_maps_libraries = ICPSudo.get_param(
'google.maps_libraries', default='')
libraries = google_maps_libraries.split(',')
if self.google_maps_drawing:
libraries.append('drawing')

result = ','.join(libraries)
return result
2 changes: 2 additions & 0 deletions web_widget_google_map_drawing/readme/CONTRIBUTORS.rst
@@ -0,0 +1,2 @@
* Yopi Angi <yopiangi@gmail.com>
* Brian McMaster <brian@mcmpest.com>
11 changes: 11 additions & 0 deletions web_widget_google_map_drawing/readme/DESCRIPTION.rst
@@ -0,0 +1,11 @@
This module extends the Google Map web view in Odoo to allow users to draw
polygons, rectangles, and circles on the map.

[![Demo](https://i.ytimg.com/vi/DDUFT6XP8AU/2.jpg)](https://youtu.be/DDUFT6XP8AU "Demo")

More information about the drawing tools can be found [here](https://developers.google.com/maps/documentation/javascript/examples/drawing-tools)

This module will support three kind of shapes:
- [Rectangle](https://developers.google.com/maps/documentation/javascript/examples/rectangle-simple)
- [Polygon](https://developers.google.com/maps/documentation/javascript/examples/polygon-simple)
- [Circle](https://developers.google.com/maps/documentation/javascript/examples/polygon-simple)
68 changes: 68 additions & 0 deletions web_widget_google_map_drawing/readme/USAGE.rst
@@ -0,0 +1,68 @@
This module provides an extendable framework and cannot be used on its own.
The following provides information on how to implement it for your own module.

## Drawing Mixin

To ease the implementation of this feature, a mixin class has been defined that you can use in your model
.. code-black:: python
class GoogleMapsDrawingShapeMixin(models.AbstractModel):
_name = 'google_maps.drawing.shape.mixin'
_description = 'Google Maps Shape Mixin'
_rec_name = 'shape_name'

shape_name = fields.Char(string='Name')
shape_area = fields.Float(string='Area')
shape_radius = fields.Float(string='Radius')
shape_description = fields.Text(string='Description')
shape_type = fields.Selection([
('circle', 'Circle'), ('polygon', 'Polygon'),
('rectangle', 'Rectangle')], string='Type', default='polygon',
required=True)
shape_paths = fields.Text(string='Paths')

@api.multi
def decode_shape_paths(self):
self.ensure_one()
return safe_eval(self.shape_paths)

How to use the widget
.. code-block:: xml
<field name="shape_paths" widget="map_drawing_shape"/>
How to load shape(s) on `map` view
.. code-block:: xml
<record id="view_res_partner_area_map" model="ir.ui.view">
<field name="name">view.res.partner.area.map</field>
<field name="model">res.partner.area</field>
<field name="arch" type="xml">
<map library="drawing" string="Shape">
<field name="partner_id"/>
<field name="shape_name"/>
<field name="shape_description"/>
<field name="shape_type"/>
<field name="shape_radius"/>
<field name="shape_area"/>
<field name="shape_paths"/>
<templates>
<t t-name="kanban-box">
<div class="oe_kanban_global_click">
<div class="oe_kanban_details">
<strong class="o_kanban_record_title oe_partner_heading">
<field name="shape_name"/>
</strong>
<div>
<field name="shape_description"/>
</div>
<div attrs="{'invisible': [('shape_type', 'not in', ['rectangle', 'polygon'])]}">
Area: <field name="shape_area"/>
</div>
<div attrs="{'invisible': [('shape_type', '!=', 'circle')]}">
Radius: <field name="shape_radius"/>
</div>
</div>
</div>
</t>
</templates>
</map>
</field>
</record>
2 changes: 2 additions & 0 deletions web_widget_google_map_drawing/security/ir.model.access.csv
@@ -0,0 +1,2 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_web_google_maps_drawing_lines,access_web_google_maps_drawing_lines,model_web_google_maps_drawing_lines,base.group_user,1,1,1,1
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit cee1315

Please sign in to comment.