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)
|
count_eweight = models.FloatField('单数重量', default=0)
|
||||||
notok_sign = models.CharField('不合格标记', max_length=10, 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')
|
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):
|
class Mlog(CommonADModel):
|
||||||
|
@ -246,7 +247,8 @@ class Handover(CommonADModel):
|
||||||
"""
|
"""
|
||||||
H_NORMAL = 10
|
H_NORMAL = 10
|
||||||
H_REPAIR = 20
|
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_date = models.DateField('送料日期')
|
||||||
send_user = models.ForeignKey(
|
send_user = models.ForeignKey(
|
||||||
User, verbose_name='交送人', on_delete=models.CASCADE, related_name='handover_send_user')
|
User, verbose_name='交送人', on_delete=models.CASCADE, related_name='handover_send_user')
|
||||||
|
|
|
@ -470,8 +470,8 @@ class HandoverSerializer(CustomModelSerializer):
|
||||||
raise ValidationError('收料车间和收料工段必须有一个')
|
raise ValidationError('收料车间和收料工段必须有一个')
|
||||||
if 'send_dept' not in attrs and 'send_mgroup' not in attrs:
|
if 'send_dept' not in attrs and 'send_mgroup' not in attrs:
|
||||||
raise ValidationError('送料车间和送料工段必须有一个')
|
raise ValidationError('送料车间和送料工段必须有一个')
|
||||||
if wm.notok_sign is not None and attrs['type'] == Handover.H_NORMAL:
|
if wm.notok_sign is not None and attrs['type'] in [Handover.H_NORMAL, Handover.H_TEST]:
|
||||||
raise ValidationError('物料不合格,不能进行正常交接')
|
raise ValidationError('物料不合格,不能进行正常/检验交接')
|
||||||
return attrs
|
return attrs
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
|
@ -119,7 +119,11 @@ def do_out(mio: MIO):
|
||||||
xmaterial, xbatch, xcount = al
|
xmaterial, xbatch, xcount = al
|
||||||
# 领到车间库存(或工段)
|
# 领到车间库存(或工段)
|
||||||
wm, new_create = WMaterial.objects.get_or_create(batch=xbatch, material=xmaterial,
|
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,
|
"batch": xbatch,
|
||||||
"material": xmaterial,
|
"material": xmaterial,
|
||||||
"count": xcount,
|
"count": xcount,
|
||||||
|
@ -138,6 +142,7 @@ def do_in(mio: MIO):
|
||||||
生产入库后更新车间物料
|
生产入库后更新车间物料
|
||||||
"""
|
"""
|
||||||
belong_dept = mio.belong_dept
|
belong_dept = mio.belong_dept
|
||||||
|
mgroup = mio.mgroup
|
||||||
do_user = mio.do_user
|
do_user = mio.do_user
|
||||||
mioitems = MIOItem.objects.filter(mio=mio)
|
mioitems = MIOItem.objects.filter(mio=mio)
|
||||||
for item in mioitems:
|
for item in mioitems:
|
||||||
|
@ -160,9 +165,9 @@ def do_in(mio: MIO):
|
||||||
for al in action_list:
|
for al in action_list:
|
||||||
xmaterial, xbatch, xcount = al
|
xmaterial, xbatch, xcount = al
|
||||||
# 优先从车间库存里拿
|
# 优先从车间库存里拿
|
||||||
wm_qs = WMaterial.objects.filter(batch=xbatch, material=xmaterial, belong_dept=belong_dept, mgroup=None, 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():
|
# 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__isnull=False, notok_sign=None, material_origin=None, count_xtest=None)
|
||||||
|
|
||||||
count_x = wm_qs.count()
|
count_x = wm_qs.count()
|
||||||
if count_x == 1:
|
if count_x == 1:
|
||||||
|
@ -213,9 +218,9 @@ def mlog_submit(mlog: Mlog, user: User, now: Union[datetime.datetime, None]):
|
||||||
if mi_wm_in:
|
if mi_wm_in:
|
||||||
wm_qs = WMaterial.objects.filter(id=mi_wm_in.id)
|
wm_qs = WMaterial.objects.filter(id=mi_wm_in.id)
|
||||||
else:
|
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():
|
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()
|
count_x = wm_qs.count()
|
||||||
if count_x == 1:
|
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:
|
for mo in m_outs_list:
|
||||||
mo_ma, mo_batch, mo_count, mo_count_eweight, notok_sign = mo
|
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:
|
if into_wm_mgroup:
|
||||||
lookup['mgroup'] = mgroup
|
lookup['mgroup'] = mgroup
|
||||||
stored_mgroup = True
|
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.update_by = user
|
||||||
mi_wm_in.save()
|
mi_wm_in.save()
|
||||||
else:
|
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:
|
if into_wm_mgroup:
|
||||||
# 退回到本工段
|
# 退回到本工段
|
||||||
lookup['mgroup'] = 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:
|
for mo in m_outs_list:
|
||||||
mo_ma, mo_batch, mo_count, _, notok_sign = mo
|
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:
|
if stored_mgroup:
|
||||||
lookup['mgroup'] = mgroup
|
lookup['mgroup'] = mgroup
|
||||||
else:
|
else:
|
||||||
|
@ -510,35 +516,76 @@ def handover_submit(handover: Handover, user: User, now: Union[datetime.datetime
|
||||||
wm_from.count = count_x
|
wm_from.count = count_x
|
||||||
wm_from.save()
|
wm_from.save()
|
||||||
if need_add:
|
if need_add:
|
||||||
if handover.recive_mgroup:
|
if handover.type == Handover.H_NORMAL:
|
||||||
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, defaults={
|
wm_to, _ = WMaterial.objects.get_or_create(
|
||||||
'batch': batch, 'material': material, 'mgroup': handover.recive_mgroup, 'belong_dept': handover.recive_dept
|
batch=batch,
|
||||||
})
|
material=material,
|
||||||
# 处理返工交接
|
mgroup=handover.recive_mgroup,
|
||||||
elif handover.type == Handover.H_REPAIR:
|
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(
|
wm_to, _ = WMaterial.objects.get_or_create(
|
||||||
batch=batch,
|
batch=batch,
|
||||||
material=handover.material_changed,
|
material=material,
|
||||||
mgroup=handover.recive_mgroup,
|
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,
|
notok_sign=handover.wm.notok_sign,
|
||||||
material_origin=handover.material,
|
material_origin=handover.material,
|
||||||
defaults={
|
count_xtest=None,
|
||||||
'batch': batch,
|
defaults={
|
||||||
'material': handover.material_changed,
|
"batch": batch,
|
||||||
'mgroup': handover.recive_mgroup,
|
"material": handover.material_changed,
|
||||||
'notok_sign': handover.wm.notok_sign,
|
"mgroup": handover.recive_mgroup,
|
||||||
'material_origin': handover.material,
|
"notok_sign": handover.wm.notok_sign,
|
||||||
'belong_dept': handover.recive_dept
|
"material_origin": handover.material,
|
||||||
})
|
"belong_dept": handover.recive_dept,
|
||||||
|
},
|
||||||
|
)
|
||||||
else:
|
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:
|
else:
|
||||||
wm_to, _ = WMaterial.objects.get_or_create(batch=batch, material=material, belong_dept=handover.recive_dept, defaults={
|
raise ParseError("不支持交接类型")
|
||||||
'batch': batch, 'material': material, 'belong_dept': handover.recive_dept
|
|
||||||
})
|
|
||||||
wm_to.count = wm_to.count + handover.count
|
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()
|
wm_to.save()
|
||||||
handover.submit_user = user
|
handover.submit_user = user
|
||||||
handover.submit_time = now
|
handover.submit_time = now
|
||||||
|
|
Loading…
Reference in New Issue