Odoo Help

2

How to override a global function?

By
René Schuster
on 7/31/14, 5:00 AM 1,768 views

Some modules contain global functions, i.e. function that are not class methods.

How can I override those with a custom module? Or what is the best practice to change this functions behavior?

Any help is highly appreciated.

 

Thanks.

This question has been included in the official documentation.
4

Hello Rene,

There are 2 ways to do this kind of programming.

1) For complete override the global function :

For example, there is one global method "fields_get" into orm file of osv model. In order to override this global method you need to follow below steps,

  •  Define one global function into you custom module. 

  • from osv import orm
    def my_fields_get(....)     .......
  • Write down the following line for the override the basic gloal function.

           orm.fields_get = my_fields_get

          Note : After doing this code, It will override the basic method of the orm file.

2) For just made some extension into currently available global function.

For example there is one global method fields_get into orm file of osv model.

  • Define one global function into you custom module. 

from osv import orm
native_fields_get = orm.fields_get
def my_fields_get(....)     ....... #custome extension code.     res = native_fields_get(....)     ....... #custome extension code.     return res
  • Write down the following line for the override the basic gloal function.

    orm.fields_get = my_fields_get

    Note : It will call the basic global function of orm file, too.

Thanks. It works.

René Schuster
on 8/22/14, 4:22 AM

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

1 follower(s)

Stats

Asked: 7/31/14, 5:00 AM
Seen: 1768 times
Last updated: 8/19/15, 5:23 AM