Odoo Help

0

How ODOO Inheritance work? Hack the secrete !!!

By
Zahin
on 9/27/14, 12:15 PM 2,416 views

I came across inheritance of ODOO.

Here each module inherit other where _inherit use that's fine we understood my that name new fields are create in that model.

But in new inherited class how it call parent class or original class methods.

Like in stock module, product model inhirited and new methods added and executed, also methods define in product can be call from stock i product model's method.

How this all work ? Please expert shall this features hows works ?

Python default overwrite class declaration, then how its works here ? Like product and stock module have class product declaration, where it do not overwrite previously declared class method and features ? How it keeps methods declared in other modules ?

Zahin
on 9/28/14, 11:40 AM
0

Ben Bernard

--Ben Bernard--
1083
| 4 3 6
Jakarta, Indonesia
--Ben Bernard--
Ben Bernard
On 9/29/14, 12:50 AM

Odoo inheritance implementation is just python 2 implementation of class/object oriented programming.

But in new inherited class how it call parent class or original class methods.

Check https://docs.python.org/2/library/functions.html#super. Odoo orm makes sure every model extend any other model if the keyword _inherit is defined. The extension will behave like class inheritance in OPP sense. To learn more about the orm, check folder openerp/osv.

Its fine that _inherits add new fields in table. but how it keeps methods even with same class name or other class named. ? how it run time evaluate right methods and other self.methods even defined in multiple codes, let me know exact things, I had already dig many things.

Zahin
on 9/29/14, 11:38 AM
0
Mohamed Essakali
On 9/27/14, 4:32 PM

See the link below, otherwise you can find a lot of example on addons module (e.g. sale_stock).

 https://www.odoo.com/forum/help-1/question/the-different-openerp-model-inheritance-mechanisms-whats-the-difference-between-them-and-when-should-they-be-used-46

I don't know if I have understood your question, here is an example :

suppose you want to override the create and the unlink methodes of the class account_invoice:

class account_invoice(osv.Model):
    _inherit = "account.invoice"

    def unlink(self, cr, uid, ids,  context={}):
        #do something here  
        return super(account_invoice, self).unlink(cr, uid, ids,  context) #invoke parent methode

    def create(self, cr, user, vals, context=None):
        inv_id = super(account_invoice,self).create(cr, user, vals, context=context) #invoke parent methode

         #do something here 
         return inv_id

 account_invoice()

 

Hopes that helps

 

I want to know how it works, by default paython with same named class, over write their mehtod. in odoo same name class can be used and also can be able to access all methods.

Zahin
on 9/28/14, 11:21 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

2 follower(s)

Stats

Asked: 9/27/14, 12:15 PM
Seen: 2416 times
Last updated: 3/16/15, 8:10 AM