Search code examples
odoo-8

add many2one field in inherited view


I want to display my Many2one field. I inherited from the hr_timesheet_sheet.sheet model like this:

class list_activity_sheet(models.Model):
    _inherit = 'hr_timesheet_sheet.sheet'
    activity_id = fields.Many2one('list_activity_sheet.activity')

class List_activity(models.Model):
    _name='list_activity_sheet.activity'
    name= fields.Char('Description',required=True)

And for the View:

<openerp>
<data>
    <record id="List_activity_form" model="ir.ui.view">
                <field name="name">hr_timesheet_sheet.sheet.form.inherit</field>
                <field name="model">hr_timesheet_sheet.sheet</field>
                <field name="inherit_id" ref="hr_timesheet_sheet.hr_timesheet_sheet_form"/>
                <field name="arch" type="xml">
                    <xpath expr="/form/sheet/notebook/page[@string='Details']/field/tree/field[@name='name']" position="after">
                        <field name="activity_id"></field>
                    </xpath>

                </field>
     </record>
</data>

When i install my addon , i got that message: field activity_id doesn't exist in the view.

Does anyone know how to solve that?


Solution

  • You're working on the wrong model. If i understand your view definition correctly, you want to choose an activity on the sheet lines.

    You have to inherit hr.analytic.timesheet for that instead of hr_timesheet_sheet.sheet. In Odoo 9+ you have to inherit account.analytic.line, because hr.analytic.timesheet was kicked out.