gdaramouskas
gdaramouskas

Reputation: 3747

Odoo overriden function call order

It is to my understanding that odoo does not extend its models as Python extends its classes (_inherit = 'model'. And that seems pretty reasonable. My question though is this:

If I have customModule1 that extends sale.order and overrides the write method adding some functionality and I later install customModule2 which in turn extends sale.order model and overrides the write method adding some functionality as well I understand that all the versions of the write method will be called but at which order?

Is write of customModule1 going to be called first when the client writes on the sale.order model? Or write of customModule2 ?

Upvotes: 4

Views: 3064

Answers (1)

Yes it's very interesting point and no one can predict which method from which module called first because odoo manages hierarchical structure for dependency.

Calling pattern comes into the picture only when the method will be called from object (manually from code) and if write method call from UI (means Sales Order edit from UI) then it will call each write method written for that model no matter in which module it is and it's sequence is LAST WRITTEN CALL FIRST (but it's only when the method is called from UI).

So in your case Custom Module 1 and Custom Module 2 will be on same level and both have the same parent Sale Order.

Sales Order => Custom Module 1 (Write method override)

Sales Order => Custom Module 2 (Write method override)

So while the write method will be called manually from code then it will gives priority to local module first and then it will call super method.

In that case suppose write method calling from Module 1 then it may be possible that it will ignore write method of Module 2 because Module 1 and Module 2 both are on same level (super will be called write method of parent class). Because we have face this issue many time in development that methods which are override on multiple modules and these are on same level then it will not going to call the method of the next module.

So when you need to call each method of the each module they must be in hierarchy but not at the same level.

Because there is main reason why the method will not be called some times for parallel modules.

Because here two thing comes into the picture,

1). depends : Parent Module (which decides the module hierarchy)

2). _inherit : Here the methods and behavoirs of the object's definied.

Module 1 and Module 2 are not there in depends of each other so by hierarchy it's not necessary to call the method from these both module no matter whether they are overriding the same method of same model.

Upvotes: 3

Related Questions