Se rendre au contenu
Menu
Cette question a été signalée
1 Répondre
10818 Vues

Using OpenERP 7.0, I have a custom module in which I have a number of address fields.

In the form view, I'd like have a button or a link to a google map for that address.

This seems quite straightforward, but I can't for the life of my figure out how to do it. I've taken a look at the google_maps module, but it doesn't seem to compile and/or import properly in to OpenERP 7.0, and the techniques that module uses don't seem to work anymore.

Any ideas?

Avatar
Ignorer
Meilleure réponse

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:

<openerp>
<data>

<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"/>
        </xpath>
    </field>
</record>

</data>
</openerp>

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.

Avatar
Ignorer
Auteur

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

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.

Auteur

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.

Publications associées Réponses Vues Activité
4
juin 21
7051
2
févr. 23
1962
2
avr. 24
14663
2
sept. 15
5593
1
mars 15
3745