from patch.include import *
from tqdm import tqdm

@app_context(commit=True)
def patch():
    with cmfutil.disable_acl(), cmfutil.disable_notify():
        tasks_with_children = set()
        for tsk in models.CmfTask.list(
            filter=["parent_task", "!=", None], fields=['parent_task']
        ):
            tasks_with_children.add(tsk.parent_task.id.value)
        for tsk in models.CmfTask.list(
            filter=["id", "IN", tasks_with_children]
        ):
            tsk.has_child_tasks = True
            tsk.save(only_data=True, emit=False, notify=False)

if __name__ == "__main__":
    patch()
