Inheritance in openERP (odoo)

I am new to openERP and have interviews. Please explain the idea of ​​different inheritance types in openERP, I think there are only 3 types. please explain this in a very simple way in terms of the interview.
PS: I am familiar with the concept of simple inheritance.

+3


source to share


1 answer


Inheritance:

The inheritance mechanism is used to generate the idea of ​​re utilability.there reability is used to reuse the code of the parent class in any object oriented programming.

Benefits:

  • Reduce code redundancy.
  • Provides the ability to reuse code.
  • Reduces source code size and improves code readability.
  • The code is easy to manage and is divided into parent and child classes.
  • Support for code extensibility by overriding base class functionality in child classes.

Disadvantages:

  • In the Inheritance class, the base class and the child classes are closely related. Hence, if you change the code of the parent class, all child classes will be affected.

  • In the class hierarchy, many data members remain unused and the memory allocated to them is not used. Hence, unless you have implemented inheritance correctly.

There are two ways of inheritance in OpenERP.

1.Classical use of Putin's way:

This allows certain "generic" behavior to be added to the Model by inheriting classes that derive from orm.Model, such as geoModel, which adds geographic support.

 class Myclass(GeoModel, AUtilsClass):

      

Using _inherit: -

The main goal is to add new behaviors / extend existing ones. For example, you want to add a new field to an invoice and add a new method



class AccountInvoice(orm.Model):
    _inherit = "account.invoice"
    _column = {'my_field': fields.char('My new field')}
    def a_new_func(self, cr, uid, ids, x, y, context=None):
        # my stuff
        return something

      

override existing method:

def existing(self, cr, uid, ids, x, y, z, context=None):
    parent_res = super(AccountInvoice, self).existing(cr, uid, ids, x, y, z, context=context)
    # my stuff
    return parent_res_plus_my_stuff

      

2.Polymorphic path: -

Using _inherits: -

When using _inherits, you will be doing a kind of polymorphic model in the database path.

For example product.product

inherits product.template

or res.users

inherits res.partner

. This means that we are creating a model that takes a view of the model but adds additional data / columns to the new database table. Therefore, when you create a user, all partner data is stored in the table res_partner

(and a partner is created), and all information related to the user is stored in the table res_users

.

For this we use dict: _inherits = {'res.partner': 'partner_id'}

. The key matches the base model and the foreign key value of the base model.

As with XML, you can inherit from Odoo views (like form view, tree view, search, etc.) and also you can change behavior from the view

Key points:

The above two methods can be applied on the server side of Odoo and which you can change the behavior of an existing view or any other things that you can change in Odoo considering the effect on your client side.

I hope this is helpful to you .. :)

+9


source







All Articles