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:
- CRM
- e-Commerce
- Comptabilité
- Inventaire
- PoS
- Project
- MRP
Cette question a été signalée
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.
Vous appréciez la discussion ? Ne vous contentez pas de lire, rejoignez-nous !
Créez un compte dès aujourd'hui pour profiter de fonctionnalités exclusives et échanger avec notre formidable communauté !
S'inscrire