Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
2 Replies
3133 Tampilan

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
Buang
Jawaban Terbai
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
Buang
Penulis Jawaban Terbai

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
Buang
Post Terkait Replies Tampilan Aktivitas
0
Mar 21
2102
0
Agu 24
1112
1
Jul 24
1876
1
Mar 22
4670
1
Jun 21
3063