Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
6364 Lượt xem

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)

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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]

Ảnh đại diện
Huỷ bỏ