Odoo Help

0

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

By
Jordi
on 12/11/14, 2:42 PM 1,295 views

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?

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?

Jordi
on 12/12/14, 3:30 AM

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.

Register

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)

Stats

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