Odoo Help

Welcome!

This community 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.

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

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 community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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