Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
3145 Widoki

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

Awatar
Odrzuć
Najlepsza odpowiedź
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

Awatar
Odrzuć
Autor Najlepsza odpowiedź

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.

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
0
mar 21
2114
0
sie 24
1119
1
lip 24
1881
1
mar 22
4682
1
cze 21
3067