根据产品变动日志更新生产进度
This commit is contained in:
parent
b76eeefe37
commit
004030e9df
|
@ -5,7 +5,7 @@ from apps.pm.models import SubProductionPlan, SubProductionProgress
|
||||||
from apps.mtm.models import Material, Step, SubprodctionMaterial
|
from apps.mtm.models import Material, Step, SubprodctionMaterial
|
||||||
from apps.qm.models import TestRecord
|
from apps.qm.models import TestRecord
|
||||||
from apps.system.models import User
|
from apps.system.models import User
|
||||||
from apps.wpm.models import WProduct, WprouctTicket
|
from apps.wpm.models import WProduct, WproductFlow, WprouctTicket
|
||||||
from utils.tools import ranstr
|
from utils.tools import ranstr
|
||||||
class WpmServies(object):
|
class WpmServies(object):
|
||||||
|
|
||||||
|
@ -61,11 +61,8 @@ class WpmServies(object):
|
||||||
wt = WprouctTicket.objects.order_by('id').last() #取最后的工单
|
wt = WprouctTicket.objects.order_by('id').last() #取最后的工单
|
||||||
if wt.step.process == test.step.process:
|
if wt.step.process == test.step.process:
|
||||||
wproduct.ng_sign = None
|
wproduct.ng_sign = None
|
||||||
# 更新子计划合格进度
|
# 更新子计划相关进度
|
||||||
ins = SubProductionProgress.objects.get(subproduction_plan=wproduct.subproduction_plan,
|
cls.update_subproduction_progress_main(sp=wproduct.subproduction_plan)
|
||||||
is_main=True, type=SubprodctionMaterial.SUB_MA_TYPE_OUT)
|
|
||||||
ins.count_ok = ins.count_ok + 1
|
|
||||||
ins.save()
|
|
||||||
else:# 如果不合格
|
else:# 如果不合格
|
||||||
wproduct.act_state = WProduct.WPR_ACT_STATE_NOTOK
|
wproduct.act_state = WProduct.WPR_ACT_STATE_NOTOK
|
||||||
# 需要走不合格品审理的工单
|
# 需要走不合格品审理的工单
|
||||||
|
@ -73,16 +70,18 @@ class WpmServies(object):
|
||||||
wproduct.test = None
|
wproduct.test = None
|
||||||
wproduct.save()
|
wproduct.save()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def update_subproduction_progress_main(cls, sp:SubProductionPlan, is_workdone:bool=False, is_testok:bool=False):
|
def update_subproduction_progress_main(cls, sp:SubProductionPlan):
|
||||||
"""
|
"""
|
||||||
更新生产进度
|
根据产品变动日志更新生产进度
|
||||||
"""
|
"""
|
||||||
if is_testok:
|
objs = WproductFlow.objects.filter(subporduction_plan=sp, is_lastlog=True)
|
||||||
|
count_ok = objs.filter(act_state__in=[WProduct.WPR_ACT_STATE_INM,
|
||||||
|
WProduct.WPR_ACT_STATE_OK, WProduct.WPR_ACT_STATE_SELLED]).count()
|
||||||
|
count_real = objs.exclude(act_state__in=[WProduct.WPR_ACT_STATE_TORETEST,
|
||||||
|
WProduct.WPR_ACT_STATE_DOWAIT, WProduct.WPR_ACT_STATE_DOING])
|
||||||
ins = SubProductionProgress.objects.get(subproduction_plan=sp,
|
ins = SubProductionProgress.objects.get(subproduction_plan=sp,
|
||||||
is_main=True, type=SubprodctionMaterial.SUB_MA_TYPE_OUT)
|
is_main=True, type=SubprodctionMaterial.SUB_MA_TYPE_OUT)
|
||||||
# 该计划下的所有产品
|
ins.count_ok = count_ok
|
||||||
wps = WProduct.objects.filter(subproduction_plan=sp)
|
ins.count_real = count_real
|
||||||
if is_workdone:
|
ins.save()
|
||||||
ins = SubProductionProgress.objects.get(subproduction_plan=sp,
|
|
||||||
is_main=True, type=SubprodctionMaterial.SUB_MA_TYPE_OUT)
|
|
|
@ -8,6 +8,7 @@ from django.dispatch import receiver
|
||||||
from rest_framework import exceptions
|
from rest_framework import exceptions
|
||||||
from apps.wpm.models import WProduct, WproductFlow, WprouctTicket
|
from apps.wpm.models import WProduct, WproductFlow, WprouctTicket
|
||||||
from apps.wpm.models import OperationWproduct
|
from apps.wpm.models import OperationWproduct
|
||||||
|
from apps.wpm.services import WpmServies
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_save, sender=Ticket)
|
@receiver(post_save, sender=Ticket)
|
||||||
|
@ -69,11 +70,7 @@ def handleTicket(sender, instance, created, **kwargs):
|
||||||
wp.act_state = WProduct.WPR_ACT_STATE_DOWAIT
|
wp.act_state = WProduct.WPR_ACT_STATE_DOWAIT
|
||||||
wp.save()
|
wp.save()
|
||||||
# 更新子计划合格进度
|
# 更新子计划合格进度
|
||||||
if sp != wt.subproduction_plan:
|
WpmServies.update_subproduction_progress_main(sp=sp)
|
||||||
ins = SubProductionProgress.objects.get(subproduction_plan=sp,
|
|
||||||
is_main=True, type=SubprodctionMaterial.SUB_MA_TYPE_OUT)
|
|
||||||
ins.count_ok = ins.count_ok - 1
|
|
||||||
ins.save()
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise exceptions.APIException('返回步骤点错误')
|
raise exceptions.APIException('返回步骤点错误')
|
||||||
|
|
|
@ -180,13 +180,19 @@ class WProductViewSet(ListModelMixin, GenericViewSet):
|
||||||
半成品
|
半成品
|
||||||
"""
|
"""
|
||||||
perms_map={'*':'*'}
|
perms_map={'*':'*'}
|
||||||
queryset = WProduct.objects.select_related('step', 'material', 'subproduction_plan').filter(is_hidden=False)
|
queryset = WProduct.objects.select_related('step', 'material', 'subproduction_plan')
|
||||||
serializer_class = WProductListSerializer
|
serializer_class = WProductListSerializer
|
||||||
filterset_class = WProductFilterSet
|
filterset_class = WProductFilterSet
|
||||||
search_fields = ['number']
|
search_fields = ['number']
|
||||||
ordering_fields = ['id']
|
ordering_fields = ['id']
|
||||||
ordering = ['id']
|
ordering = ['id']
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
queryset = self.queryset
|
||||||
|
if self.request.query_params.get('tag', None) != 'show_hidden':
|
||||||
|
queryset = queryset.filter(is_hidden=False)
|
||||||
|
return queryset
|
||||||
|
|
||||||
@action(methods=['post'], detail=False, perms_map={'post':'*'}, serializer_class=WpmTestFormInitSerializer)
|
@action(methods=['post'], detail=False, perms_map={'post':'*'}, serializer_class=WpmTestFormInitSerializer)
|
||||||
def test_init(self, request, pk=None):
|
def test_init(self, request, pk=None):
|
||||||
"""
|
"""
|
||||||
|
@ -283,7 +289,12 @@ class WProductViewSet(ListModelMixin, GenericViewSet):
|
||||||
FIFOItemProduct.objects.bulk_create(ips)
|
FIFOItemProduct.objects.bulk_create(ips)
|
||||||
# 更新库存并修改半成品进行状态
|
# 更新库存并修改半成品进行状态
|
||||||
update_inm(fifo)
|
update_inm(fifo)
|
||||||
wproducts.update(act_state=WProduct.WPR_ACT_STATE_INM, warehouse=warehouse, update_by=request.user, update_time=timezone.now())
|
for i in wproducts:
|
||||||
|
i.act_state = WProduct.WPR_ACT_STATE_INM
|
||||||
|
i.warehouse = warehouse
|
||||||
|
i.update_by = request.user
|
||||||
|
i.update_time = timezone.now()
|
||||||
|
i.save()
|
||||||
return Response()
|
return Response()
|
||||||
|
|
||||||
@action(methods=['post'], detail=True, perms_map={'post':'*'}, serializer_class=WproductPutInSerializer)
|
@action(methods=['post'], detail=True, perms_map={'post':'*'}, serializer_class=WproductPutInSerializer)
|
||||||
|
@ -544,10 +555,7 @@ class OperationViewSet(ListModelMixin, RetrieveModelMixin, CreateModelMixin, Upd
|
||||||
# 更新子计划生产进度
|
# 更新子计划生产进度
|
||||||
# 如果产品有返工标记不做计算
|
# 如果产品有返工标记不做计算
|
||||||
if wp.ng_sign not in [WProduct.NG_BACK_FIX, WProduct.NG_BACK_WORK]:
|
if wp.ng_sign not in [WProduct.NG_BACK_FIX, WProduct.NG_BACK_WORK]:
|
||||||
ins = SubProductionProgress.objects.get(subproduction_plan=wsp,
|
WpmServies.update_subproduction_progress_main(sp=wsp)
|
||||||
is_main=True, type=SubprodctionMaterial.SUB_MA_TYPE_OUT)
|
|
||||||
ins.count_real = ins.count_real + 1
|
|
||||||
ins.save()
|
|
||||||
wp.operation = None
|
wp.operation = None
|
||||||
wp.update_by = request.user
|
wp.update_by = request.user
|
||||||
wp.save()
|
wp.save()
|
||||||
|
@ -560,7 +568,8 @@ class OperationViewSet(ListModelMixin, RetrieveModelMixin, CreateModelMixin, Upd
|
||||||
act_state=WProduct.WPR_ACT_STATE_DOWAIT, remark='',
|
act_state=WProduct.WPR_ACT_STATE_DOWAIT, remark='',
|
||||||
subproduction_plan=i.subproduction_plan)
|
subproduction_plan=i.subproduction_plan)
|
||||||
for x in range(i.count):
|
for x in range(i.count):
|
||||||
WProduct.objects.create(**wpr)
|
WProduct.objects.create(**wpr)
|
||||||
|
WpmServies.update_subproduction_progress_main(sp=i.subproduction_plan)
|
||||||
elif step.type == Step.STEP_TYPE_COMB:
|
elif step.type == Step.STEP_TYPE_COMB:
|
||||||
oms_w = OperationMaterial.objects.filter(operation=op, type=SubprodctionMaterial.SUB_MA_TYPE_OUT,
|
oms_w = OperationMaterial.objects.filter(operation=op, type=SubprodctionMaterial.SUB_MA_TYPE_OUT,
|
||||||
subproduction_progress__is_main=True)
|
subproduction_progress__is_main=True)
|
||||||
|
@ -577,9 +586,7 @@ class OperationViewSet(ListModelMixin, RetrieveModelMixin, CreateModelMixin, Upd
|
||||||
else:
|
else:
|
||||||
wproduct.act_state = WProduct.WPR_ACT_STATE_TOTEST
|
wproduct.act_state = WProduct.WPR_ACT_STATE_TOTEST
|
||||||
# 更新子计划进度
|
# 更新子计划进度
|
||||||
instance = oms_w.subproduction_progress
|
WpmServies.update_subproduction_progress_main(sp=oms_w.subproduction_plan)
|
||||||
instance.count_real = instance.count_real + 1 # 这个地方可能会有问题,不够严谨
|
|
||||||
instance.save()
|
|
||||||
wproduct.create_by = request.user
|
wproduct.create_by = request.user
|
||||||
wproduct.save()
|
wproduct.save()
|
||||||
# 隐藏原半成品
|
# 隐藏原半成品
|
||||||
|
|
Loading…
Reference in New Issue