Odoo Help

Welcome!

This community 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.

1

Which method is used first if two modules inherit the same class/method?

By
Pascal Tremblay
on 2/29/16, 10:35 PM 652 views

Hello all,

if I have to modules that both inherit the same class.

the same method is defined in both inherited classes.

how to know which of the two new methods will be executed first?

where is the best documentation about this concept? Can we talk about multi inheritance?

thanks to guide me

2

Sudhir Arya (SA)

--Sudhir Arya (SA)--
10150
| 6 8 8
Ahmedabad, India
--Sudhir Arya (SA)--

Working as an OpenERP/Odoo developer and a Team Leader 

Top 5 Odoo contributor On Stackoverflow

LinkedIn

Blog

Stackoverflow

Sudhir Arya (SA)
On 3/1/16, 2:16 AM

Hello Pascal,

It decides based on the module dependency.

The method of child method will be called first and then its parent module's method will be called.

Ex: There are 3 modules called A, B (B depends on A), C (C depends on B)

So, first method of module C (child) will be called. Then method of module B will be called and then method of module A will be called.

Parent module's method will be called if you have called super() method.

Hope this helps you.

Thanks for you answer. If B depends on A and module C depends on A too???

Pascal Tremblay
on 3/1/16, 7:13 AM

I am not sure but might be the module which was installed last, the method of that module will be called.

Sudhir Arya (SA)
on 3/1/16, 7:17 AM

thanks again. I will test it.

Pascal Tremblay
on 3/1/16, 8:53 AM
0
Ahmed Ababneh
On 8/2/16, 3:33 AM

First of all, when we you define a method again, you are overriding it, which means only one version of the method is called. No method will be called before the other.

Odoo will look into your __openerp__.py. It will check the 'depends' list value. It will look for the method your are overriding in the modules in the 'depends' list.

Odoo will try to find the method in the first module in the list, if not found it will look into the next module, and if not it will look into the 3rd one, etc ...

So, if method B override method A and method C overrides A as well, you need to add the module name of the method A in the 'depends' list before the module name of method B. 

On the other hand, if method B overrides method A, and method C overrides method B, you need to add the module name of the method B in the 'depends' list before the module name of method A. 

Hint: The module name is the same as the folder name in [Odoo home directory]/addons folder

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 2/29/16, 10:35 PM
Seen: 652 times
Last updated: 8/2/16, 3:33 AM