Skip to Content
Menu
This question has been flagged
2 Replies
5252 Views

i inherit res.partner and i have field , i want to replace that field city with my city_id i use this code below

class ResPartner(models.Model):
_inherit = 'res.partner'
    city_id = fields.Many2one('res.city', string='City')
my xml

<record id="view_partner_form_inherit_tawssil" model="ir.ui.view">
<field name="name">res.partner.form.inherit.tawssil</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='city']" position="replace">
<field name="city_id" placeholder="City" context="{'default_city': active_id}"/>
</xpath>
</record>
but i had the error 
Field 'city' used in attributes must be present in view but is missing:
- 'city' in context="{'default_parent_id': active_id, 'default_street': street, 'default_street2': street2, 'default_city': city, 'default_state_id': state_id, 'default_zip': zip, 'default_country_id': country_id, 'default_supplier': supplier, 'default_customer': customer, 'default_lang': lang, 'default_user_id': user_id}"
Avatar
Discard
Best Answer

I think the problem is with the context="{'default_city': active_id}". Try to remove that.

Avatar
Discard
Author Best Answer

Here is the solution :


class ResPartner(models.Model):
_inherit = 'res.partner'
city_id = fields.Many2one('res.city', string='City')

@api.depends('city_id')
@api.multi
def set_city(self):
self.city = self.city_id.name

city = fields.Char(compute=set_city, store=True)
and in your xml inheritance :

<xpath expr="//div/field[@name='street2']" position="after">
<field name="city_id" placeholder="City" class="o_address_city"/>
</xpath>
<field name="city" position="attributes">
<attribute name="invisible">1</attribute>
</field>
Thanks
Avatar
Discard
Related Posts Replies Views Activity
2
Mar 23
1635
7
Jun 24
21670
3
Sep 21
4238
0
Sep 20
1334
1
Apr 23
1300