简体   繁体   中英

Got Error: Field `message_follower_ids` does not exist when trying inherit employee form

I'm facing this issue for 2 days and no luck to find the way how to resolve it without reading any links regarding the same error

I'm just create a simple module call insurance and add it as a new tab in employee view form

here is my view file

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

and model file

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

I also add hr into depends in openerp .py

'depends': ['base_action_rule','hr'],

And it always return this error

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>

问题出在下面指定的行上

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

To inherit Employee form you will need to make some changes to your view and model.

The view name should be as following:

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

The view model should be hr.employee :

<field name='model'>hr.employee</field>

To add new fields you should inherit hr.employee and keep the names of the original fields (unless you need to change their attributes), like name field which is supposed to be an employee name. You can prefix your field names to avoid overwriting any field accidentally.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM