Skip to Content
Menu
This question has been flagged
2 Replies
5999 Views

I am duplicating projects and tasks, in that process, the one2many fields should also be duplicated.

I am using the create function instead of copy() function for duplicating the projects and tasks

This is the One2many field that i want to duplicate:

predecessor_ids = fields.One2many('project.task.predecessor', 'task_id', 'Links' ,copy=True)

Avatar
Discard
Best Answer

Hi,

Using the self you can iterate over the one2many lines and create a record in the one2many line model calling its create function and in the dictionary pass task_id as the id of the newly created task.


Thanks

Avatar
Discard
Best Answer

In the dictionary you use to create, add the key for predecessor_ids as 

'predecessor_ids': [(0,0,{
                                            'project.task.predecessor field1': line. field1,
                                            'project.task.predecessor field2': line. field2,

})for line in self.predecessor_ids]

Avatar
Discard