# Create your tasks here
from __future__ import absolute_import, unicode_literals
from apps.utils.tasks import CustomTask
from celery import shared_task
from .models import Order, OrderItem


# @shared_task(base=CustomTask)
# def change_order_state_when_schedue(orderitemIds):
#     """排产后更新orderstate
#     """
#     orderIds = list(OrderItem.objects.filter(
#         id__in=orderitemIds).values_list('order__id', flat=True).distinct())
#     for i in orderIds:
#         order = Order.objects.get(id=i)
#         state = Order.ORDER_PLANED
#         orderitems = OrderItem.objects.filter(order__id=i)
#         for item in orderitems:
#             if item.mtask is None:
#                 state = Order.ORDER_PLANING
#         order.state = state
#         order.save()
