This question has been flagged

Hi All,

I have four modules. (DY_A,DY_B,DY_C,DY_D)

The A has one model and one function (def function01). 

The B\C\D inherit A and they inhert A's function01.


DY_A:

from odoo import models, fields, api
# AAAAAAAAAAAAAAAAAA

class A(models.Model):
_name = 'dy.a'

def func(self):
a = 1
return a

DY_B:

from odoo import models, fields, api
##### BBBBBBBBBBBBBBBBBBBBBBBBB

class B(models.Model):
_inherit = 'dy.a'

def func(self):
res = super(B, self).func()
a = 2
return a

DY_C:

from odoo import models, fields, api
#CCCCCCCCCCCCCCCCC

class C(models.Model):
_inherit = 'dy.a'

def func(self):
res = super(C, self).func()
a = 3
print(C.mro())
return a

DY_D:

from odoo import models, fields, api
#DDDDDDDDDDDDDDDDDDDDD

class D(models.Model):
_inherit = 'dy.a'

def func(self):
res = super(D, self).func()
a = 4
print(D.mro())
return a
I don't understand how their inheritance execution order is handled? Who Can Help Me?
Avatar
Discard

Not sure what you are trying to achieve here but the model to get defined last in the line gets executed first. Also, I see that you are trying not to return the result you got from calling the super method rather returning something different so I suggest you make sure that you don't need the values you are getting from the super method.

Author

I Just want to test the inheritance order.

A(module)

/ | \

/ | \

B C D (module)

B\C\D are the same level. If all they inherit A and rewrite the A's function. What's execution order and why?

I find that the execution order of the function is D->C->B->A,But I don't understand the reason.

Is it related to the order of installation or modules' name?

Thanks.

Author

I Just want to test the inheritance order.

                      A(module)

                    / | \ 

                  /   |    \ 

                B   C     D (module)

B\C\D are the same level. If all they inherit A and rewrite the A's function. What's execution order and why?

I find that the execution order of the function is D->C->B->A,But I don't understand the reason.

Is it related to the order of installation or modules' name?

Thanks.