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