How to "directly" override a method in the osv Model class, such as write, create, etc, so that any new model that I create inherits this functionality?
I mean, suppose I am extending res.partner, sale.order, purchase.order and a bunch of other models, and I want to override write for all of them, adding the same code to every one (like logging or something). Can I do this without overriding write in every single model?
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 Julian,
def unlink(self, cr, uid, ids, context=None):
--- custome code --
after creating your method add this code
osv.osv.unlink = unlink
now your method is overrided the osv method
Thanks, this worked!
Hi Julian,
You can do as you want. Just see the following ex for the write method. It is override the write method of the osv.
from openerp.osv import orm
def custom_write(self, cr, uid, ids, vals, context=None):
..... Your code ...
return True
orm.BaseModel.write = custom_write
Thanks this worked!
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 | |
---|---|---|---|---|
|
1
thg 3 15
|
4795 | ||
|
3
thg 11 24
|
30019 | ||
|
1
thg 12 21
|
2759 | ||
|
0
thg 12 21
|
2324 | ||
|
3
thg 12 15
|
1367 |
Already asked related questions 1) https://www.odoo.com/forum/help-1/question/how-to-override-method-of-basemodel-orm-in-odoo-v8-61799 2) https://www.odoo.com/forum/help-1/question/inherit-create-function-in-the-new-framework-62150#answer-62249