Se rendre au contenu
Menu
Cette question a été signalée
2 Réponses
3160 Vues

Hello,


odoo has a good support for different kinds of inheritance, but what is the reason about it's implementation? 

I really don't know how can I call 'super' in a class that inherits, in Python's terms, from Model, and if this class has a "_inherit = 'my.parent.model'", the super actually calls the class of 'my.parent.model' and not Model. How does this work out?

I went some time through Model class code and its parents and saw some code that maybe manipulate the class inheritance, but is not clear to me.

Thanks

Avatar
Ignorer
Meilleure réponse
simple example for inheritance :

class User(models.Model): _inherit = 'res.users' is_commercial = fields.Boolean(string= 'is Commercial') // i added this field to res.users table @api.multi def write(self, values): super(User, self).write() // here i called supper write method
for partner in self.partner_id: partner.is_commercial = self.is_commercial

here is official odoo documentation docs:

https://www.odoo.com/documentation/14.0/howtos/backend.html#inheritance

Avatar
Ignorer
Auteur Meilleure réponse

Thank you Ibrahim, but that is not what i'd asked for. 

Still,  I think I've managed to get how odoo manages inheritance of Python class implicitly using _inherit. Apparently, is by changing the __bases__ property of the Model classes.

This is at '_build_model' of models.py.

Avatar
Ignorer
Publications associées Réponses Vues Activité
0
mars 21
2123
0
août 24
1146
1
juil. 24
1919
1
mars 22
4725
1
juin 21
3105