Skip to content

Instantly share code, notes, and snippets.

@vijoin
Last active July 12, 2019 20:48
Show Gist options
  • Save vijoin/0cfa7d719cfd5aa2e0063e74d3a7908c to your computer and use it in GitHub Desktop.
Save vijoin/0cfa7d719cfd5aa2e0063e74d3a7908c to your computer and use it in GitHub Desktop.
Odoo: Ignoring Method inheritance in multiple inheritance

There are cases when you need to re-write a method defined in a module (module_A) which already inherits an Odoo module. You want your improvements into a new module (module_B), but you don't want to execute anything from the method in module_A.

History short: Call the super() directly from module_A

Inheritance for method _search in module_A.HrExpenseFirstInheritance

from odoo import models, fields, api, _

class HrExpenseFirstInheritance(models.Model):
    _inherit = 'hr.expense.expense'
    
    def _search(self, args, offset=0, limit=None, order=None, count=False, access_rights_uid=None):
        #Your code here. i.e define new_args
        new_args = more_code
        
        #This is the normal call for his parent method
        return super(HrExpenseFirstInheritance, self)._search(new_args, offset, limit, order, count=count,
                                                         access_rights_uid=access_rights_uid)

Inheritance for method _search in module_B.HrExpenseSecondInheritance

from odoo.addons.module_A.models import hr_expense_inheritedA

class HrExpenseExpenseSecondInheritance(models.Model):
    _inherit = 'hr.expense.expense'
    
    def _search(self, args, offset=0, limit=None, order=None, count=False, access_rights_uid=None):
        #Your new code here. i.e define new_args,completly different from the defined in module_A
        new_args = more_code_totally_different
        
        #Call the super in module_A
        return super(hr_expense_inheritedA.HrExpenseFirstInheritance, self)._search(new_args, offset, limit, order, count=count,
                                                         access_rights_uid=access_rights_uid)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment