feat: 修改gen_number_with_rule 以获取的最后编号为准
This commit is contained in:
parent
8994b39917
commit
7429b7d5fb
|
@ -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):
|
||||
|
|
|
@ -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})
|
||||
return Response({"count": count, "last_number": last_number, "material_model":mat.model, "last_number_count": last_number_count})
|
Loading…
Reference in New Issue