出现错误:尝试继承员工表单时,字段“message_follower_ids”不存在

时间:2016-11-23 10:55:45

标签: python openerp odoo-9

我正面临这个问题2天,如果没有阅读有关同一错误的任何链接,找不到如何解决问题的方法

我只是创建一个简单的模块呼叫保险并将其添加为员工视图表单中的新选项卡

这是我的视图文件

    <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>

和模型文件

from openerp import models, fields, api

class hr_insurance(models.Model):
    _name = 'hr.insurance'

    _description = 'Insurance'

    _order = 'id desc'

    name = fields.Many2one('hr.contract', string='Insurance', required=True)

    employee_id = fields.Many2one('hr.employee', string='Employee', required=True)

    date_join = fields.Date('Date join Insurance', required=True)

    amount = fields.Float('Amount of social insurance')

    salary = fields.Float('Salary Social insurance')

    notes = fields.Text('Notes')

我还将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>

2 个答案:

答案 0 :(得分:0)

问题在下面指定的行上

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

答案 1 :(得分:0)

要继承Employee form,您需要对视图和模型进行一些更改。

视图名称应如下:

<field name='name'>social.insurance.tab</field>

视图模型应为hr.employee

<field name='model'>hr.employee</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')