Odoo Help

0

How to override method inside a class in Odoo8

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

How to override method inside a class in Odoo8

I updated my answer please check now

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

Baiju KS

--Baiju KS--
3219
| 5 5 8
Kochi, India
--Baiju KS--
ODOO technical

        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 KS
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

About This Community

This platform 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.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

2 follower(s)

Stats

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