Difference Between Inheriting a Method vs Overriding a Method


1. Inheriting a Method


✅ Definition:

An inherited method is a method that is not redefined in the child class but is available for use because the class inherits from a parent that defines it.


✅ Behavior:

  • You can use the method directly in your class.
  • You do not change its logic.
  • You're simply benefiting from the existing functionality.

✅ Odoo Example:


class CustomSaleOrder(models.Model):

    _inherit = 'sale.order'

    def some_custom_logic(self):

        self.action_confirm()  # This method is inherited from 'sale.order'


  • Here, action_confirm() is inherited. You are calling it as-is, without changing its logic.



2. Overriding a Method


✅ Definition:

An overridden method is a method that is explicitly redefined in your child class to modify or extend its original behavior.


✅ Behavior:

  • You can change the behavior completely.
  • Or you can add extra logic before or after calling the parent method using super().


✅ Odoo Example:


class CustomSaleOrder(models.Model):

    _inherit = 'sale.order'


    def action_confirm(self):

        # Custom logic

        _logger.info(f"Confirming sale order: {self.name}")

        # Call original method

        return super().action_confirm()


Here, action_confirm() is overridden — the method exists in the parent, and you are modifying its behavior.



🧠 Key Differences


Criteria

Inherited Method

Overridden Method

Defined in child class

❌ No

✅ Yes

Logic changed

❌ No

✅ Yes

Uses super()

❌ Not applicable

✅ Usually

Purpose

To use parent method

To customize parent method

Example

Call action_confirm() as-is

Redefine action_confirm() to add logic



✅ Summary

  • Inheriting a method: Using it without changing its logic.
  • Overriding a method: Redefining it to change or extend its behavior.

Every overridden method is inherited, but not every inherited method is overridden.