コンテンツへスキップ
メニュー
この質問にフラグが付けられました

I just want to inherit fields.py file and want to override a method in Many2many class to append some code. 

アバター
破棄
最善の回答

Hi, 

Try monkey patch:

from odoo import fields.Many2many as Many2many_class

def function_name_as_you_like_it_to_be(..):
  // Your code here


Many2many_class.odoo_function_you_want_to_override() = function_name_as_you_like_it_to_be

----------------------------------

your  code should look like this, using methode "groupable" as an example:

from odoo import fields.Many2many as Many2many_class

@property
def groupable(self):
//my code here   
return self.store 

Many2many_class.groupable = groupable


hope this helps.

Upvote if it does or write back for further analysis.

Regards.

アバター
破棄
著作者

It works. Thank you a lot.

著作者

How we can call super metho inside the patched method?

@property
def groupable(self):
//my code here
super().groupable()
return self.store

You changed the native function to a new one.
So either add what you want within your patched function.

Or if it's in another module, you just inherit it as you normally do.

著作者 最善の回答

How can we call the method with super() in Monkey patching?

アバター
破棄
関連投稿 返信 ビュー 活動
2
9月 23
9727
1
2月 22
6699
2
7月 19
2771
0
11月 18
2780
4
9月 18
4763