嗨,我想在hr.contract.form中创建一个新选项卡。
当我创建一个新组xpath元素时,我收到错误消息,指出该组未添加到根元素中。
ValueError: Element '<page string="Assignment Information" name="assignment_information">' cannot be located in parent view
当我创建一个新页面和一个新组时,这些字段仅显示在“合同详细信息”选项卡中,而不显示在新的页面中。
这是我的hr.contract.xml文件。这些字段在hr_contract.py文件中定义,并按应显示的形式显示,以便可以使用。
<?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>
这是hr_contract.py文件:
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'
)
感谢您的关注!
答案 0 :(得分:2)
您错误地添加了新页面。请尝试
<?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>