Search code examples
inheritanceodoo-11odoo-view

Inherit specific fields from res.partner Odoo v11


Hi i've got a field which contains contact information so i used the inheritence so i can get only name, adress, email, phone num but i'm getting all the view showed with all the existing fields. The xml code:

<record model="ir.ui.view" id="laboratory_view">
        <field name="name">new view for 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="name"/>
            <field name="adress"/>
            <field name="phone"/>
            <field name="email"/>
        </field>
    </record>

Solution

  • In order to modify existing views in Odoo you must specify which part you want to work on and the operation you want to do using XML's xpath syntax

    Also if you want to remove existing fields from views it's better to hide them than removing as it'll be more compatible to other modules that depend on that field.

    Example for hiding the Website Field of a Contact field:

    <odoo>
      <record id="view_company_form" model="ir.ui.view">
        <field name="name">res.partner</field>
        <field name="model">res.partner</field>
        <field name="type">form</field>
        <field name="inherit_id" ref="base.view_partner_form"/>
        <field name="arch" type="xml">
          <xpath expr="//field[@name='website']" position="attributes">
            <attribute name="invisible">1</attribute>
          </xpath>
        </field>
      </record>
    </odoo>