feat: 增加从车间库存明细获取物料标签
This commit is contained in:
parent
ebf3bbe257
commit
af751f5a9d
|
@ -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)
|
Loading…
Reference in New Issue