fix: batchlog创建时避免回环
This commit is contained in:
parent
e47464805e
commit
a4f2b6eb55
|
@ -621,18 +621,20 @@ 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, reuse_node=False):
|
def g_create(cls, batch:str, mio=None, handover=None, mlog=None, material_start=None, reuse_node=False, exclude_batchst_ids=[]):
|
||||||
"""
|
"""
|
||||||
创建新的批次
|
创建新的批次
|
||||||
"""
|
"""
|
||||||
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:
|
||||||
node = cls.objects.get(batch=batch)
|
node = cls.objects.exclude(id__in=exclude_batchst_ids).get(batch=batch)
|
||||||
except cls.DoesNotExist:
|
except cls.DoesNotExist:
|
||||||
return cls.objects.create(batch=batch), True
|
return cls.objects.create(batch=batch), True
|
||||||
except cls.MultipleObjectsReturned:
|
except cls.MultipleObjectsReturned:
|
||||||
# 兼容性处理
|
# 兼容性处理
|
||||||
node = cls.objects.filter(batch=batch).order_by('-version').first()
|
node = cls.objects.filter(batch=batch).exclude(id__in=exclude_batchst_ids).order_by('-version').first()
|
||||||
|
if node is None:
|
||||||
|
raise ParseError(f"{node.batch}-该批次号本次操作不可引用")
|
||||||
return node, False
|
return node, False
|
||||||
else:
|
else:
|
||||||
version = 1
|
version = 1
|
||||||
|
|
|
@ -175,14 +175,17 @@ def mlog_submit(mlog: Mlog, user: User, now: Union[datetime.datetime, None]):
|
||||||
can_matoutIds = process.get_canout_mat_ids()
|
can_matoutIds = process.get_canout_mat_ids()
|
||||||
# 建立关系链
|
# 建立关系链
|
||||||
m_outs = Mlogb.objects.filter(mlog=mlog, material_out__isnull=False)
|
m_outs = Mlogb.objects.filter(mlog=mlog, material_out__isnull=False)
|
||||||
|
exclude_batchst_ids = []
|
||||||
for item in m_outs:
|
for item in m_outs:
|
||||||
if item.mlogb_from and item.batch != item.mlogb_from.batch:
|
if item.mlogb_from and item.batch != item.mlogb_from.batch:
|
||||||
source, _ = BatchSt.g_create(batch=item.mlogb_from.batch)
|
source, _ = BatchSt.g_create(batch=item.mlogb_from.batch, exclude_batchst_ids=exclude_batchst_ids)
|
||||||
target, _ = BatchSt.g_create(batch=item.batch, mlog=mlog, material_start=item.material_out)
|
target, _ = BatchSt.g_create(batch=item.batch, mlog=mlog, material_start=item.material_out)
|
||||||
|
exclude_batchst_ids.append(target.id)
|
||||||
BatchLog.g_create(source= source, target=target, mlog=mlog)
|
BatchLog.g_create(source= source, target=target, mlog=mlog)
|
||||||
if item.mlogbw_from and item.batch != item.mlogbw_from.mlogb.batch:
|
if item.mlogbw_from and item.batch != item.mlogbw_from.mlogb.batch:
|
||||||
source, _ = BatchSt.g_create(batch=item.mlogbw_from.mlogb.batch)
|
source, _ = BatchSt.g_create(batch=item.mlogbw_from.mlogb.batch, exclude_batchst_ids=exclude_batchst_ids)
|
||||||
target, _ = BatchSt.g_create(batch=item.batch, mlog=mlog, material_start=item.material_out)
|
target, _ = BatchSt.g_create(batch=item.batch, mlog=mlog, material_start=item.material_out)
|
||||||
|
exclude_batchst_ids.append(target.id)
|
||||||
BatchLog.g_create(source=source, target=target, mlog=mlog)
|
BatchLog.g_create(source=source, target=target, mlog=mlog)
|
||||||
|
|
||||||
if material_in or is_fix: # 需要进行车间库存管理
|
if material_in or is_fix: # 需要进行车间库存管理
|
||||||
|
@ -746,6 +749,7 @@ def handover_submit(handover:Handover, user: User, now: Union[datetime.datetime,
|
||||||
raise ParseError("合并批次时请提供新批次号")
|
raise ParseError("合并批次时请提供新批次号")
|
||||||
|
|
||||||
new_target = None
|
new_target = None
|
||||||
|
exclude_batchst_ids = []
|
||||||
mids = []
|
mids = []
|
||||||
for item in handoverb_list:
|
for item in handoverb_list:
|
||||||
wmId, xcount, handover_or_b = item
|
wmId, xcount, handover_or_b = item
|
||||||
|
@ -756,17 +760,19 @@ def handover_submit(handover:Handover, user: User, now: Union[datetime.datetime,
|
||||||
|
|
||||||
# 合并为新批
|
# 合并为新批
|
||||||
if mtype == Handover.H_MERGE:
|
if mtype == Handover.H_MERGE:
|
||||||
source, _ = BatchSt.g_create(batch=wm_from.batch)
|
source, _ = BatchSt.g_create(batch=wm_from.batch, exclude_batchst_ids=exclude_batchst_ids)
|
||||||
batch = new_batch
|
batch = new_batch
|
||||||
if new_target is None:
|
if new_target is None:
|
||||||
new_target, _ = BatchSt.g_create(batch=batch, handover=handover, material_start=material)
|
new_target, _ = BatchSt.g_create(batch=batch, handover=handover, material_start=material)
|
||||||
|
exclude_batchst_ids.append(new_target.id)
|
||||||
BatchLog.g_create(source=source, target=new_target, handover=handover, relation_type="merge")
|
BatchLog.g_create(source=source, target=new_target, handover=handover, relation_type="merge")
|
||||||
elif mtype == Handover.H_DIV:
|
elif mtype == Handover.H_DIV:
|
||||||
if handover.wm is None:
|
if handover.wm is None:
|
||||||
raise ParseError('拆批请选择车间库存')
|
raise ParseError('拆批请选择车间库存')
|
||||||
source, _ = BatchSt.g_create(batch=handover.wm.batch)
|
source, _ = BatchSt.g_create(batch=handover.wm.batch, exclude_batchst_ids=exclude_batchst_ids)
|
||||||
batch = handover_or_b.batch
|
batch = handover_or_b.batch
|
||||||
target, _ = BatchSt.g_create(batch=batch, handover=handover, material_start=material)
|
target, _ = BatchSt.g_create(batch=batch, handover=handover, material_start=material)
|
||||||
|
exclude_batchst_ids.append(target.id)
|
||||||
BatchLog.g_create(source=source, target=target, handover=handover, relation_type="split")
|
BatchLog.g_create(source=source, target=target, handover=handover, relation_type="split")
|
||||||
else:
|
else:
|
||||||
batch = wm_from.batch
|
batch = wm_from.batch
|
||||||
|
|
Loading…
Reference in New Issue