feat: handover 合并可指定现有库存

This commit is contained in:
caoqianming 2025-03-26 13:19:30 +08:00
parent 3e074b51e3
commit 0ddc6692ac
4 changed files with 59 additions and 21 deletions

View File

@ -0,0 +1,19 @@
# Generated by Django 3.2.12 on 2025-03-26 03:17
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('wpm', '0104_auto_20250325_0921'),
]
operations = [
migrations.AddField(
model_name='handover',
name='new_wm',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='wpm.wmaterial'),
),
]

View File

@ -483,6 +483,7 @@ class Handover(CommonADModel):
H_MERGE = 30
H_DIV = 20
new_batch = models.TextField('新批次号', null=True, blank=True)
new_wm = models.ForeignKey(WMaterial, on_delete=models.SET_NULL, null=True, blank=True)
mtype = models.PositiveSmallIntegerField("合并类型", default=H_NORMAL, choices=
[(H_NORMAL, '正常'), (H_DIV, '分批'), (H_MERGE, '合批')])
type = models.PositiveSmallIntegerField('交接类型', choices=[
@ -600,11 +601,22 @@ class BatchSt(BaseModel):
if mio is None and handover is None and mlog is None and material_start is None:
return cls.objects.get_or_create(batch=batch)
else:
# 带有来源的批次获取,需检查批次号是否可用
if cls.objects.filter(batch=batch).exists():
raise ParseError(f"{batch}-该批次号不可用")
if mio is None and handover is None and mlog is None:
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)
return ins, True
@classmethod
def init_dag(cls, batch:str, force_init=False):
"""
更新批次数据
"""
pass
class BatchLog(BaseModel):
"""

View File

@ -953,8 +953,12 @@ class HandoverSerializer(CustomModelSerializer):
if attrs["type"] == Handover.H_CHANGE:
if "material_changed" not in attrs:
raise ParseError("必须指定改版后的物料")
if mtype == Handover.H_MERGE and not attrs.get("new_batch", None):
raise ParseError("必须指定合并后的批次")
if mtype == Handover.H_MERGE:
new_wm = attrs.get("new_wm", None)
if new_wm:
attrs['new_batch'] = new_wm.batch
if not attrs.get("new_batch", None):
raise ParseError("必须指定合并后的批次")
wm:WMaterial = attrs.get('wm', None)
handoverb = attrs.get('handoverb', [])
if wm:

View File

@ -712,18 +712,18 @@ def handover_submit(handover:Handover, user: User, now: Union[datetime.datetime,
batches = [new_batch]
else:
raise ParseError("合并批次时请提供新批次号")
create_new_batch = False
new_target = None
for item in handoverb_list:
wm_from, xcount, handover_or_b = item
# 合并为新批
if mtype == Handover.H_MERGE:
batch = new_batch
if create_new_batch is False:
target, _ = BatchSt.g_create(batch=batch, handover=handover, material_start=material)
create_new_batch = True
if new_target is None:
new_target, _ = BatchSt.g_create(batch=batch, handover=handover, material_start=material)
source, _ = BatchSt.g_create(batch=wm_from.batch)
BatchLog.g_create(source=source, target=target, handover=handover, relation_type="merge")
BatchLog.g_create(source=source, target=new_target, handover=handover, relation_type="merge")
elif mtype == Handover.H_DIV:
batch = handover_or_b.batch
target, _ = BatchSt.g_create(batch=batch, handover=handover, material_start=material)
@ -747,20 +747,23 @@ def handover_submit(handover:Handover, user: User, now: Union[datetime.datetime,
if need_add:
# 开始变动
if handover.type == Handover.H_NORMAL:
wm_to, _ = WMaterial.objects.get_or_create(
batch=batch,
material=material,
mgroup=recive_mgroup,
belong_dept=recive_dept,
state=WMaterial.WM_OK,
notok_sign=wm_from.notok_sign,
defect=wm_from.defect,
defaults={
"batch_ofrom": wm_from.batch_ofrom,
"material_ofrom": wm_from.material_ofrom,
"create_by": user
}
)
if mtype == Handover.H_MERGE and handover.new_wm:
wm_to = handover.new_wm
else:
wm_to, _ = WMaterial.objects.get_or_create(
batch=batch,
material=material,
mgroup=recive_mgroup,
belong_dept=recive_dept,
state=WMaterial.WM_OK,
notok_sign=wm_from.notok_sign,
defect=wm_from.defect,
defaults={
"batch_ofrom": wm_from.batch_ofrom,
"material_ofrom": wm_from.material_ofrom,
"create_by": user
}
)
elif handover.type == Handover.H_REPAIR:
# 返修交接
recive_mgroup = handover.recive_mgroup