From 7429b7d5fbc95df6c96e428a259aaba8cf5d5d3d Mon Sep 17 00:00:00 2001 From: caoqianming Date: Fri, 30 May 2025 10:13:57 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9gen=5Fnumber=5Fwith?= =?UTF-8?q?=5Frule=20=E4=BB=A5=E8=8E=B7=E5=8F=96=E7=9A=84=E6=9C=80?= =?UTF-8?q?=E5=90=8E=E7=BC=96=E5=8F=B7=E4=B8=BA=E5=87=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/wpm/views.py | 10 +++++++--- apps/wpmw/views.py | 6 ++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/apps/wpm/views.py b/apps/wpm/views.py index d3544383..d54afa1b 100644 --- a/apps/wpm/views.py +++ b/apps/wpm/views.py @@ -694,14 +694,18 @@ class MlogbInViewSet(CreateModelMixin, UpdateModelMixin, DestroyModelMixin, Cust c_year2 = str(c_year)[-2:] c_month = now.month m_model = material_out.model - wps_qs = Wpr.objects.filter(material_start=material_out, create_time__year=c_year, create_time__month=c_month).order_by("create_time") - n_count = wps_qs.count() + 1 + wpr = Wpr.objects.filter(material_start=material_out, create_time__year=c_year, create_time__month=c_month).order_by("number").last() + if wpr: + try: + n_count = int(wpr.number.split("-")[-1].lstrip('0')) + except Exception as e: + raise ParseError(f"获取该类产品最后编号错误: {str(e)}") try: if gen_count == 1: return rule.format(c_year=c_year, c_month=c_month, m_model=m_model, n_count=n_count, c_year2=c_year2) else: return [rule.format(c_year=c_year, c_month=c_month, m_model=m_model, n_count=n_count+i, c_year2=c_year2) for i in range(gen_count)] - except (KeyError, ValueError) as e: + except Exception as e: raise ParseError(f"个号生成错误: {e}") class MlogbOutViewSet(UpdateModelMixin, CustomGenericViewSet): diff --git a/apps/wpmw/views.py b/apps/wpmw/views.py index 458398f2..217a8b4f 100644 --- a/apps/wpmw/views.py +++ b/apps/wpmw/views.py @@ -47,7 +47,9 @@ class WprViewSet(CustomListModelMixin, RetrieveModelMixin, CustomGenericViewSet) 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") + wpr_last = wps_qs.order_by("number").last() count = wps_qs.count() - last_number = wps_qs.last().number if count > 0 else None + last_number = wpr_last.number if count > 0 else None + last_number_count = int(last_number.split("-")[-1].lstrip('0')) mat = Material.objects.get(id=material_start) - return Response({"count": count, "last_number": last_number, "material_model":mat.model}) \ No newline at end of file + return Response({"count": count, "last_number": last_number, "material_model":mat.model, "last_number_count": last_number_count}) \ No newline at end of file