Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to override method inside a class in Odoo8

By
Giezel Esteves
on 9/21/16, 10:44 PM 184 views

How to override method inside a class in Odoo8

I updated my answer please check now

Baiju
on 9/25/16, 2:28 AM
1

Baiju

--Baiju--
3154
| 5 4 8
Kochi, India
--Baiju--
ODOO technical and functional

        I like learning new thing, especially technical thing. I am a quick learner, I can learn technical things very fast. I have good logical skill,  I have immense interest in programming.

e-mail id : baijuks@hotmail.com

Baiju
On 9/25/16, 2:28 AM

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.



0
Sunny Dabgar
On 9/22/16, 2:28 AM

Using super you can override method inside a class

create a method with the same name and use super

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 9/21/16, 10:44 PM
Seen: 184 times
Last updated: 9/25/16, 6:15 AM