from patch.include import *
from tqdm import tqdm


@app_context(commit=True)
def patch():
    with cmfutil.disable_acl(), cmfutil.disable_notify():
        # Инициализируем поле parent_task у op_gantt_task
        # DEV-1624986135
        for task in tqdm(models.CmfTask.list(fields=['op_gantt_task.parent_task', 'parent_task'],
                                                filter=['op_gantt_task.parent_task', '=', None])):
            # Такого по-идее быть не должно
            if not task.op_gantt_task:
                continue
            task.op_gantt_task.parent_task = task.parent_task
            task.op_gantt_task.save(only_data=True)


if __name__ == "__main__":
    patch()
