odoo-addons
odoo-addons copied to clipboard
I am not able use in form view in V12
Hi I cannot use this map view in a form view I have a one2many field and I need to map those records inside map view, but map view is not comming what to do? please help me
Hi @midhunmadhuk
Please check the following use case of how to display map view inside a form
Assumed you have a new model called res.partner.location
and then relate this model to res.partner
model via field location_ids
defined as One2many
class ResPartnerLocation(models.Model):
_name = 'res.partner.location'
_description = 'Contact Location'
name = fields.Char()
partner_id = fields.Many2one(
comodel_name='res.partner',
required=True,
ondelete='cascade',
string='Contact'
)
latitude = fields.Float(string='Latitude', digits=(16, 5))
longitude = fields.Float(string='Longitude', digits=(16, 5))
class ResPartner(models.Model):
_inherit = 'res.partner'
location_ids = fields.One2many(
comodel_name='res.partner.location',
inverse_name='partner_id',
string='Locations',
)
Next on views definition, you append a new tab called Locations by inherit partner form view
<record id="view_res_partner_contacts_map_inherit" model="ir.ui.view">
<field name="name">view.res.partner.contacts.map.inherit</field>
<field name="model">res.partner</field>
<field name="priority">1000</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<xpath expr="//page[1]" position="after">
<page string="Locations">
<field name="location_ids" mode="map">
<map string="Locations" lat="latitude" lng="longitude">
<field name="name"/>
<field name="latitude"/>
<field name="longitude"/>
<field name="partner_id"/>
<templates>
<t t-name="kanban-box">
<div class="oe_kanban_global_click">
<div class="oe_kanban_details">
<strong class="o_kanban_record_title">
<field name="name"/>
</strong>
</div>
</div>
</t>
</templates>
</map>
<form string="Location" geo_field="{'lat': 'latitude', 'lng': 'longitude'}">
<sheet>
<group>
<group>
<field name="name"/>
<field name="partner_id"/>
</group>
<group>
<field name="latitude"/>
<field name="longitude"/>
</group>
</group>
</sheet>
</form>
</field>
</page>
</xpath>
</field>
</record>
The results will looks like this
Hope this helpful :)