Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add a Google Maps link in ODOO?

Tags:

xml

odoo

Hey I have one form so I wanted a google map view in odoo specially in HR Module I will be having address of all employees .So When I click on specific view it should show some view with map

like image 880
Shridhar Ivani Avatar asked Dec 15 '25 19:12

Shridhar Ivani


1 Answers

you have to inherit hr.employee and use odoo method for google_map is in res.partner.

like,

class hr_employee(osv.osv):
    _inherit = "hr.employee"

    _columns = {
        'map': fields.function(google_map_img, string='Map', type='text'),
    }
    def google_map_img(self, cr, uid, ids, name, args, context=None):
        employee = self.browse(cr, uid, ids[0], context=context)
        if employee.address_id:
            map_img_url = self.browse(cr, SUPERUSER_ID, ids[0], context=context).address_id.google_map_img()
            return {ids[0]: map_img_url}
        return None

here one functional field, that calculate the map data using partner address and return a map url.

using thism field you can easily render map on front-end using <img t-att-src="map"/>

but if you want to render it on back-end form view than you have to create a widget that render a image using generated url.(widget="image")

in google_map_img() method has extra parameter like zoom, height, width. change as per your need.

this two method are use for google map image and map link.

def google_map_img(...)
    pass
def google_map_link(...)
    pass

search this method in addons/website/models/website.py

if you use this methods then add website module in depends on your module in __openerp__.py

like image 172
i'm PosSible Avatar answered Dec 18 '25 01:12

i'm PosSible



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!