Search Here

Override Built-in Modules Button Method in Odoo

 In this article, you will learn how to override a button located in built-in modules like purchase, sales, crm, etc. To achieve this functionality we will use the super method provided by odoo.

Override Built-in Modules Button Method in Odoo

How to override button functionality in odoo

To override the button method in our custom module we are going to use the super method, the purpose of overriding any button is to add or modify the existing functionality that comes with odoo modules by default.

Built-in module code


class account_voucher(models.Model):
_name = 'account.voucher'
def button_proforma_voucher(self, cr, uid, ids, context=None):
self.signal_workflow(cr, uid, ids, 'proforma_voucher')
return {'type': 'ir.actions.act_window_close'}
In the above code, we have an account.voucher model and this model contains a button named "button_proforma_voucher". Now we want to override this button in our custom module. To do this we have to inherit this model and button method in our custom module.


class account_voucher(models.Model):
_inherit = 'account.voucher'
# By using old api
def button_proforma_voucher(self,cr, uid, ids, context=None):
obj = super(account_voucher, self).button_proforma_voucher(cr, uid, ids, context=None)
# add your custom functionality here
return obj
# By using new api
@api.multi
def button_proforma_voucher(self):
obj = super(account_voucher, self).button_proforma_voucher()
# add your custom functionality here
return obj

Post a Comment

0 Comments