From b28174309a4ac1927ec647443732732fc87ceb0d Mon Sep 17 00:00:00 2001 From: caoqianming Date: Wed, 16 Oct 2024 11:13:25 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BB=8E=E8=BD=A6=E9=97=B4=E5=BA=93?= =?UTF-8?q?=E5=AD=98=E6=98=8E=E7=BB=86=E8=8E=B7=E5=8F=96=E7=89=A9=E6=96=99?= =?UTF-8?q?=E6=A0=87=E7=AD=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/cm/views.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/apps/cm/views.py b/apps/cm/views.py index 0c3952ca..13b0c13d 100644 --- a/apps/cm/views.py +++ b/apps/cm/views.py @@ -1,7 +1,7 @@ from apps.cm.models import LableMat from rest_framework.decorators import action from apps.cm.serializers import TidSerializer, LabelMatSerializer -from apps.inm.models import MaterialBatch +from apps.inm.models import MaterialBatch, MIOItem from apps.wpm.models import WMaterial from rest_framework.exceptions import ParseError, NotFound from rest_framework.response import Response @@ -58,4 +58,27 @@ class LableMatViewSet(CustomListModelMixin, RetrieveModelMixin, CustomGenericVie material_origin=wm.material_origin) rdata = LabelMatSerializer(obj).data rdata["code_label"] = f"mat:{obj.id}" - return Response(rdata) \ No newline at end of file + return Response(rdata) + + @action(methods=['post'], detail=False, serializer_class=TidSerializer) + def get_from_mioitem(self, request, pk=None): + """ + 从出入库明细获取物料标签 + + 从出入库明细获取物料标签 + """ + tid = request.data.get('tid') + try: + mioitem: MIOItem = MIOItem.objects.get(id=tid) + except MIOItem.DoesNotExist: + raise NotFound('出入库明细不存在') + obj, _ = LableMat.objects.get_or_create( + state=10, + material=mioitem.material, + batch=mioitem.batch, + defaults={ + "supplier": mioitem.mio.supplier + }) + rdata = LabelMatSerializer(obj).data + rdata["code_label"] = f"mat:{obj.id}" + return rdata \ No newline at end of file