Hello, I have a visit class where I have several record fields including a contact_tag field which can be chosen more than one, but when saving I want a record to be duplicated for each contact-Tag separately.
That is to say, create as many duplicate records for each line of a contact_Tag field when clicking on save (in each duplicate record only the contact_Tag field changes), I was trying to put it from the create method but I don't know how to pass it the iteration of each contact_Tag, Could you guide me a little please, I would appreciate it.
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- 客戶關係
- e-Commerce
- 會計
- 庫存
- PoS
- Project
- MRP
此問題已被標幟
Hii MANUEL APONTE,
->You can achieve this functionality with the help of copy() method.
->You can write below code to achieve your functionality.
@api.model
def create(self, vals):
result = super(SaleOrder, self).create(vals)
if not result._context.get('from_copy') and len(result.contact_Tag)>1:
for record in result.contact_Tag:
result.with_context({'from_copy':True}).copy({
'contact_Tag':[(4,record.id)]
})
return result
->Explaination:Here we are using copy() method to create the duplicate record and we are passing the context in order to bypass the recursion as copy() method internally calls create() method.
I hope this can help you.
Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari
Thank you very much Jainesh Shah, it worked well with the copy, I was trying with the create define more than once but it only executed the last one.