plz can anyone told me how to modify the default "copy" duplicate function by inheretance???
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ờ
Here is the syntax to override def copy
function in your module:
def copy(self, cr, uid, id, default=None, context=None):
"""
Duplicate record with given id updating it with default values
:param default: dictionary of field values to override in the original values of the copied record, e.g: ``{'field_name': overriden_value, ...}``
:type default: dictionary
"""
if default is None:
default = {}
#Todo code (You can pass your value of any field in default)
default.update({'your_field': value})
return super(your_class_name, self).copy(cr, uid, id, default=default, context=context)
You can refer ORM Copy Method.
with new api:
@api.one
def copy(self, default=None):
default = dict(default or {})
default.update({
'[field you want to change the default value of]': '[value you want]',
})
return super([class you are changing], self).copy(default)
+1 for using new API
Still works in Odoo 13
Quick note that in Odoo V14 and up you should remove the @api.one because it has been deprecated. The rest still applies :)
Write a new function that overrides the original one and calls the original with your changes:
def copy(self, cr, uid, id, default={}, context=None):
if not default:
default = {}
default.update({
'[field you want to change the default value of]': '[value you want]',
})
return super([class you are changing], self).copy(cr, uid, id, default, context=context)`
Hi,
I have done same in Odoo v10. May be its help to others.
@api.one
@api.returns('self', lambda value: value.id)
def copy(self, default=None):
default = dict(default or {})
default.update({
'invoice_date': ''})
return super(AccountInvoice, self).copy(default)
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 | |
---|---|---|---|---|
|
3
thg 8 24
|
15338 | ||
|
3
thg 7 23
|
67931 | ||
|
2
thg 6 23
|
4265 | ||
|
0
thg 10 17
|
2584 | ||
|
1
thg 7 16
|
10797 |