Skip to Content
Menu
This question has been flagged

Hi!

I'm trying to extend hr_employee to add a couple of fields, one of those to show how many one2many items has an employee linked. 

------------------------
from openerp import models, fields, api

class hr_employee(models.Model):
    _name = 'hr.employee'
    _inherit = ['hr.employee']

    employee_session_ids = fields.One2many('session.session', 'employee_id')
    employee_session_count = fields.Integer(string="Session Items", coumpute='_employee_session_count')

    @api.one
    @api.depends('employee_session_ids')
    def _employee_session_count(self):
        self.employee_session_count = len(self.employee_session_ids)
------------------------

'session.session' is implemented with new api syntax. And I've managed to do it well when all classes involved are in the new syntax. But if I inherit an old class the method is not invoked.

I've misunderstood the operation of the api decorators, probably. I tried to decorate the method with @api.model and @api.returns but it doesn't work.

------
    @api.one
    @api.model
    @api.returns('hr.employee', lambda val: val.id)
    @api.depends('employee_session_ids')
    def _employee_session_count(self):
        self.employee_session_count = len(self.employee_session_ids)
------

Any clue?

Avatar
Discard
Author

I've read the "Old API compatibility" section in the odoo documentation and it says: By default, methods are assumed to use the new API style and are not callable from the old API style. Does it means that in case you need to extend an old api class is best done with the old style?

Related Posts Replies Views Activity
6
Jan 23
16043
1
Apr 15
8462
2
Mar 15
17472
1
Mar 15
3351
1
Aug 18
5316