feat: 改版交接支持拆合批

This commit is contained in:
caoqianming 2025-12-08 13:57:02 +08:00
parent 75b2a420b7
commit 09c3bec66a
4 changed files with 60 additions and 24 deletions

View File

@ -0,0 +1,23 @@
# Generated by Django 3.2.12 on 2025-12-08 05:37
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('wpm', '0125_auto_20251126_0953'),
]
operations = [
migrations.AddField(
model_name='handover',
name='state_changed',
field=models.PositiveSmallIntegerField(blank=True, choices=[(10, '合格'), (20, '不合格'), (30, '返修'), (34, '返修完成'), (40, '检验'), (50, '报废')], default=10, null=True, verbose_name='变更后状态'),
),
migrations.AddField(
model_name='wmaterial',
name='state_origin',
field=models.PositiveSmallIntegerField(blank=True, choices=[(10, '合格'), (20, '不合格'), (30, '返修'), (34, '返修完成'), (40, '检验'), (50, '报废')], null=True, verbose_name='原始状态'),
),
]

View File

@ -119,6 +119,7 @@ class WMaterial(CommonBDModel):
defect = models.ForeignKey('qm.defect', verbose_name='缺陷', on_delete=models.SET_NULL, null=True, blank=True)
notok_sign = models.CharField('不合格标记', max_length=10, null=True, blank=True)
material_origin = models.ForeignKey(Material, verbose_name='原始物料', on_delete=models.SET_NULL, null=True, blank=True, related_name='wm_mo')
state_origin = models.PositiveSmallIntegerField('原始状态', choices=WmStateOption.choices, null=True, blank=True)
count_xtest = models.DecimalField('已检数量', null=True, blank=True, max_digits=11, decimal_places=1)
batch_ofrom = models.TextField('原料批次号', null=True, blank=True)
material_ofrom = models.ForeignKey(Material, verbose_name='原料物料', on_delete=models.SET_NULL, null=True, blank=True, related_name='wm_mofrom')
@ -601,6 +602,7 @@ class Handover(CommonADModel):
material = models.ForeignKey(
Material, verbose_name='物料', on_delete=models.CASCADE, related_name='h_ma')
material_changed = models.ForeignKey(Material, verbose_name='变更后物料', on_delete=models.CASCADE, null=True, blank=True, related_name='h_ma_c')
state_changed = models.PositiveSmallIntegerField('变更后状态', choices=WmStateOption.choices, default=10, null=True, blank=True)
count = models.DecimalField('送料数', default=0, max_digits=11, decimal_places=1)
count_eweight = models.FloatField('单数重量', default=0)
recive_dept = models.ForeignKey(

View File

@ -1195,13 +1195,6 @@ class HandoverSerializer(CustomModelSerializer):
attrs['mtype'] = Handover.H_NORMAL
if 'type' not in attrs:
attrs['type'] = Handover.H_NORMAL
if attrs["type"] == Handover.H_CHANGE:
attrs["mtype"] = Handover.H_MERGE
if "material_changed" in attrs and attrs["material_changed"]:
pass
else:
raise ParseError("必须指定改版后的物料")
mtype = attrs["mtype"]
if mtype == Handover.H_MERGE:
@ -1211,12 +1204,23 @@ class HandoverSerializer(CustomModelSerializer):
attrs['new_batch'] = new_wm.batch
new_state = new_wm.state
new_defect = new_wm.defect
if attrs["type"] == Handover.H_CHANGE:
attrs["material_changed"] = new_wm.material
attrs["state_changed"] = new_wm.state
if not attrs.get("new_batch", None):
raise ParseError("必须指定合并后的批次")
if 'undefined' in attrs['new_batch'] or 'null' in attrs['new_batch'] or '#' in attrs['new_batch']:
raise ParseError("新批次号含有不允许信息!")
else:
attrs['new_batch'] = None
attrs['new_wm'] = None
if attrs["type"] == Handover.H_CHANGE:
if "material_changed" in attrs and attrs["material_changed"]:
pass
else:
raise ParseError("必须指定改版后的物料")
wm:WMaterial = attrs.get('wm', None)
if wm:
attrs["batch"] = wm.batch

View File

@ -800,11 +800,12 @@ def handover_submit(handover:Handover, user: User, now: Union[datetime.datetime,
elif handover.type == Handover.H_REPAIR:
# 返修交接
recive_mgroup = handover.recive_mgroup
if recive_mgroup:
# if recive_mgroup.process.type == Process.PRO_TEST:
# wm_state = WMaterial.WM_REPAIRED
# else:
wm_state = WMaterial.WM_REPAIR
wm_state = WMaterial.WM_REPAIR
if mtype == Handover.H_MERGE and handover.new_wm:
wm_to = handover.new_wm
if wm_to.state != WMaterial.WM_REPAIR or wm_to.material != wm_from.material:
raise ParseError("返修合并到的车间库存状态或物料异常")
elif recive_mgroup:
wm_to, _ = WMaterial.objects.get_or_create(
batch=batch,
material=material,
@ -824,6 +825,7 @@ def handover_submit(handover:Handover, user: User, now: Union[datetime.datetime,
else:
raise ParseError("返工交接必须指定接收工段")
elif handover.type == Handover.H_TEST:
raise ParseError("检验交接已废弃")
wm_to, _ = WMaterial.objects.get_or_create(
batch=batch,
material=material,
@ -838,7 +840,11 @@ def handover_submit(handover:Handover, user: User, now: Union[datetime.datetime,
},
)
elif handover.type == Handover.H_SCRAP:
if recive_mgroup:
if mtype == Handover.H_MERGE and handover.new_wm:
wm_to = handover.new_wm
if wm_to.state != WMaterial.WM_SCRAP or wm_to.material != wm_from.material:
raise ParseError("报废合并到的车间库存状态或物料异常")
elif recive_mgroup:
wm_to, _ = WMaterial.objects.get_or_create(
batch=batch,
material=material,
@ -857,23 +863,24 @@ def handover_submit(handover:Handover, user: User, now: Union[datetime.datetime,
else:
raise ParseError("不支持非工段报废")
elif handover.type == Handover.H_CHANGE:
if handover.new_wm:
if mtype == Handover.H_MERGE and handover.new_wm:
wm_to = handover.new_wm
elif handover.recive_mgroup:
wm_to, _ = WMaterial.objects.get_or_create(
batch=batch,
material=handover.material_changed,
state=handover.state_changed,
mgroup=recive_mgroup,
belong_dept=recive_dept,
notok_sign=None,
defect=None,
material_origin=material,
state=WMaterial.WM_OK,
notok_sign=wm_from.notok_sign,
defect=wm_from.defect,
material_origin=None if handover.material_changed == material else material,
state_origin=None if handover.state_changed == wm_from.state else wm_from.state,
defaults={
"batch_ofrom": wm_from.batch_ofrom,
"material_ofrom": wm_from.material_ofrom,
"create_by": user,
"number_from": wm_from.number_from
"batch_ofrom": wm_from.batch_ofrom,
"material_ofrom": wm_from.material_ofrom,
"create_by": user,
"number_from": wm_from.number_from
}
)
else: