feat: wmaterial增加count_xtest/handover增加检验交接
This commit is contained in:
parent
a2b52e95a5
commit
1a42cf34f0
|
@ -0,0 +1,23 @@
|
|||
# Generated by Django 3.2.12 on 2024-08-09 07:08
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('wpm', '0058_auto_20240723_1006'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='wmaterial',
|
||||
name='count_xtest',
|
||||
field=models.PositiveIntegerField(blank=True, null=True, verbose_name='已检数量'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='handover',
|
||||
name='type',
|
||||
field=models.PositiveSmallIntegerField(choices=[(10, '正常交接'), (20, '返修交接'), (30, '检验交接')], default=10, verbose_name='交接类型'),
|
||||
),
|
||||
]
|
|
@ -97,6 +97,7 @@ class WMaterial(CommonBDModel):
|
|||
count_eweight = models.FloatField('单数重量', default=0)
|
||||
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')
|
||||
count_xtest = models.PositiveIntegerField('已检数量', null=True, blank=True)
|
||||
|
||||
|
||||
class Mlog(CommonADModel):
|
||||
|
@ -246,7 +247,8 @@ class Handover(CommonADModel):
|
|||
"""
|
||||
H_NORMAL = 10
|
||||
H_REPAIR = 20
|
||||
type = models.PositiveSmallIntegerField('交接类型', choices=[(H_NORMAL, '正常交接'), (H_REPAIR, '返修交接')], default=H_NORMAL)
|
||||
H_TEST = 30
|
||||
type = models.PositiveSmallIntegerField('交接类型', choices=[(H_NORMAL, '正常交接'), (H_REPAIR, '返修交接'), (H_TEST, '检验交接')], default=H_NORMAL)
|
||||
send_date = models.DateField('送料日期')
|
||||
send_user = models.ForeignKey(
|
||||
User, verbose_name='交送人', on_delete=models.CASCADE, related_name='handover_send_user')
|
||||
|
|
|
@ -470,8 +470,8 @@ class HandoverSerializer(CustomModelSerializer):
|
|||
raise ValidationError('收料车间和收料工段必须有一个')
|
||||
if 'send_dept' not in attrs and 'send_mgroup' not in attrs:
|
||||
raise ValidationError('送料车间和送料工段必须有一个')
|
||||
if wm.notok_sign is not None and attrs['type'] == Handover.H_NORMAL:
|
||||
raise ValidationError('物料不合格,不能进行正常交接')
|
||||
if wm.notok_sign is not None and attrs['type'] in [Handover.H_NORMAL, Handover.H_TEST]:
|
||||
raise ValidationError('物料不合格,不能进行正常/检验交接')
|
||||
return attrs
|
||||
|
||||
class Meta:
|
||||
|
|
|
@ -119,7 +119,11 @@ def do_out(mio: MIO):
|
|||
xmaterial, xbatch, xcount = al
|
||||
# 领到车间库存(或工段)
|
||||
wm, new_create = WMaterial.objects.get_or_create(batch=xbatch, material=xmaterial,
|
||||
belong_dept=belong_dept, mgroup=mgroup, defaults={
|
||||
belong_dept=belong_dept, mgroup=mgroup,
|
||||
notok_sign=None,
|
||||
material_origin=None,
|
||||
count_xtest=None,
|
||||
defaults={
|
||||
"batch": xbatch,
|
||||
"material": xmaterial,
|
||||
"count": xcount,
|
||||
|
@ -138,6 +142,7 @@ def do_in(mio: MIO):
|
|||
生产入库后更新车间物料
|
||||
"""
|
||||
belong_dept = mio.belong_dept
|
||||
mgroup = mio.mgroup
|
||||
do_user = mio.do_user
|
||||
mioitems = MIOItem.objects.filter(mio=mio)
|
||||
for item in mioitems:
|
||||
|
@ -160,9 +165,9 @@ def do_in(mio: MIO):
|
|||
for al in action_list:
|
||||
xmaterial, xbatch, xcount = al
|
||||
# 优先从车间库存里拿
|
||||
wm_qs = WMaterial.objects.filter(batch=xbatch, material=xmaterial, belong_dept=belong_dept, mgroup=None, notok_sign=None)
|
||||
if not wm_qs.exists():
|
||||
wm_qs = WMaterial.objects.filter(batch=xbatch, material=xmaterial, belong_dept=belong_dept, mgroup__isnull=False, notok_sign=None)
|
||||
wm_qs = WMaterial.objects.filter(batch=xbatch, material=xmaterial, belong_dept=belong_dept, mgroup=mgroup, notok_sign=None, material_origin=None, count_xtest=None)
|
||||
# if not wm_qs.exists():
|
||||
# wm_qs = WMaterial.objects.filter(batch=xbatch, material=xmaterial, belong_dept=belong_dept, mgroup__isnull=False, notok_sign=None, material_origin=None, count_xtest=None)
|
||||
|
||||
count_x = wm_qs.count()
|
||||
if count_x == 1:
|
||||
|
@ -213,9 +218,9 @@ def mlog_submit(mlog: Mlog, user: User, now: Union[datetime.datetime, None]):
|
|||
if mi_wm_in:
|
||||
wm_qs = WMaterial.objects.filter(id=mi_wm_in.id)
|
||||
else:
|
||||
wm_qs = WMaterial.objects.filter(batch=mi_batch, material=mi_ma, mgroup=mgroup, notok_sign=None)
|
||||
wm_qs = WMaterial.objects.filter(batch=mi_batch, material=mi_ma, mgroup=mgroup, notok_sign=None, count_xtest=None, material_origin=None)
|
||||
if not wm_qs.exists():
|
||||
wm_qs = WMaterial.objects.filter(batch=mi_batch, material=mi_ma, belong_dept=belong_dept, mgroup=None, notok_sign=None)
|
||||
wm_qs = WMaterial.objects.filter(batch=mi_batch, material=mi_ma, belong_dept=belong_dept, mgroup=None, notok_sign=None, count_xtest=None, material_origin=None)
|
||||
|
||||
count_x = wm_qs.count()
|
||||
if count_x == 1:
|
||||
|
@ -255,7 +260,7 @@ def mlog_submit(mlog: Mlog, user: User, now: Union[datetime.datetime, None]):
|
|||
|
||||
for mo in m_outs_list:
|
||||
mo_ma, mo_batch, mo_count, mo_count_eweight, notok_sign = mo
|
||||
lookup = {'batch': mo_batch, 'material': mo_ma, 'mgroup': None, 'notok_sign': notok_sign}
|
||||
lookup = {'batch': mo_batch, 'material': mo_ma, 'mgroup': None, 'notok_sign': notok_sign, 'material_origin': None, 'count_xtest': None}
|
||||
if into_wm_mgroup:
|
||||
lookup['mgroup'] = mgroup
|
||||
stored_mgroup = True
|
||||
|
@ -304,7 +309,8 @@ def mlog_revert(mlog: Mlog, user: User, now: Union[datetime.datetime, None]):
|
|||
mi_wm_in.update_by = user
|
||||
mi_wm_in.save()
|
||||
else:
|
||||
lookup = {'batch': mi_batch, 'material': mi_ma, 'mgroup': None, 'notok_sign': None}
|
||||
# 针对光子的情况,实际上必须需要wm_in
|
||||
lookup = {'batch': mi_batch, 'material': mi_ma, 'mgroup': None, 'notok_sign': None, 'material_origin': None, 'count_xtest': None}
|
||||
if into_wm_mgroup:
|
||||
# 退回到本工段
|
||||
lookup['mgroup'] = mgroup
|
||||
|
@ -333,7 +339,7 @@ def mlog_revert(mlog: Mlog, user: User, now: Union[datetime.datetime, None]):
|
|||
|
||||
for mo in m_outs_list:
|
||||
mo_ma, mo_batch, mo_count, _, notok_sign = mo
|
||||
lookup = {'batch': mo_batch, 'material': mo_ma, 'mgroup': None, 'notok_sign': notok_sign}
|
||||
lookup = {'batch': mo_batch, 'material': mo_ma, 'mgroup': None, 'notok_sign': notok_sign, 'material_origin': None, 'count_xtest': None}
|
||||
if stored_mgroup:
|
||||
lookup['mgroup'] = mgroup
|
||||
else:
|
||||
|
@ -510,35 +516,76 @@ def handover_submit(handover: Handover, user: User, now: Union[datetime.datetime
|
|||
wm_from.count = count_x
|
||||
wm_from.save()
|
||||
if need_add:
|
||||
if handover.recive_mgroup:
|
||||
if handover.type == Handover.H_NORMAL:
|
||||
wm_to, _ = WMaterial.objects.get_or_create(batch=batch, material=material, mgroup=handover.recive_mgroup, material_origin=None, defaults={
|
||||
'batch': batch, 'material': material, 'mgroup': handover.recive_mgroup, 'belong_dept': handover.recive_dept
|
||||
})
|
||||
# 处理返工交接
|
||||
elif handover.type == Handover.H_REPAIR:
|
||||
if handover.type == Handover.H_NORMAL:
|
||||
if handover.recive_mgroup:
|
||||
wm_to, _ = WMaterial.objects.get_or_create(
|
||||
batch=batch,
|
||||
material=material,
|
||||
mgroup=handover.recive_mgroup,
|
||||
material_origin=None,
|
||||
notok_sign=None,
|
||||
count_xtest=None,
|
||||
defaults={"batch": batch, "material": material, "mgroup": handover.recive_mgroup, "belong_dept": handover.recive_dept},
|
||||
)
|
||||
else:
|
||||
wm_to, _ = WMaterial.objects.get_or_create(
|
||||
batch=batch,
|
||||
material=handover.material_changed,
|
||||
mgroup=handover.recive_mgroup,
|
||||
material=material,
|
||||
belong_dept=handover.recive_dept,
|
||||
material_origin=None,
|
||||
notok_sign=None,
|
||||
count_xtest=None,
|
||||
defaults={"batch": batch, "material": material, "belong_dept": handover.recive_dept}
|
||||
)
|
||||
elif handover.type == Handover.H_REPAIR:
|
||||
if handover.recive_mgroup:
|
||||
wm_to, _ = WMaterial.objects.get_or_create(
|
||||
batch=batch,
|
||||
material=handover.material_changed,
|
||||
mgroup=handover.recive_mgroup,
|
||||
notok_sign=handover.wm.notok_sign,
|
||||
material_origin=handover.material,
|
||||
defaults={
|
||||
'batch': batch,
|
||||
'material': handover.material_changed,
|
||||
'mgroup': handover.recive_mgroup,
|
||||
'notok_sign': handover.wm.notok_sign,
|
||||
'material_origin': handover.material,
|
||||
'belong_dept': handover.recive_dept
|
||||
})
|
||||
count_xtest=None,
|
||||
defaults={
|
||||
"batch": batch,
|
||||
"material": handover.material_changed,
|
||||
"mgroup": handover.recive_mgroup,
|
||||
"notok_sign": handover.wm.notok_sign,
|
||||
"material_origin": handover.material,
|
||||
"belong_dept": handover.recive_dept,
|
||||
},
|
||||
)
|
||||
else:
|
||||
raise ParseError('不支持的交接类型')
|
||||
raise ParseError("返工交接必须指定接收工段")
|
||||
elif handover.type == Handover.H_TEST:
|
||||
if handover.recive_mgroup:
|
||||
wm_to, _ = WMaterial.objects.get_or_create(
|
||||
batch=batch,
|
||||
material=material,
|
||||
mgroup=handover.recive_mgroup,
|
||||
material_origin=None,
|
||||
notok_sign=None,
|
||||
defaults={
|
||||
"batch": batch,
|
||||
"material": material,
|
||||
"mgroup": handover.recive_mgroup,
|
||||
"belong_dept": handover.recive_dept,
|
||||
"count_xtest": 0},
|
||||
)
|
||||
else:
|
||||
wm_to, _ = WMaterial.objects.get_or_create(
|
||||
batch=batch,
|
||||
material=material,
|
||||
belong_dept=handover.recive_dept,
|
||||
material_origin=None,
|
||||
notok_sign=None,
|
||||
defaults={"batch": batch, "material": material, "belong_dept": handover.recive_dept, "count_xtest": 0},
|
||||
)
|
||||
else:
|
||||
wm_to, _ = WMaterial.objects.get_or_create(batch=batch, material=material, belong_dept=handover.recive_dept, defaults={
|
||||
'batch': batch, 'material': material, 'belong_dept': handover.recive_dept
|
||||
})
|
||||
raise ParseError("不支持交接类型")
|
||||
|
||||
wm_to.count = wm_to.count + handover.count
|
||||
wm_to.count_eweight = handover.count_eweight
|
||||
wm_to.count_eweight = handover.count_eweight # 这行代码有隐患
|
||||
wm_to.save()
|
||||
handover.submit_user = user
|
||||
handover.submit_time = now
|
||||
|
|
Loading…
Reference in New Issue