Skip to Content
Menu
This question has been flagged
3 Replies
6181 Views

How can I add custom fields to inherited Models and views when I Tried to add it is throwing an Parse Error solve this

I tried to add like this

In Model

class ResPartner(models.Model):

    _name = 'new.customer.model'
    _inherit = 'res.partner'
    district = fields.Char(string='district', Size=32)

In Xml:

<record id="add_new_partner" model="ir.ui.view">
            <field name="name">new.customer.model</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='country_id']" position="after">
                <field name="district" placeholder="district"/>
              <xpath/>
            </field>
    </record>
Avatar
Discard
Best Answer

Hi

Update the code,

In python:
from odoo import fields, models

class ResPartner(models.Model):
    _inherit = 'res.partner'

    district = fields.Char(string='District', size=32)
   
In XML:
<record id="add_new_partner" model="ir.ui.view">
<field
name="name">new.customer.model</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='vat']" position="before">
            <field name="district" placeholder="District"/>
        </xpath>
    </field>
</record>




Hope it helps

Avatar
Discard
Author Best Answer

Nothing is changed, i get same error as below except for 'new.customer.model' changed to res.partner now

ParseError: "Error while validating constraint

Field `district` does not exist

Error context:
View `res.partner`
[view_id: 1094, xml_id: n/a, model: res.partner, parent_id: 124]
None" while parsing file:///c:/program files (x86)/odoo 10.0/server/odoo/addons/localizationindonesia/views/partner.xml:4, near
<record id="add_new_partner" model="ir.ui.view">
            <field name="name">res.partner</field>
            <field name="model">res.partner</field>
            <field name="inherit_id" ref="base.view_partner_form"/>
            <field name="arch" type="xml">
              <field name="country_id" position="after">
                <field name="district" placeholder="District"/>
              </field>
            </field>
    </record>

Please help

Avatar
Discard
Best Answer

Hi Sharath,

You gave wrong value of '_name'. 

Instead of _name = 'new.customer.model' , you should use  _name = 'res.partner'.

Hope this will help you!

Thanks.

Avatar
Discard
Author

no it is not working

Author

Nothing is changed, i get same error as below except for 'new.customer.model' changed to res.partner now

ParseError: "Error while validating constraint

Field `district` does not exist

Error context:

View `res.partner`

[view_id: 1094, xml_id: n/a, model: res.partner, parent_id: 124]

None" while parsing file:///c:/program files (x86)/odoo 10.0/server/odoo/addons/localizationindonesia/views/partner.xml:4, near

<record id="add_new_partner" model="ir.ui.view">

<field name="name">res.partner</field>

<field name="model">res.partner</field>

<field name="inherit_id" ref="base.view_partner_form"/>

<field name="arch" type="xml">

<field name="country_id" position="after">

<field name="district" placeholder="District"/>

</field>

</field>

</record>

Related Posts Replies Views Activity
1
Aug 17
167
2
Mar 22
7916
1
May 17
3560
1
May 17
9401
7
Jun 21
12172