Odoo Help


[v8.0] extend an old api class using new api style. Specifically hr_employee.

on 12/11/14, 2:42 PM 1,109 views


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

    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.returns('hr.employee', lambda val: val.id)
    def _employee_session_count(self):
        self.employee_session_count = len(self.employee_session_ids)

Any clue?

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?

on 12/12/14, 3:30 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 12/11/14, 2:42 PM
Seen: 1109 times
Last updated: 3/16/15, 8:10 AM