Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
6632 มุมมอง

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)

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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]

อวตาร
ละทิ้ง