feat: mio_purin
This commit is contained in:
parent
c6af3f7f62
commit
a4a96ce59e
|
@ -1,4 +1,7 @@
|
||||||
|
from rest_framework.exceptions import ValidationError
|
||||||
from apps.pum.models import PuOrderItem, PuPlan, PuPlanItem, PuOrder
|
from apps.pum.models import PuOrderItem, PuPlan, PuPlanItem, PuOrder
|
||||||
|
from django.db.models import F
|
||||||
|
from apps.inm.models import MIO, MIOItem
|
||||||
|
|
||||||
class PumService:
|
class PumService:
|
||||||
|
|
||||||
|
@ -14,6 +17,33 @@ class PumService:
|
||||||
puplan.state = state
|
puplan.state = state
|
||||||
puplan.save()
|
puplan.save()
|
||||||
|
|
||||||
|
def mio_purin(mio: MIO):
|
||||||
|
"""
|
||||||
|
采购入库成功后的操作
|
||||||
|
"""
|
||||||
|
pu_order = mio.pu_order
|
||||||
|
for i in MIOItem.objects.filter(mio=mio):
|
||||||
|
pu_orderitem = PuOrderItem.objects.get(material=i.material, pu_order=pu_order)
|
||||||
|
delivered_count = pu_orderitem.delivered_count + i.count
|
||||||
|
if delivered_count > pu_orderitem.count:
|
||||||
|
raise ValidationError(f'{i.material.name}-超出采购订单所需数量')
|
||||||
|
pu_orderitem.delivered_count = delivered_count
|
||||||
|
pu_orderitem.save()
|
||||||
|
pu_order_state = PuOrder.PUORDER_SHIP
|
||||||
|
qs = PuOrderItem.objects.filter(pu_order=pu_order, count__lte=F('delivered_count'))
|
||||||
|
if qs.exists():
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
pu_order_state = PuOrder.PUORDER_DONE
|
||||||
|
pu_order.state = pu_order_state
|
||||||
|
pu_order.save()
|
||||||
|
# 查看计划进度
|
||||||
|
qs2 = PuPlanItem.objects.filter(pu_order=pu_order).values_list('pu_plan', flat=True).distinct()
|
||||||
|
for puplan in qs2:
|
||||||
|
qs3 = PuPlanItem.objects.filter(pu_plan=puplan).values_list('pu_order__state', flat=True)
|
||||||
|
states = set(list(qs3))
|
||||||
|
if len(states) == 1 and states[0] == PuOrder.PUORDER_DONE:
|
||||||
|
puplan.state = PuPlan.PUPLAN_DONE
|
||||||
|
puplan.save()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,11 @@ from apps.pum.services import PumService
|
||||||
|
|
||||||
|
|
||||||
class SupplierViewSet(CustomModelViewSet):
|
class SupplierViewSet(CustomModelViewSet):
|
||||||
|
"""
|
||||||
|
list: 供应商
|
||||||
|
|
||||||
|
供应商
|
||||||
|
"""
|
||||||
queryset = Supplier.objects.all()
|
queryset = Supplier.objects.all()
|
||||||
serializer_class = SupplierSerializer
|
serializer_class = SupplierSerializer
|
||||||
search_fields = ['name', 'contact']
|
search_fields = ['name', 'contact']
|
||||||
|
@ -26,6 +31,11 @@ class SupplierViewSet(CustomModelViewSet):
|
||||||
|
|
||||||
|
|
||||||
class PuPlanViewSet(CustomModelViewSet):
|
class PuPlanViewSet(CustomModelViewSet):
|
||||||
|
"""
|
||||||
|
list: 采购计划
|
||||||
|
|
||||||
|
采购计划
|
||||||
|
"""
|
||||||
queryset = PuPlan.objects.all()
|
queryset = PuPlan.objects.all()
|
||||||
serializer_class = PuPlanSerializer
|
serializer_class = PuPlanSerializer
|
||||||
search_fields = ['name', 'number']
|
search_fields = ['name', 'number']
|
||||||
|
@ -54,6 +64,11 @@ class PuPlanViewSet(CustomModelViewSet):
|
||||||
return Response()
|
return Response()
|
||||||
|
|
||||||
class PuPlanItemViewSet(CustomModelViewSet):
|
class PuPlanItemViewSet(CustomModelViewSet):
|
||||||
|
"""
|
||||||
|
list: 采购计划明细
|
||||||
|
|
||||||
|
采购计划明细
|
||||||
|
"""
|
||||||
queryset = PuPlanItem.objects.all()
|
queryset = PuPlanItem.objects.all()
|
||||||
serializer_class = PuPlanItemSerializer
|
serializer_class = PuPlanItemSerializer
|
||||||
filterset_class = PuPlanItemFilter
|
filterset_class = PuPlanItemFilter
|
||||||
|
@ -71,6 +86,11 @@ class PuPlanItemViewSet(CustomModelViewSet):
|
||||||
|
|
||||||
|
|
||||||
class PuOrderViewSet(CustomModelViewSet):
|
class PuOrderViewSet(CustomModelViewSet):
|
||||||
|
"""
|
||||||
|
list: 采购订单
|
||||||
|
|
||||||
|
采购订单
|
||||||
|
"""
|
||||||
queryset = PuOrder.objects.all()
|
queryset = PuOrder.objects.all()
|
||||||
serializer_class = PuOrderSerializer
|
serializer_class = PuOrderSerializer
|
||||||
filterset_fields = ['state', 'supplier']
|
filterset_fields = ['state', 'supplier']
|
||||||
|
@ -105,6 +125,11 @@ class PuOrderViewSet(CustomModelViewSet):
|
||||||
|
|
||||||
|
|
||||||
class PuOrderItemViewSet(CustomModelViewSet):
|
class PuOrderItemViewSet(CustomModelViewSet):
|
||||||
|
"""
|
||||||
|
list: 采购订单明细
|
||||||
|
|
||||||
|
采购订单明细
|
||||||
|
"""
|
||||||
queryset = PuOrderItem.objects.all()
|
queryset = PuOrderItem.objects.all()
|
||||||
serializer_class = PuOrderItemSerializer
|
serializer_class = PuOrderItemSerializer
|
||||||
filterset_fields = ['material', 'pu_order']
|
filterset_fields = ['material', 'pu_order']
|
||||||
|
|
Loading…
Reference in New Issue