from apps.pm.models import Utask, Mtask


def correct_utask_state():
    utaskIds = Utask.objects.all().values_list('id', flat=True)
    for utaskId in utaskIds:
        if Mtask.objects.filter(utask__id=utaskId).exclude(state=Mtask.MTASK_SUBMIT).count() == 0:
            Utask.objects.filter(id=utaskId).update(state=Utask.UTASK_SUBMIT)
