콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다

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?
아바타
취소

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.

작성자

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.

작성자

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.

관련 게시물 답글 화면 활동
3
11월 22
12683
2
6월 25
700
2
6월 25
2925
1
3월 15
5197
1
2월 25
1107