fix: batchst并发创建的处理
This commit is contained in:
parent
e2c7847c74
commit
4b52c28b5e
|
@ -665,17 +665,15 @@ class BatchSt(BaseModel):
|
||||||
"""
|
"""
|
||||||
if mioitem:
|
if mioitem:
|
||||||
mio = mioitem.mio
|
mio = mioitem.mio
|
||||||
try:
|
node, created = cls.safe_get_or_create(batch=batch, version=1, defaults={
|
||||||
node = cls.objects.get(batch=batch, version=1)
|
"mio":mio, "mioitem":mioitem, "handover":handover, "mlog":mlog, "material_start":material_start})
|
||||||
if check_mat_start:
|
if not created and check_mat_start:
|
||||||
if node.material_start is None:
|
if node.material_start is None:
|
||||||
node.material_start = material_start
|
node.material_start = material_start
|
||||||
node.save(update_fields = ["material_start"])
|
node.save(update_fields = ["material_start"])
|
||||||
if node.material_start != material_start:
|
if node.material_start != material_start:
|
||||||
raise ParseError(f"{batch}-该批次号因物料不同不可引用")
|
raise ParseError(f"{batch}-该批次号因物料不同不可引用")
|
||||||
return node, False
|
return node, created
|
||||||
except cls.DoesNotExist:
|
|
||||||
return cls.objects.create(batch=batch, mio=mio, mioitem=mioitem, handover=handover, mlog=mlog, material_start=material_start, version=1), True
|
|
||||||
|
|
||||||
# if mio is None and handover is None and mlog is None:
|
# if mio is None and handover is None and mlog is None:
|
||||||
# try:
|
# try:
|
||||||
|
@ -778,9 +776,15 @@ class BatchLog(BaseModel):
|
||||||
if target.mio is None and target.mioitem is None:
|
if target.mio is None and target.mioitem is None:
|
||||||
target.delete()
|
target.delete()
|
||||||
if mio:
|
if mio:
|
||||||
BatchSt.objects.filter(mio=mio).delete()
|
ts = BatchSt.objects.filter(mio=mio)
|
||||||
|
for t in ts:
|
||||||
|
if not BatchLog.objects.filter(Q(source=t) | Q(target=t)).exists():
|
||||||
|
t.delete()
|
||||||
if mioitem:
|
if mioitem:
|
||||||
BatchSt.objects.filter(mioitem=mioitem).delete()
|
ts = BatchSt.objects.filter(mioitem=mioitem)
|
||||||
|
for t in ts:
|
||||||
|
if not BatchLog.objects.filter(Q(source=t) | Q(target=t)).exists():
|
||||||
|
t.delete()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def batches_to(cls, batch:str):
|
def batches_to(cls, batch:str):
|
||||||
|
|
Loading…
Reference in New Issue