fix: batchst恢复成batch单一校验
This commit is contained in:
parent
c8d05bed68
commit
cdb9083def
|
@ -247,10 +247,8 @@ class InmService:
|
||||||
BatchLog.clear(mio=instance)
|
BatchLog.clear(mio=instance)
|
||||||
else:
|
else:
|
||||||
for item in MIOItem.objects.filter(mio=instance):
|
for item in MIOItem.objects.filter(mio=instance):
|
||||||
if item.mb: # 说明录入到已有批次
|
BatchSt.g_create(
|
||||||
BatchSt.g_create(batch=item.batch)
|
batch=item.batch, mio=instance, material_start=item.material, reuse_node=True)
|
||||||
else:
|
|
||||||
BatchSt.g_create(batch=item.batch, mio=instance, material_start=item.material)
|
|
||||||
from apps.pum.services import PumService
|
from apps.pum.services import PumService
|
||||||
if is_reverse:
|
if is_reverse:
|
||||||
cls.update_mb(instance, -1)
|
cls.update_mb(instance, -1)
|
||||||
|
@ -262,10 +260,8 @@ class InmService:
|
||||||
BatchLog.clear(mio=instance)
|
BatchLog.clear(mio=instance)
|
||||||
else:
|
else:
|
||||||
for item in MIOItem.objects.filter(mio=instance):
|
for item in MIOItem.objects.filter(mio=instance):
|
||||||
if item.mb:
|
BatchSt.g_create(
|
||||||
BatchSt.g_create(batch=item.batch)
|
batch=item.batch, mio=instance, material_start=item.material, reuse_node=True)
|
||||||
else:
|
|
||||||
BatchSt.g_create(batch=item.batch, mio=instance, material_start=item.material)
|
|
||||||
if is_reverse:
|
if is_reverse:
|
||||||
cls.update_mb(instance, -1)
|
cls.update_mb(instance, -1)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -616,18 +616,32 @@ class BatchSt(BaseModel):
|
||||||
unique_together = [("batch", "version")]
|
unique_together = [("batch", "version")]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def g_create(cls, batch:str, mio=None, handover=None, mlog=None, material_start=None):
|
def g_create(cls, batch:str, mio=None, handover=None, mlog=None, material_start=None, reuse_node=False):
|
||||||
"""
|
"""
|
||||||
创建新的批次
|
创建新的批次
|
||||||
"""
|
"""
|
||||||
if mio is None and handover is None and mlog is None:
|
if mio is None and handover is None and mlog is None:
|
||||||
return cls.objects.get_or_create(batch=batch, version=1)
|
try:
|
||||||
|
node = cls.objects.get(batch=batch)
|
||||||
|
except cls.DoesNotExist:
|
||||||
|
return cls.objects.create(batch=batch), True
|
||||||
|
except cls.MultipleObjectsReturned:
|
||||||
|
# 兼容性处理
|
||||||
|
node = cls.objects.filter(batch=batch).order_by('-version').first()
|
||||||
|
return node, False
|
||||||
else:
|
else:
|
||||||
version = 1
|
version = 1
|
||||||
# 带有来源的批次获取,需检查批次号是否可用
|
# 带有来源的批次获取,需检查批次号是否可用
|
||||||
if cls.objects.filter(batch=batch, version=1).exists():
|
if cls.objects.filter(batch=batch).exists():
|
||||||
latest_version = BatchSt.objects.filter(batch=batch).aggregate(Max("version"))["version__max"]
|
if reuse_node:
|
||||||
version = latest_version + 1
|
node = cls.objects.filter(batch=batch).order_by('-version').first()
|
||||||
|
if node.material_start is not None and node.material_start != material_start:
|
||||||
|
raise ParseError(f"{batch}-该批次号因物料不同不可引用")
|
||||||
|
return node, False
|
||||||
|
else:
|
||||||
|
raise ParseError(f"{batch}-该批次号不可使用")
|
||||||
|
# latest_version = BatchSt.objects.filter(batch=batch).aggregate(Max("version"))["version__max"]
|
||||||
|
# version = latest_version + 1
|
||||||
if mio is None and handover is None and mlog is None:
|
if mio is None and handover is None and mlog is None:
|
||||||
raise ParseError("mio or handover or mlog must be provided")
|
raise ParseError("mio or handover or mlog must be provided")
|
||||||
ins = cls.objects.create(batch=batch, mio=mio, handover=handover, mlog=mlog, material_start=material_start, version=version)
|
ins = cls.objects.create(batch=batch, mio=mio, handover=handover, mlog=mlog, material_start=material_start, version=version)
|
||||||
|
|
Loading…
Reference in New Issue