Odoo Help


[V8] General question about method inheritance : multiple override in different modules

Aurélien Rivet
on 3/31/16, 6:08 AM 1,173 views

I have some questions about the method inheritance mechanism in Odoo.

I will take as an example the name_get method of res.partner model.

If I inherit it in two different modules, which one will be called ? What is the proper way to do it ?

For instance, in a res_partner class I override the method to display some code before the name of the partner.

But the method is already overriden in another module, which add also something to the name displayed. How will it behave ?

Also, when I override a base method like in that case, I used to copy the code of the original method ? Is it a good way to do ?




| 6 5 7
Tbilisi, Georgia
On 3/31/16, 10:15 AM
  • it should be aligned with the dependency chain. if module "A" defines method "foo" and both, module "B" and "C" override it, the actual method called should be chosen from "B" if "B" depends on "C" and vice versa, a "foo" defined in "C" should be used, if "C" depends on "B" (check dependencies in technical details of module or in the __openerp__.py - the "depends" list, BTW you can add to that depends list desired modules). Please, check it yourself and comment about it, if you get an unexpected behavior...

  • It's better to call function from parent model, using "super" python keyword if possible, but sometimes it's necessary to copy code in order to change something in it, incompatible with "super" call, or overcome a multiple inheritance gotchas. However it's strongly discouraged and you should avoid such practice as mach as possible.

Thanks ! Your answer is very useful. But that means that, for name_get again, it is impossible to add some string in a module via overriden function and some other string in another module via overriden function. Good to know, though.

Aurélien Rivet
on 3/31/16, 10:33 AM

without "super" it should not be possible, but with "super" why not... if there is "super" in *every* overridden version, they should be called in chain then. if "C" depends on "B" and "B" depends on "A" and all "foo" definitions call parent's function with "super", then it should be possible to add strings incrementally. if "B" is already depends on "A" and you are implementing "C", then just add in your __openerp__.py the "B" module in "depends" list, in order to avoid unexpected sequence of calls. Most probably you can get it done per your requirements.

on 3/31/16, 10:44 AM

Yeah that's ok. Thanks again.

Aurélien Rivet
on 3/31/16, 10:48 AM

About This Community

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


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 3/31/16, 6:08 AM
Seen: 1173 times
Last updated: 3/31/16, 10:33 AM