Odoo Help

1 Answer

Brett Lehrer

--Brett Lehrer--

| 5 5 8
Milwaukee, United States
--Brett Lehrer--
Director of IT and open source enthusiast.
Brett Lehrer
21.10.13 15:10

This code works for me, and this is pretty much taken directly from the 6.1 code from what I recall:

from openerp.osv import osv,fields

class launch_map(osv.osv):
    _inherit = "res.partner"

    def open_map(self, cr, uid, ids, context=None):
        if context is None:
            context = {}

        partner = self.browse(cr, uid, ids[0], context=context)
        url = "http://maps.google.com/maps?oi=map&q="
        if partner.street:
            url += partner.street.replace(' ','+')
        if partner.city:
            url += '+'+partner.city.replace(' ','+')
        if partner.state_id:
            url += '+'+partner.state_id.name.replace(' ','+')
        if partner.country_id:
            url += '+'+partner.country_id.name.replace(' ','+')
        if partner.zip:
            url += '+'+partner.zip.replace(' ','+')

        return {
            'type': 'ir.actions.act_url',
            'url': url,
            'target': 'new'

In your view, just add a button on the partner that calls the open_map function. No more complicated than this:


<record model="ir.ui.view" id="view_partner_form_googlemaps">
    <field name="name">res.partner.form.googlemaps</field>
    <field name="model">res.partner</field>
    <field name="inherit_id" ref="base.view_partner_form"/>
    <field name="arch" type="xml">
        <xpath expr="//sheet/div[@name='buttons']" position="inside">
            <button name="open_map" string="Google Maps" type="object"/>


You can just add in your additional fields wherever they're necessary to fill out the address format in a single line, Google will take care of the rest.

Shaun Dawson
21.10.13 16:25

Works perfectly. Thanks so much for sharing. It's so simple, but I didn't know how object buttons worked. But I do now!

Brett Lehrer
21.10.13 17:19

object = python function defined in the object's class. A bit odd to think of it that way, though I understand why. Calling it a "function" there would've probably been more intuitive.

Shaun Dawson
21.10.13 17:24

The other piece of the puzzle that I needed, and didn't find documented anywhere was what the python function in question is supposed to return. In this case, a dictionary describing an ir_actions record, and that there was such a thing as an ir.actions.act_url that could open up a new window pointing to a particular URL. That's immensely helpful.

Ask a Question
Keep Informed
2 follower(s)
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now