How to override method inside a class in Odoo8
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project management
- MRP
This question has been flagged
Hi,
You can use standard inheritance for this:-
_inherit = 'model' (without any _name)
You can use standard inheritance to add new behaviors/extend existing models. For example you want to add a new field to a 'custom.object' and add a new method:
class CustomObject(orm.Model):
_inherit = "custom.object"
_column = {
'my_field': fields.char('My new field')
}
def a_new_func(self, cr, uid, ids, x, y, context=None):
# my stuff
return something
**You can also override existing methods: [ if you want to inherit an existing method and add a few codes on it, you can use like this ]
here super calls the original method and returns the value and you can add your code after that
def existing(self, cr, uid, ids, x, y, z, context=None):
parent_res = super(CustomObject, self).existing(cr, uid, ids, x, y, z, context=context)
# my stuff <--- here goes your code
return parent_res_plus_my_stuff`
** In some cases you want to modify the entire functionality of a method and have to redefine that method, in that case you can simply define that function without using super :-
def existing(self, cr, uid, ids, x, y, z, context=None):
# my stuff <--- here goes your code
return my_stuff`
Hope this helps.
Using super you can override method inside a class
create a method with the same name and use super
I updated my answer please check now