تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
3146 أدوات العرض

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

الصورة الرمزية
إهمال
أفضل إجابة
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

الصورة الرمزية
إهمال
الكاتب أفضل إجابة

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.

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
0
مارس 21
2114
0
أغسطس 24
1120
1
يوليو 24
1882
1
مارس 22
4682
1
يونيو 21
3067