This question has been flagged
2 Replies
4587 Views

Hello,

I want to add a new employee_children module that inherits the hr_employee module, which add new tab in the existing form. 

That page will show a table with the children of the employee. 

I created new model for the children with that fields: name, birth_date and parent_id-> which is of type many2one. 

I also created a model which inherits hr.employee model, and added there the children_ids field-> which is of type one2many.

Then I created a new view that inherits hr.view_employee_form, and added new page to that form, and in that page I added the children_ids field. 
But I got the error: 

```

Field `children_ids` does not exist

```

What is the solution for that error? 


here is my code:

employee_children.py:

```

from odoo import models, fields, api


class ChildrenInformation(models.Model):

    _inherit = ['hr.employee']

    children_ids = fields.one2many('hr.employee.children', 'emp_id', string='Children', groups="hr.group_hr_user")

```

employee_children_view.xml:

```

<?xml version='1.0' encoding='UTF-8'?>

<odoo>

    <data>

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

            <field name="name">hr.employee.employee_children.form.inherit</field>

            <field name="model">hr.employee</field>

            <field name="inherit_id" ref="hr.view_employee_form"/>

            <field name="type">tree</field>

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

                <xpath expr="//page[@name='personal_information']" position="after">

                    <page name="children" string="Children" >

                        <group string="Children">

                            <field name='children_ids' widget='one2many'>

                                <tree string="tree">

                                    <field name="name"/>

                                    <field name="birth_date"/>

                                </tree>

                            </field>

                        </group>

                    </page>

                </xpath>

            </field>

        </record>

    </data>

</odoo>

```

Avatar
Discard
Author

I solved it, the problem was spelling - had to write One2many and not one2many

Best Answer

Mostly your changes are looks good. Try following changes if that helps:

_inherit = ['hr.employee'] replace this by _inherit = 'hr.employee'

Remove following tag from your XML:

<field name="type">tree</field> # Remove this tag

Remove widget='one2many' because children_ids is already a one2many:

<field name='children_ids'>
Avatar
Discard