如何在 odoo 13 中创建新选项卡?
How to create a new tab in odoo 13?
您好,我想在 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'
)
感谢您的浏览!
你添加你的新页面wrongly.Try这个
<?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>
您好,我想在 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'
)
感谢您的浏览!
你添加你的新页面wrongly.Try这个
<?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>