Odoo Help


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.


Override Method without class?

Harsh Dhaduk
on 12/17/14, 1:59 AM 1,054 views

Hi All,

How to override method without class?


In a.py file have one method

def abc(self):
     print "Called ABC()"


In b.py i want to override a.py file's abc() method.


I clear about.

1) I am not talking about Class method override.
2) And no any class use in a.py and b.py
3) It is possible to override abc() method without class ?


Thanks in advance,
Harsh Dhaduk



| 5 3 6
Jakarta, Indonesia
On 12/17/14, 2:54 AM

from a import abc

def new_method():


abc = new_method


import a

def new_method():


a.abc = new_method

it's called monkey patching.  You can search the net for other examples, but here is one: http://stackoverflow.com/questions/19545982/monkey-patching-a-class-in-another-module-in-python

method abc is in module a

Ben Bernard
on 12/17/14, 4:14 AM

Good catch Ben. I've updated the answer.

on 12/17/14, 4:41 AM


| 5 4 8
Kochi, India
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

On 12/17/14, 2:59 AM

Hi Harsh,

To override a method you have to understand the object to which that method belongs.

If method abc() belongs to class object 'test'

ie. in .py file it will be like:-

class test (osv.osv):

    _name = 'test'

    def abc():

        return True


If you want to override that function you have to define a class to inherit that object and then define method with same name. Eg:-

IN b.py file

class test(osv.osv):

    _inherit = 'test'

    def abc():

        return True


Here we overrided the method abc()

Thanks a lot!

Pascal Tremblay
on 12/27/14, 1:10 PM


| 5 4 6
Zagreb | Karlovac, Croatia

there is only 10 kind of people the ones that understand binary ... and others

On 12/17/14, 2:52 AM

try in b.py:

import a
def ab1(self...):
   something here

a.abc = ab1


Harsh Dhaduk
On 12/17/14, 4:03 AM

Hi Baiju i am not talking about class method override.

Hi Ivan have other examples like monkey patching?

Hi Bole i tried that one but not working.


Thanks for your replay.

Google python monkey patch and you can get a lot of examples.

on 12/17/14, 4:10 AM

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

1 follower(s)


Asked: 12/17/14, 1:59 AM
Seen: 1054 times
Last updated: 3/16/15, 8:10 AM