I just want to inherit fields.py file and want to override a method in Many2many class to append some code.
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Kế toán
- Tồn kho
- PoS
- Project
- MRP
Câu hỏi này đã bị gắn cờ
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?
Bạn có hứng thú với cuộc thảo luận không? Đừng chỉ đọc, hãy tham gia nhé!
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!
Đăng kýBài viết liên quan | Trả lời | Lượt xem | Hoạt động | |
---|---|---|---|---|
|
2
thg 9 23
|
9706 | ||
|
1
thg 2 22
|
6668 | ||
|
2
thg 7 19
|
2768 | ||
|
0
thg 11 18
|
2776 | ||
Custom float field auto rounding?
Đã xử lý
|
|
4
thg 9 18
|
4754 |