feat: 优化batches_to以达到自然排序功能
This commit is contained in:
parent
5d33301389
commit
45e02eae5f
|
@ -13,6 +13,7 @@ from rest_framework.exceptions import ParseError
|
||||||
from django.db.models import Count
|
from django.db.models import Count
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
from django.db.models import Max
|
from django.db.models import Max
|
||||||
|
import re
|
||||||
|
|
||||||
# Create your models here.
|
# Create your models here.
|
||||||
class SfLog(CommonADModel):
|
class SfLog(CommonADModel):
|
||||||
|
@ -673,7 +674,11 @@ class BatchSt(BaseModel):
|
||||||
handover = Handover.objects.filter(mtype=20, b_handover__batch=batch, submit_time__isnull=False).order_by('submit_time').first() # 拆分
|
handover = Handover.objects.filter(mtype=20, b_handover__batch=batch, submit_time__isnull=False).order_by('submit_time').first() # 拆分
|
||||||
handover2 = Handover.objects.filter(mtype=10, b_handover__batch=batch, submit_time__isnull=False).order_by('submit_time').first() # 合并
|
handover2 = Handover.objects.filter(mtype=10, b_handover__batch=batch, submit_time__isnull=False).order_by('submit_time').first() # 合并
|
||||||
return ins
|
return ins
|
||||||
|
|
||||||
|
def custom_key(s):
|
||||||
|
match = re.search(r'(\d+)(?!.*\d)', s) # 匹配最后一个数字
|
||||||
|
return int(match.group(1)) if match else float('inf')
|
||||||
|
|
||||||
class BatchLog(BaseModel):
|
class BatchLog(BaseModel):
|
||||||
"""
|
"""
|
||||||
TN: 拆合批变更记录
|
TN: 拆合批变更记录
|
||||||
|
@ -709,8 +714,8 @@ class BatchLog(BaseModel):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def batches_to(cls, batch:str):
|
def batches_to(cls, batch:str):
|
||||||
batches = BatchLog.objects.filter(source__batch=batch).values_list("target__batch", flat=True).order_by("target__batch").distinct()
|
batches = BatchLog.objects.filter(source__batch=batch).values_list("target__batch", flat=True).distinct()
|
||||||
batches = list(batches)
|
batches = sorted(list(batches), key=custom_key)
|
||||||
last_batch_num = None
|
last_batch_num = None
|
||||||
if batches:
|
if batches:
|
||||||
last_batch = batches[-1]
|
last_batch = batches[-1]
|
||||||
|
|
Loading…
Reference in New Issue