Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
10825 Widoki

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?

Awatar
Odrzuć
Najlepsza odpowiedź

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.

Awatar
Odrzuć
Autor

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.

Autor

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.

Powiązane posty Odpowiedzi Widoki Czynność
4
cze 21
7054
2
lut 23
1969
2
kwi 24
14667
2
wrz 15
5596
1
mar 15
3748