From 7c3e63668ec0e06b5a617068689706890ce85440 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Thu, 13 Nov 2025 16:29:55 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=8F=90=E4=BE=9B=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E7=BC=96=E5=8F=B7=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/wpm/serializers.py | 7 ++++++- apps/wpm/views.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/apps/wpm/serializers.py b/apps/wpm/serializers.py index 91da7ebd..991d7413 100644 --- a/apps/wpm/serializers.py +++ b/apps/wpm/serializers.py @@ -1549,4 +1549,9 @@ class MlogQuickSerializer(serializers.Serializer): mgroup = serializers.CharField(label="工段ID") route = serializers.CharField(label="工艺步骤ID", required=False) mtask = serializers.CharField(label="任务ID", required=False) - handle_user = serializers.CharField(label="操作人员ID") \ No newline at end of file + handle_user = serializers.CharField(label="操作人员ID") + + +class BatchChangeSerializer(serializers.Serializer): + old_batch = serializers.CharField(label="原批号") + new_batch = serializers.CharField(label="新批号") \ No newline at end of file diff --git a/apps/wpm/views.py b/apps/wpm/views.py index d6c0ca6a..062fb212 100644 --- a/apps/wpm/views.py +++ b/apps/wpm/views.py @@ -49,6 +49,7 @@ from .serializers import ( MlogQuickSerializer, MlogbwStartTestSerializer, HandoverListSerializer, + BatchChangeSerializer ) from .services import mlog_submit, handover_submit, mlog_revert, get_batch_dag, handover_revert from apps.wpm.services import mlog_submit_validate, generate_new_batch @@ -203,6 +204,35 @@ class WMaterialViewSet(CustomListModelMixin, CustomGenericViewSet): defect_ids = queryset.values_list("defect", flat=True).distinct() return Response(DefectSerializer(Defect.objects.filter(id__in=defect_ids), many=True).data) + @action(methods=["post"], detail=False, perms_map={"post": "*"}, serializer_class=BatchChangeSerializer) + @transaction.atomic + def change_batch(self, request, *args, **kwargs): + """修改批次号""" + sr = BatchChangeSerializer(data=request.data) + sr.is_valid(raise_exception=True) + vdata = sr.validated_data + new_batch = vdata["new_batch"] + old_batch = vdata["old_batch"] + if BatchSt.objects.filter(batch=new_batch).exists(): + raise ParseError("新批次号已存在,不可使用") + from apps.cm.models import LableMat + from apps.inm.models import MIOItem, MaterialBatch, MaterialBatchA, MIOItemA + from apps.qm.models import FtestWork + LableMat.objects.filter(batch=old_batch).update(batch=new_batch) + MIOItem.objects.filter(batch=old_batch).update(batch=new_batch) + MIOItemA.objects.filter(batch=old_batch).update(batch=new_batch) + MaterialBatch.objects.filter(batch=old_batch).update(batch=new_batch) + MaterialBatchA.objects.filter(batch=old_batch).update(batch=new_batch) + FtestWork.objects.filter(batch=old_batch).update(batch=new_batch) + + Mlog.objects.filter(batch=old_batch).update(batch=new_batch) + Mlogb.objects.filter(batch=old_batch).update(batch=new_batch) + WMaterial.objects.filter(batch=old_batch).update(batch=new_batch) + Handover.objects.filter(batch=old_batch).update(batch=new_batch) + Handoverb.objects.filter(batch=old_batch).update(batch=new_batch) + Handover.objects.filter(new_batch=old_batch).update(new_batch=new_batch) + BatchSt.objects.filter(batch=old_batch).update(batch=new_batch) + return Response() class MlogViewSet(CustomModelViewSet): """