feat: wpr获取新编号

This commit is contained in:
caoqianming 2025-05-12 16:47:04 +08:00
parent c744c07326
commit 56afccf0a4
2 changed files with 25 additions and 4 deletions

View File

@ -18,3 +18,9 @@ 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")

View File

@ -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):
@ -35,3 +37,16 @@ class WprViewSet(CustomListModelMixin, RetrieveModelMixin, CustomGenericViewSet)
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})