feat: 从车间库存明细获取物料标签

This commit is contained in:
caoqianming 2024-10-16 11:13:25 +08:00
parent 46dd264dba
commit b28174309a
1 changed files with 25 additions and 2 deletions

View File

@ -1,7 +1,7 @@
from apps.cm.models import LableMat from apps.cm.models import LableMat
from rest_framework.decorators import action from rest_framework.decorators import action
from apps.cm.serializers import TidSerializer, LabelMatSerializer 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 apps.wpm.models import WMaterial
from rest_framework.exceptions import ParseError, NotFound from rest_framework.exceptions import ParseError, NotFound
from rest_framework.response import Response from rest_framework.response import Response
@ -58,4 +58,27 @@ class LableMatViewSet(CustomListModelMixin, RetrieveModelMixin, CustomGenericVie
material_origin=wm.material_origin) material_origin=wm.material_origin)
rdata = LabelMatSerializer(obj).data rdata = LabelMatSerializer(obj).data
rdata["code_label"] = f"mat:{obj.id}" rdata["code_label"] = f"mat:{obj.id}"
return Response(rdata) 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