Python 获取错误:尝试继承员工表单时,字段“message\u follower\u id”不存在
我面对这个问题已经有两天了,在没有阅读任何关于相同错误的链接的情况下,我很难找到解决方法 我只是创建一个简单的模块call insurance,并将其添加为员工视图表单中的一个新选项卡 这是我的视图文件Python 获取错误:尝试继承员工表单时,字段“message\u follower\u id”不存在,python,openerp,odoo-9,Python,Openerp,Odoo 9,我面对这个问题已经有两天了,在没有阅读任何关于相同错误的链接的情况下,我很难找到解决方法 我只是创建一个简单的模块call insurance,并将其添加为员工视图表单中的一个新选项卡 这是我的视图文件 <record id='social_insurance_tab' model='ir.ui.view'> <field name='social.insurance.tab'></field> <field na
<record id='social_insurance_tab' model='ir.ui.view'>
<field name='social.insurance.tab'></field>
<field name='model'>hr.insurance</field>
<field name='inherit_id' ref='hr.view_employee_form'></field>
<field name='arch' type='xml'>
<notebook position="inside">
<page name='insurance' string='Social Insurance'>
<group string="Informations">
<group>
<field name='name'></field>
<field name='employee_id'></field>
<field name='date_join'></field>
</group>
<group>
<field name='amount'></field>
<field name='salary'></field>
</group>
</group>
<label for='notes' string="Notes"/>
<field name="notes"/>
</page>
</notebook>
</field>
</record>
我还将hr添加到openerp.py中
'depends': ['base_action_rule','hr'],
它总是返回这个错误
ParseError: "Invalid view definition
Error details:
Field `message_follower_ids` does not exist
Error context:
View `insurance.tab`
[view_id: 1462, xml_id: n/a, model: hr.insurance, parent_id: 905]
None" while parsing /opt/odoo/odoo/addons/hr_insurance/hr_insurance_view.xml:66, near
<record id="insurance_tab" model="ir.ui.view">
<field name="name">insurance.tab</field>
<field name="model">hr.insurance</field>
<field name="inherit_id" ref="hr.view_employee_form"/>
<field name="arch" type="xml">
<data>
<xpath expr="//notebook" position="inside">
<page string="Insurance">
<field name="name"/>
</page>
</xpath>
</data>
</field>
</record>
ParseError:“视图定义无效
错误详细信息:
字段“message\u follower\u id”不存在
错误上下文:
查看'insurance.tab`
[视图id:1462,xml\U id:n/a,型号:hr.insurance,家长id:905]
解析/opt/odoo/odoo/addons/hr_insurance/hr_insurance_view.xml:66时为“无”
保险标签
人力资源保险
问题在下面指定的行上
<field name="inherit_id" ref="hr.view_employee_form"/>
要继承员工表单,您需要对视图和模型进行一些更改 视图名称应如下所示:
<field name='name'>social.insurance.tab</field>
要添加新字段,您应继承hr.employee
,并保留原始字段的名称(除非您需要更改其属性),如name
字段,该字段应为员工名称。
可以为字段名添加前缀,以避免意外覆盖任何字段
class HrEmployee(models.Model):
_inherit = 'hr.employee'
_order = 'id desc'
insurance_id= fields.Many2one('hr.insurance', string='Insurance', required=True)
insurance_date_join = fields.Date('Date join Insurance', required=True)
insurance_amount = fields.Float('Amount of social insurance')
insurance_salary = fields.Float('Salary Social insurance')
insurance_notes = fields.Text('Notes')
我知道你在那里做了什么。这很难解释。在您的视图中,您继承了一个已经存在的视图
hr.view\u employee\u form
。该视图仍然具有字段声明消息\u follower\u id
。但是您将模型声明更改为自定义模型hr.insurance
。如果我正确理解您的问题,您只需要在hr.employee
-视图的选项卡中添加一些字段,对吗?没错,我创建了一个带有一些字段的新模块,并将其添加到员工视图中。我通过查看hr.employee
中的更改模型对其进行了修复,并继承了模型hr.employee
,而不是在模型文件尼斯中创建hr.insurance
。这就是我的意思。请注意您的姓名
字段。您可能会覆盖此字段。不确定,但你应该证明这一点。默认情况下,hr.employee
中的name
字段的类型为char
。如果您以在模型中执行的方式继承该模型。您将覆盖一个manyOne
字段。我将字段名更改为保险,现在一切正常,谢谢您的帮助:D
<field name='model'>hr.employee</field>
class HrEmployee(models.Model):
_inherit = 'hr.employee'
_order = 'id desc'
insurance_id= fields.Many2one('hr.insurance', string='Insurance', required=True)
insurance_date_join = fields.Date('Date join Insurance', required=True)
insurance_amount = fields.Float('Amount of social insurance')
insurance_salary = fields.Float('Salary Social insurance')
insurance_notes = fields.Text('Notes')