diff --git a/apps/cm/views.py b/apps/cm/views.py index 4c980a7a..0c3952ca 100644 --- a/apps/cm/views.py +++ b/apps/cm/views.py @@ -1,9 +1,9 @@ -from django.shortcuts import render 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 rest_framework.exceptions import ParseError +from apps.wpm.models import WMaterial +from rest_framework.exceptions import ParseError, NotFound from rest_framework.response import Response from apps.utils.viewsets import CustomGenericViewSet, RetrieveModelMixin, CustomListModelMixin # Create your views here. @@ -25,7 +25,7 @@ class LableMatViewSet(CustomListModelMixin, RetrieveModelMixin, CustomGenericVie try: mb = MaterialBatch.objects.get(id=tid) except MaterialBatch.DoesNotExist: - raise ParseError('仓库明细不存在') + raise NotFound('仓库明细不存在') obj, _ = LableMat.objects.get_or_create( state=10, material=mb.material, @@ -36,4 +36,26 @@ class LableMatViewSet(CustomListModelMixin, RetrieveModelMixin, CustomGenericVie ) rdata = LabelMatSerializer(obj).data rdata["code_label"] = f"mat:{obj.id}" + return Response(rdata) + + @action(methods=['post'], detail=False, serializer_class=TidSerializer) + def get_from_wm(self, request, pk=None): + """ + 从车间库存明细获取物料标签 + + 从车间库存明细获取物料标签 + """ + tid = request.data.get('tid') + try: + wm = WMaterial.objects.get(id=tid) + except WMaterial.DoesNotExist: + raise NotFound('车间库存不存在') + obj, _ = LableMat.objects.get_or_create( + state=wm.state, + material=wm.material, + batch=wm.batch, + notok_sign=wm.notok_sign, + 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