Maubeh
Maubeh

Reputation: 445

How to correctly inherit an inherited view in odoo?

I have been trying to target an inherited element in the view, but it's not working for me.

So I have a view that inherits from the form view of hr.contract as shown here:

  <record id="hr_contract_view_form_cayor" model="ir.ui.view">
    <field name="name">name</field>
    <field name="model">hr.contract</field>
    <field name="inherit_id" ref="hr_contract.hr_contract_view_form"/>
    <field name="arch" type="xml">
        <data>
            <!-- more elements define with xpath -->
            <xpath expr="//field[@name='job_id']" position="after">
                <field name="retirement_age"/>
            </xpath>
            ...
            <xpath expr="//page[@name='information']" position="after">
                <page string="Allowances" groups="hr_payroll.group_hr_payroll_user">

                    <group>
                        <group name="allowances_group1">
                            ...
                            <field name="car_allowance"/>
                            ...
                        </group>
                        <group name="allowances_group2">
                            ...
                        </group>
                    </group>
                </page>
            </xpath>
        </data>
    </field>
</record>

I have defined a new file to inherit from this form view, which adds a new field to it, as follows:

<record id="hr_contract.hr_contract_view_form_inherited" model="ir.ui.view">
    <field name="name">hr.contract.grade.rank.form.inherit</field>
    <field name="model">hr.contract</field>
    <field name="inherit_id" ref="module.hr_contract_view_form_cayor"/>
    <field name="arch" type="xml">
         <data>
            <xpath expr="//group[@name='allowances_group1']" position="inside">
                <field name="medical_allowance" />
            </xpath> 
         </data>
    </field>
</record>

But when I upgrade my module, I get the following error:

Field `retirement_age` does not exist

How can I correctly inherit from the first one, and add my new field?

Any help will be greatly appreciated, thanks in advance.

Upvotes: 2

Views: 2318

Answers (1)

Bhoomi Vaishnani
Bhoomi Vaishnani

Reputation: 718

Please try this code :

Python :

class HrContract(models.Model):
    _inherit = 'hr.contract'

    retirement_age = fields.Char(string="Retirement Age:")

XML :

<record id="hr_contract_view_form_cayor" model="ir.ui.view">
    <field name="name">name</field>
    <field name="model">hr.contract</field>
    <field name="inherit_id" ref="hr_contract.hr_contract_view_form"/>
    <field name="arch" type="xml">
        <data>
            <!-- more elements define with xpath -->
            <xpath expr="//field[@name='job_id']" position="after">
                <field name="retirement_age"/>
            </xpath>
        </data>
    </field>
</record>

Upvotes: 1

Related Questions