Reputation: 523
Hi I want to create a new tab in the hr.contract.form.
When I create a new group the xpath element I get the error message that the group is not added to the root element.
ValueError: Element '<page string="Assignment Information" name="assignment_information">' cannot be located in parent view
When I create a new page and a new group then the fields just show up in the Contract Details tab and not in a new one.
This is my hr.contract.xml file. The fields are defined in the hr_contract.py file and appear ar they should, so that one should be fine.
<?xml version="1.0"?>
<odoo>
<record model="ir.ui.view" id="hr_contract_view_form">
<field name="inherit_id" ref="hr_contract.hr_contract_view_form"/>
<field name="model">hr.contract</field>
<field name="name">mycompany.hr.contract.form</field>
<field name="arch" type="xml">
<!-- Additional fields in the contract details tab -->
<xpath expr="//group[@name='duration_group']" position="after">
<group string="Tasks" name="tasks">
<label for="employee_tasks"/>
<div>
<field name="employee_tasks"/>
</div>
</group>
</xpath>
<!-- Assignment Information tab-->
<page string="Assignment Information" name="assignment_information">
<group name="assignment_information">
<xpath expr="//group[@name='additional_assignment_information']" position="after">
<group string="Assignment Location" name="assignment_location">
<label for="assignment_location"/>
<div>
<field name="assignment_location"/>
</div>
</group>
</xpath>
</group>
</page>
</field>
</record>
</odoo>
This is the hr_contract.py file:
from logging import getLogger
from odoo import models, fields
LOGGER = getLogger(__name__)
class EmployeeContract(models.Model):
'''
Extend hr.contract model to add custom fields.
'''
_inherit = 'hr.contract'
employee_tasks = fields.Text(
string='Employee tasks',
store=True,
readonly=False,
translate=False,
help='Custom colon-separated (name: value) tasks assigned to the employee.'
)
assignment_location = fields.Text(
string='Assignment Location',
store=True,
readonly=False,
translate=False,
help='Location of the freelancers assignment'
)
Thanks for taking a look at it!
Upvotes: 1
Views: 832
Reputation: 376
You add your new page wrongly.Try this
<?xml version="1.0"?>
<odoo>
<record model="ir.ui.view" id="hr_contract_view_form">
<field name="inherit_id" ref="hr_contract.hr_contract_view_form"/>
<field name="model">hr.contract</field>
<field name="name">mycompany.hr.contract.form</field>
<field name="arch" type="xml">
<!-- Additional fields in the contract details tab -->
<xpath expr="//group[@name='duration_group']" position="after">
<group string="Tasks" name="tasks">
<label for="employee_tasks"/>
<div>
<field name="employee_tasks"/>
</div>
</group>
</xpath>
<!-- Assignment Information tab-->
<xpath expr="//notebook/page[@name='your previsous page name']" position="After">
<page string="Assignment Information" name="assignment_information">
<group name="assignment_information">
<xpath expr="//group[@name='additional_assignment_information']" position="after">
<group string="Assignment Location" name="assignment_location">
<label for="assignment_location"/>
<div>
<field name="assignment_location"/>
</div>
</group>
</xpath>
</group>
</page>
</xpath>
</field>
</record>
</odoo>
Upvotes: 3