Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
6601 Widoki

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)

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
Najlepsza odpowiedź

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]

Awatar
Odrzuć