Classical Python inheritance in Odoo

There are many situations when we need to inherit some model in order to achieve a particular case. Odoo supports three types of model inheritance:

In this post, I am going to explain the first one, Classical Python inheritance. It is called Classical Python Inheritance because it supports default inheritance that is used in Python. You can use this type of inheritance when you need a different table in the DB for the new model, but you want to inherit all methods and fields from the original model and to add some additional functionality.

Example: You need to represent a model PartnerContact that supports the existing functionalities from res.partner model, but you need to separate the data from both models in different tables.
In order to accomplish that we create a new model PartnerContact as following:

from openerp.addons.base.res_partner import res_partner as ResPartner

class PartnerContact(ResPartner):
    _name = ''

Also, you can use this type of inheritance if you want to add functionality from some other class to the model that you define. You can do that in the following way:

from openerp import models

class PartnerContact(models.Model, AdditionalClass):
    _name = ''

You can find more for these three types of inheritance here here

Leave a Reply

Your email address will not be published.