feat: wpr获取新编号
This commit is contained in:
parent
c744c07326
commit
56afccf0a4
|
@ -17,4 +17,10 @@ class WprSerializer(CustomModelSerializer):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Wpr
|
model = Wpr
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
|
|
||||||
|
|
||||||
|
class WprNewSerializer(serializers.Serializer):
|
||||||
|
year = serializers.IntegerField()
|
||||||
|
month = serializers.IntegerField()
|
||||||
|
material_start = serializers.CharField(label="物料ID")
|
|
@ -1,9 +1,11 @@
|
||||||
|
from rest_framework.decorators import action
|
||||||
from apps.utils.viewsets import CustomModelViewSet, CustomGenericViewSet
|
from apps.utils.viewsets import CustomModelViewSet, CustomGenericViewSet
|
||||||
from apps.utils.mixins import CustomListModelMixin, RetrieveModelMixin
|
from apps.utils.mixins import CustomListModelMixin, RetrieveModelMixin
|
||||||
|
|
||||||
from apps.wpmw.models import Wpr, WprDefect
|
from apps.wpmw.models import Wpr, WprDefect
|
||||||
from apps.wpmw.serializers import WprSerializer
|
from apps.wpmw.serializers import WprSerializer, WprNewSerializer
|
||||||
|
from rest_framework.response import Response
|
||||||
|
from apps.mtm.models import Material
|
||||||
|
|
||||||
|
|
||||||
class WprViewSet(CustomListModelMixin, RetrieveModelMixin, CustomGenericViewSet):
|
class WprViewSet(CustomListModelMixin, RetrieveModelMixin, CustomGenericViewSet):
|
||||||
|
@ -34,4 +36,17 @@ class WprViewSet(CustomListModelMixin, RetrieveModelMixin, CustomGenericViewSet)
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
qs.exclude(mb=None, wm=None)
|
qs.exclude(mb=None, wm=None)
|
||||||
return qs
|
return qs
|
||||||
|
|
||||||
|
@action(methods=['post'], detail=False, perms_map={'post': '*'}, serializer_class=WprNewSerializer)
|
||||||
|
def new_number(self, request, *args, **kwargs):
|
||||||
|
"""获取新的编号"""
|
||||||
|
data = request.data
|
||||||
|
year = data.get("year")
|
||||||
|
month = data.get("month")
|
||||||
|
material_start = data.get("material_start")
|
||||||
|
wps_qs = Wpr.objects.filter(material_start=material_start, create_time__year=year, create_time__month=month).order_by("create_time")
|
||||||
|
count = wps_qs.count()
|
||||||
|
last_number = wps_qs.last().number if count > 0 else None
|
||||||
|
mat = Material.objects.get(id=material_start)
|
||||||
|
return Response({"count": count, "last_number": last_number, "material_model":mat.model})
|
Loading…
Reference in New Issue