Inheritance using super(): When you inherit a method and call super() within the overridden method, it allows you to extend or modify the behavior of the original method while still executing the code of the overridden method in the parent class. This ensures that the original functionality is preserved while adding your custom logic.
For example:
class MyModule(models.Model):
_inherit = 'some.other.module'
def my_method(self):
# Custom code before the super call
res = super(MyModule, self).my_method()
# Custom code after the super call
return res
In this case, calling super() invokes the method in the parent class (the original method), and you can modify its behavior as needed.
Inheritance without super(): If you inherit a method but do not include a super() call within the overridden method, the original method in the parent class will not be executed automatically. Instead, only the code within the overridden method will be executed.
For example:
class MyModule(models.Model):
_inherit = 'some.other.module'
def my_method(self):
# Custom code without calling super()
return # No call to super()
In this case, the original method in the parent class will not be executed unless explicitly called within the overridden method.