Compare commits
2 Commits
57459cc7dc
...
041474411e
| Author | SHA1 | Date |
|---|---|---|
|
|
041474411e | |
|
|
07b2df1fd0 |
|
|
@ -706,12 +706,15 @@ class BatchSt(BaseModel):
|
||||||
unique_together = [("batch", "version")]
|
unique_together = [("batch", "version")]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def g_create(cls, batch:str, mio=None, mioitem=None, handover=None, mlog=None, material_start=None, check_mat_start=False, exclude_batchst_ids=[]):
|
def g_create(cls, batch:str, mio=None, mioitem=None, handover=None, mlog=None, material_start=None, check_mat_start=False, exclude_batchst_ids=[], check_batch_exist=False):
|
||||||
"""
|
"""
|
||||||
创建新的批次
|
创建新的批次
|
||||||
"""
|
"""
|
||||||
if mioitem:
|
if mioitem:
|
||||||
mio = mioitem.mio
|
mio = mioitem.mio
|
||||||
|
if check_batch_exist:
|
||||||
|
if cls.objects.filter(batch=batch).exclude(id__in=exclude_batchst_ids).exists():
|
||||||
|
raise ParseError(f"{batch}-该批次号已存在不可使用")
|
||||||
node, created = cls.safe_get_or_create(batch=batch, version=1, defaults={
|
node, created = cls.safe_get_or_create(batch=batch, version=1, defaults={
|
||||||
"mio":mio, "mioitem":mioitem, "handover":handover, "mlog":mlog, "material_start":material_start})
|
"mio":mio, "mioitem":mioitem, "handover":handover, "mlog":mlog, "material_start":material_start})
|
||||||
if not created and check_mat_start:
|
if not created and check_mat_start:
|
||||||
|
|
|
||||||
|
|
@ -1197,13 +1197,12 @@ class HandoverSerializer(CustomModelSerializer):
|
||||||
attrs['type'] = Handover.H_NORMAL
|
attrs['type'] = Handover.H_NORMAL
|
||||||
|
|
||||||
mtype = attrs["mtype"]
|
mtype = attrs["mtype"]
|
||||||
new_state = None
|
|
||||||
|
new_wm:WMaterial = attrs.get("new_wm", None)
|
||||||
|
|
||||||
if mtype == Handover.H_MERGE:
|
if mtype == Handover.H_MERGE:
|
||||||
new_wm:WMaterial = attrs.get("new_wm", None)
|
|
||||||
if new_wm:
|
if new_wm:
|
||||||
attrs['new_batch'] = new_wm.batch
|
attrs['new_batch'] = new_wm.batch
|
||||||
new_state = new_wm.state
|
|
||||||
new_defect = new_wm.defect
|
|
||||||
if attrs["type"] == Handover.H_CHANGE:
|
if attrs["type"] == Handover.H_CHANGE:
|
||||||
attrs["material_changed"] = new_wm.material
|
attrs["material_changed"] = new_wm.material
|
||||||
attrs["state_changed"] = new_wm.state
|
attrs["state_changed"] = new_wm.state
|
||||||
|
|
@ -1252,6 +1251,14 @@ class HandoverSerializer(CustomModelSerializer):
|
||||||
# raise ParseError('正常交接收料工段与送料工段不能相同')
|
# raise ParseError('正常交接收料工段与送料工段不能相同')
|
||||||
t_count = 0
|
t_count = 0
|
||||||
tracking = attrs["material"].tracking
|
tracking = attrs["material"].tracking
|
||||||
|
|
||||||
|
next_mat = None
|
||||||
|
next_state = None
|
||||||
|
next_defect = None
|
||||||
|
if new_wm:
|
||||||
|
next_mat = new_wm.material
|
||||||
|
next_state = new_wm.state
|
||||||
|
next_defect = new_wm.defect
|
||||||
for ind, item in enumerate(attrs['handoverb']):
|
for ind, item in enumerate(attrs['handoverb']):
|
||||||
if item["count"] > 0:
|
if item["count"] > 0:
|
||||||
pass
|
pass
|
||||||
|
|
@ -1259,16 +1266,16 @@ class HandoverSerializer(CustomModelSerializer):
|
||||||
raise ParseError(f'第{ind+1}行-交接数量必须大于0')
|
raise ParseError(f'第{ind+1}行-交接数量必须大于0')
|
||||||
wm = item["wm"]
|
wm = item["wm"]
|
||||||
if mtype == Handover.H_MERGE:
|
if mtype == Handover.H_MERGE:
|
||||||
if new_state is None:
|
if next_mat is None:
|
||||||
new_mat = wm.material
|
next_mat = wm.material
|
||||||
new_state = wm.state
|
next_state = wm.state
|
||||||
new_defect = wm.defect
|
next_defect = wm.defect
|
||||||
else:
|
else:
|
||||||
if new_mat != wm.material:
|
if next_mat != wm.material:
|
||||||
raise ParseError(f'第{ind+1}行-合并的物料不一致')
|
raise ParseError(f'第{ind+1}行-合并的物料不一致')
|
||||||
if new_state != wm.state:
|
if next_state != wm.state:
|
||||||
raise ParseError(f'第{ind+1}行-合并的物料状态不一致')
|
raise ParseError(f'第{ind+1}行-合并的物料状态不一致')
|
||||||
if new_defect != wm.defect:
|
if next_defect != wm.defect:
|
||||||
raise ParseError(f'第{ind+1}行-合并的物料缺陷不一致')
|
raise ParseError(f'第{ind+1}行-合并的物料缺陷不一致')
|
||||||
if tracking == Material.MA_TRACKING_SINGLE:
|
if tracking == Material.MA_TRACKING_SINGLE:
|
||||||
handoverbw = item.get("handoverbw", [])
|
handoverbw = item.get("handoverbw", [])
|
||||||
|
|
|
||||||
|
|
@ -727,12 +727,15 @@ def handover_submit(handover:Handover, user: User, now: Union[datetime.datetime,
|
||||||
batches = []
|
batches = []
|
||||||
mids = []
|
mids = []
|
||||||
exclude_batchst_ids = []
|
exclude_batchst_ids = []
|
||||||
|
check_batch_exist = False
|
||||||
if mtype == Handover.H_MERGE:
|
if mtype == Handover.H_MERGE:
|
||||||
if new_batch:
|
if new_batch:
|
||||||
batches = [new_batch]
|
batches = [new_batch]
|
||||||
else:
|
else:
|
||||||
raise ParseError("合并批次时请提供新批次号")
|
raise ParseError("合并批次时请提供新批次号")
|
||||||
target_b, _ = BatchSt.g_create(batch=new_batch, handover=handover, material_start=material)
|
if handover.new_wm is None:
|
||||||
|
check_batch_exist = True
|
||||||
|
target_b, _ = BatchSt.g_create(batch=new_batch, handover=handover, material_start=material, check_batch_exist=check_batch_exist)
|
||||||
exclude_batchst_ids.append(target_b.id)
|
exclude_batchst_ids.append(target_b.id)
|
||||||
elif mtype == Handover.H_DIV:
|
elif mtype == Handover.H_DIV:
|
||||||
if handover.wm is None:
|
if handover.wm is None:
|
||||||
|
|
@ -761,6 +764,7 @@ def handover_submit(handover:Handover, user: User, now: Union[datetime.datetime,
|
||||||
batches_to_limit.append(batch)
|
batches_to_limit.append(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)
|
exclude_batchst_ids.append(target.id)
|
||||||
|
# 这里暂时忽略check_batch_exist,因为拆批一般不会重复
|
||||||
BatchLog.g_create(source=source_b, target=target, handover=handover, relation_type="split")
|
BatchLog.g_create(source=source_b, target=target, handover=handover, relation_type="split")
|
||||||
else:
|
else:
|
||||||
batch = wm_from.batch
|
batch = wm_from.batch
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue