from patch.include import *
from tqdm import tqdm


@app_context(commit=True)
def plan_date():
    """
    Для тестирования патча: ( cd /opt/eva-app; python3 -m patch.202410140743_plan_date )
    Здесь можно работать с моделями через models.CmfTask и т.д.
    Для прогрессбара используйте:
    for task in tqdm(models.CmfTask.list()):
        ...
    """
    print('Запуск патча plan_date')
    for field in tqdm(models.CmfUiFormField.list(filter=['name', 'IN', ['plan_start_date', 'plan_end_date']])):
        if field.name == 'plan_start_date':
            field.name = 'op_gantt_task.sched_start_date'
        elif field.name == 'plan_end_date':
            field.name = 'op_gantt_task.sched_finish_date'
        field.save(only_data=True)

if __name__ == "__main__":
    plan_date()
