42 lines
1.4 KiB
Python
42 lines
1.4 KiB
Python
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 rest_framework.response import Response
|
|
from apps.utils.viewsets import CustomGenericViewSet
|
|
# Create your views here.
|
|
|
|
class LableMatViewSet(CustomGenericViewSet):
|
|
perms_map = {"post": "*"}
|
|
@action(methods=['post'], detail=False, serializer_class=TidSerializer)
|
|
def get_from_mb(self, request, pk=None):
|
|
"""
|
|
从仓库明细获取物料标签
|
|
|
|
从仓库明细获取物料标签
|
|
"""
|
|
tid = request.data.get('tid')
|
|
try:
|
|
mb = MaterialBatch.objects.get(id=tid)
|
|
except MaterialBatch.DoesNotExist:
|
|
raise ParseError('仓库明细不存在')
|
|
obj, _ = LableMat.objects.get_or_create(
|
|
state=10,
|
|
material=mb.material,
|
|
batch=mb.batch,
|
|
defaults={
|
|
"supplier": mb.supplier
|
|
}
|
|
)
|
|
return Response({"label": f"mat:{obj.id}"})
|
|
|
|
def info(self, request, pk=None):
|
|
"""
|
|
获取物料标签信息
|
|
|
|
获取物料标签信息
|
|
"""
|
|
obj = self.get_object()
|
|
return Response(LabelMatSerializer(obj).data) |