Search code examples
odoo

Inheriting a model and adding new field to the model odoo 12


I'm trying to add a new field in the res.users model near the field named partned_id in that model.But im not getting the field in the view and i dont understand why.

I have tried below code:

*.py

class Users(models.Model):
_inherit = "res.users"

reporting_to = fields.Many2one('res.users',string="Reporting To")

*.xml

    <record id="view_users_form_inherit" model="ir.ui.view">
        <field name="name">res.users.form.inherit</field>
        <field name="model">res.users</field>
        <field name="inherit_id" ref="base.view_users_form"/>
        <field name="arch" type="xml">
        
        <xpath expr="//field[@name='partner_id']" position="after">
            <field name="reporting_to"/>
        </xpath>
        
        </field>
    </record>

Solution

  • Assuming you have registered your XML in the manifest file.

    The partner_id field exists many times on the base view. It may find the wrong one. Use a more exact xpath.