跳至内容
菜单
此问题已终结
1 回复
9598 查看

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.

形象
丢弃
最佳答案

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.

相关帖文 回复 查看 活动
1
6月 16
4836
1
8月 21
6684
0
1月 17
4812
1
4月 22
5802
2
5月 18
27777