This question has been flagged
1 Reply
3618 Views

I got three different custom modules that each overwrite the same method like the following :


from odoo.addons.website_sale.controllers.main import WebsiteSale

class WebsiteSale(WebsiteSale):

@http.route()
def shop(self, page=0, category=None, search='', ppg=False, **post):
    {Code Block 1}

from odoo.addons.website_sale.controllers.main import WebsiteSale

class WebsiteSale(WebsiteSale):

@http.route()
def shop(self, page=0, category=None, search='', ppg=False, **post):
    {Code Block 2}

from odoo.addons.website_sale.controllers.main import WebsiteSale

class WebsiteSale(WebsiteSale):

@http.route()
def shop(self, page=0, category=None, search='', ppg=False, **post):
    {Code Block 3}


When calling shop route or function which code block will be executed ?

Avatar
Discard
Best Answer

Hello Yaman,

Here is an interesting reply I got from stackoverflow posted by  emipro-technologies-pvt-ltd. I hope it helps.

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.

Avatar
Discard