Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps:
CRM | e-Commerce | Accounting | Inventory | PoS | Project management | MRP | etc.
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 ?
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.
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.Register
Odoo Training Center
Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.Test it now
|Asked: 3/31/16, 6:08 AM|
|Seen: 832 times|
|Last updated: 3/31/16, 10:33 AM|