from copy import copy

from patch.include import *


@app_context(commit=True)
def patch():

    status_opts_list = models.CmfStatusOpt.list(
        filter=['OR', ["name", "==", None], ["color", "==", None]],
        fields=["status", "work_list"]
    )
    for status_opt in status_opts_list:
        if status_opt.work_list.value and status_opt.work_list.value.class_name == 'CmfList':
            if status_opt.name == None:
                status_opt.name = status_opt.status.name
            if status_opt.color == None:
                status_opt.color = status_opt.status.color
            status_opt.save()

if __name__ == "__main__":
    patch()
