Search code examples
odooopenerp-7

Inheritance of non model, core class in Odoo/OpenERP


In Odoo, I want to modify the addons/web/session/OpenERPSession class without modifying the core code. Meaning I want to subclass this class from my module so that the system will use my version of the OpenERPSession class instead of the core class. And specifically I want to alter only a method's implementation, and I do so by overriding it:

class ExtendedSession(session.OpenERPSession):

    def model(self, model):
        _logger = logging.getLogger(__name__)
        _logger.info('OVERRIDEN ==================== OpenERPSession.model')
        if self._db == False:
            raise session.SessionExpiredException("Session expired")
        return session.Model(self, model)

But unfortunately the 'OVERRIDEN ==================== OpenERPSession.model' statement is not print therefore the system does not call my implementation.

How can I instruct Odoo to use my implementation of the OpenERPSession?


Solution

  • Sorry for answering late...

    For any non model class, you can inherit them by using full signature path of that class, for ex.

    You can inherit session.OpenERPSession using the full path ...

    class ExtendedSession(addons.web.sessions.OpenERPSession):
    
        def model(self, model):
            _logger = logging.getLogger(__name__)
            _logger.info('OVERRIDEN ==================== OpenERPSession.model')
            if self._db == False:
                raise session.SessionExpiredException("Session expired")
            return session.Model(self, model)
    

    Try this......