I am trying to copy create (duplicate) the tab called 'predecessor' which is a one2many field . In the same, i want to map the subtask to the corresponding parent task
Code:
pred_rec = self.env['project.task.predecessor'].search([('task_id', '=', task.id)])
new_parent=self.env['project.task.predecessor']
for predecessor_idrec in pred_rec:
for taskid in pred_rec:
if not taskid.parent_task_id:
new_parent=taskid
for subtask in pred_rec:
if subtask.id!=new_parent.id:
subtask.write({'parent_task_id':new_parent.id})
predecessor_vals = {
'lag_type': predecessor_idrec.lag_type,
'parent_task_id': predecessor_idrec.parent_task_id,
'task_id': new_task.id,
'type': predecessor_idrec.type,
}
predecessor_rec = self.env['project.task.predecessor'].create(predecessor_vals)
parent_task_id is the name of the parent task field
I am getting the following error:
The operation cannot be completed, probably due to the following:
- deletion: you may be trying to delete a record while other records still reference it
- creation/update: a mandatory field is not correctly set
[object with reference: parent_task_id - parent.task.id]
This is because parent_task_id 's value is null
I am unable to solve the error