feat: wmaterial增加state字段并进行相应处理
This commit is contained in:
parent
824dacf78d
commit
ba6c30a745
|
@ -72,6 +72,8 @@ class FtestWorkCreateUpdateSerializer(CustomModelSerializer):
|
||||||
if 'wm' not in attrs:
|
if 'wm' not in attrs:
|
||||||
raise ValidationError('请选择车间库存')
|
raise ValidationError('请选择车间库存')
|
||||||
wm:WMaterial = attrs['wm']
|
wm:WMaterial = attrs['wm']
|
||||||
|
if wm.state not in [WMaterial.WM_OK, WMaterial.WM_TEST]:
|
||||||
|
raise ValidationError('不支持对该物料检验')
|
||||||
attrs['material'] = wm.material
|
attrs['material'] = wm.material
|
||||||
attrs['batch'] = wm.batch
|
attrs['batch'] = wm.batch
|
||||||
count_notok_json = attrs.get('count_notok_json', None)
|
count_notok_json = attrs.get('count_notok_json', None)
|
||||||
|
|
|
@ -7,7 +7,7 @@ from django.utils import timezone
|
||||||
|
|
||||||
def ftestwork_submit(ins:FtestWork, user: User):
|
def ftestwork_submit(ins:FtestWork, user: User):
|
||||||
wm:WMaterial = ins.wm
|
wm:WMaterial = ins.wm
|
||||||
if wm.count_xtest is not None: # 如果关心检验数量 一般是全检
|
if wm.state == WMaterial.WM_TEST:
|
||||||
# 更新对应的车间库存
|
# 更新对应的车间库存
|
||||||
wm.count = wm.count - ins.count
|
wm.count = wm.count - ins.count
|
||||||
if wm.count >= 0:
|
if wm.count >= 0:
|
||||||
|
@ -24,9 +24,7 @@ def ftestwork_submit(ins:FtestWork, user: User):
|
||||||
batch=wm.batch,
|
batch=wm.batch,
|
||||||
mgroup=wm.mgroup,
|
mgroup=wm.mgroup,
|
||||||
belong_dept=wm.belong_dept,
|
belong_dept=wm.belong_dept,
|
||||||
notok_sign=None,
|
state=WMaterial.WM_OK,
|
||||||
material_origin=None,
|
|
||||||
count_xtest=None,
|
|
||||||
defaults={
|
defaults={
|
||||||
'count': count_ok,
|
'count': count_ok,
|
||||||
'material': wm.material,
|
'material': wm.material,
|
||||||
|
@ -56,15 +54,15 @@ def ftestwork_submit(ins:FtestWork, user: User):
|
||||||
mgroup=wm.mgroup,
|
mgroup=wm.mgroup,
|
||||||
belong_dept=wm.belong_dept,
|
belong_dept=wm.belong_dept,
|
||||||
notok_sign=notok_sign,
|
notok_sign=notok_sign,
|
||||||
material_origin=None,
|
state=WMaterial.WM_NOTOK,
|
||||||
count_xtest=None,
|
|
||||||
defaults={
|
defaults={
|
||||||
'count': v,
|
'count': v,
|
||||||
'material': wm.material,
|
'material': wm.material,
|
||||||
'batch': wm.batch,
|
'batch': wm.batch,
|
||||||
'mgroup': wm.mgroup,
|
'mgroup': wm.mgroup,
|
||||||
'belong_dept': wm.belong_dept,
|
'belong_dept': wm.belong_dept,
|
||||||
'notok_sign': notok_sign
|
'notok_sign': notok_sign,
|
||||||
|
'state': WMaterial.WM_NOTOK,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
if not new_create:
|
if not new_create:
|
||||||
|
|
|
@ -38,6 +38,7 @@ class WMaterialFilter(filters.FilterSet):
|
||||||
model = WMaterial
|
model = WMaterial
|
||||||
fields = {
|
fields = {
|
||||||
"material": ["exact", "in"],
|
"material": ["exact", "in"],
|
||||||
|
"state": ["exact", "in"],
|
||||||
"material__type": ["exact", "in"],
|
"material__type": ["exact", "in"],
|
||||||
"material__name": ["exact", "in", "contains"],
|
"material__name": ["exact", "in", "contains"],
|
||||||
"material__process": ["exact", "in"],
|
"material__process": ["exact", "in"],
|
||||||
|
|
|
@ -89,6 +89,12 @@ class WMaterial(CommonBDModel):
|
||||||
"""
|
"""
|
||||||
belong_dept是所在车间
|
belong_dept是所在车间
|
||||||
"""
|
"""
|
||||||
|
WM_OK = 10
|
||||||
|
WM_NOTOK = 20
|
||||||
|
WM_REPAIR = 30
|
||||||
|
WM_TEST = 40
|
||||||
|
WM_SCRAP = 50
|
||||||
|
state = models.PositiveSmallIntegerField('状态', default=10, choices=((10, '合格'), (20, '不合格'), (30, '返修'), (40, '检验'), (50, '报废')))
|
||||||
material = models.ForeignKey(
|
material = models.ForeignKey(
|
||||||
Material, verbose_name='物料', on_delete=models.CASCADE, related_name='wm_m')
|
Material, verbose_name='物料', on_delete=models.CASCADE, related_name='wm_m')
|
||||||
mgroup = models.ForeignKey(Mgroup, verbose_name='所在工段', on_delete=models.CASCADE, null=True, blank=True)
|
mgroup = models.ForeignKey(Mgroup, verbose_name='所在工段', on_delete=models.CASCADE, null=True, blank=True)
|
||||||
|
|
|
@ -383,6 +383,8 @@ class MlogbInSerializer(CustomModelSerializer):
|
||||||
mlog: Mlog = attrs['mlog']
|
mlog: Mlog = attrs['mlog']
|
||||||
mtask: Mtask = attrs['mtask']
|
mtask: Mtask = attrs['mtask']
|
||||||
wm_in: WMaterial = attrs['wm_in']
|
wm_in: WMaterial = attrs['wm_in']
|
||||||
|
if wm_in.state != WMaterial.WM_OK:
|
||||||
|
raise ValidationError('非合格品不可使用')
|
||||||
if mlog.route != mtask.route:
|
if mlog.route != mtask.route:
|
||||||
raise ValidationError('工序不匹配')
|
raise ValidationError('工序不匹配')
|
||||||
route = mlog.route
|
route = mlog.route
|
||||||
|
|
|
@ -120,9 +120,7 @@ def do_out(mio: MIO):
|
||||||
# 领到车间库存(或工段)
|
# 领到车间库存(或工段)
|
||||||
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,
|
belong_dept=belong_dept, mgroup=mgroup,
|
||||||
notok_sign=None,
|
state=WMaterial.WM_OK,
|
||||||
material_origin=None,
|
|
||||||
count_xtest=None,
|
|
||||||
defaults={
|
defaults={
|
||||||
"batch": xbatch,
|
"batch": xbatch,
|
||||||
"material": xmaterial,
|
"material": xmaterial,
|
||||||
|
@ -130,6 +128,7 @@ def do_out(mio: MIO):
|
||||||
"create_by": do_user,
|
"create_by": do_user,
|
||||||
"belong_dept": belong_dept,
|
"belong_dept": belong_dept,
|
||||||
"mgroup": mgroup,
|
"mgroup": mgroup,
|
||||||
|
"state": WMaterial.WM_OK,
|
||||||
})
|
})
|
||||||
if not new_create:
|
if not new_create:
|
||||||
wm.count = wm.count + item.count
|
wm.count = wm.count + item.count
|
||||||
|
@ -165,7 +164,7 @@ 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=mgroup, notok_sign=None, material_origin=None, count_xtest=None)
|
wm_qs = WMaterial.objects.filter(batch=xbatch, material=xmaterial, belong_dept=belong_dept, mgroup=mgroup, state=WMaterial.WM_OK)
|
||||||
# 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, material_origin=None, count_xtest=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)
|
||||||
|
|
||||||
|
@ -218,9 +217,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, count_xtest=None, material_origin=None)
|
wm_qs = WMaterial.objects.filter(batch=mi_batch, material=mi_ma, mgroup=mgroup, state=WMaterial.WM_OK)
|
||||||
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, count_xtest=None, material_origin=None)
|
wm_qs = WMaterial.objects.filter(batch=mi_batch, material=mi_ma, belong_dept=belong_dept, mgroup=None, state=WMaterial.WM_OK)
|
||||||
|
|
||||||
count_x = wm_qs.count()
|
count_x = wm_qs.count()
|
||||||
if count_x == 1:
|
if count_x == 1:
|
||||||
|
@ -260,7 +259,8 @@ 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, 'material_origin': None, 'count_xtest': None}
|
wm_state = WMaterial.WM_OK if notok_sign is None else WMaterial.WM_NOTOK
|
||||||
|
lookup = {'batch': mo_batch, 'material': mo_ma, 'mgroup': None, 'notok_sign': notok_sign, 'state': wm_state}
|
||||||
if into_wm_mgroup:
|
if into_wm_mgroup:
|
||||||
lookup['mgroup'] = mgroup
|
lookup['mgroup'] = mgroup
|
||||||
stored_mgroup = True
|
stored_mgroup = True
|
||||||
|
@ -310,7 +310,7 @@ def mlog_revert(mlog: Mlog, user: User, now: Union[datetime.datetime, None]):
|
||||||
mi_wm_in.save()
|
mi_wm_in.save()
|
||||||
else:
|
else:
|
||||||
# 针对光子的情况,实际上必须需要wm_in
|
# 针对光子的情况,实际上必须需要wm_in
|
||||||
lookup = {'batch': mi_batch, 'material': mi_ma, 'mgroup': None, 'notok_sign': None, 'material_origin': None, 'count_xtest': None}
|
lookup = {'batch': mi_batch, 'material': mi_ma, 'mgroup': None, 'state': WMaterial.WM_OK}
|
||||||
if into_wm_mgroup:
|
if into_wm_mgroup:
|
||||||
# 退回到本工段
|
# 退回到本工段
|
||||||
lookup['mgroup'] = mgroup
|
lookup['mgroup'] = mgroup
|
||||||
|
@ -339,7 +339,8 @@ 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, 'material_origin': None, 'count_xtest': None}
|
wm_state = WMaterial.WM_OK if notok_sign is None else WMaterial.WM_NOTOK
|
||||||
|
lookup = {'batch': mo_batch, 'material': mo_ma, 'mgroup': None, 'notok_sign': notok_sign, 'state': wm_state}
|
||||||
if stored_mgroup:
|
if stored_mgroup:
|
||||||
lookup['mgroup'] = mgroup
|
lookup['mgroup'] = mgroup
|
||||||
else:
|
else:
|
||||||
|
@ -522,19 +523,16 @@ def handover_submit(handover: Handover, user: User, now: Union[datetime.datetime
|
||||||
batch=batch,
|
batch=batch,
|
||||||
material=material,
|
material=material,
|
||||||
mgroup=handover.recive_mgroup,
|
mgroup=handover.recive_mgroup,
|
||||||
material_origin=None,
|
state=WMaterial.WM_OK,
|
||||||
notok_sign=None,
|
|
||||||
count_xtest=None,
|
|
||||||
defaults={"batch": batch, "material": material, "mgroup": handover.recive_mgroup, "belong_dept": handover.recive_dept},
|
defaults={"batch": batch, "material": material, "mgroup": handover.recive_mgroup, "belong_dept": handover.recive_dept},
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
wm_to, _ = WMaterial.objects.get_or_create(
|
wm_to, _ = WMaterial.objects.get_or_create(
|
||||||
batch=batch,
|
batch=batch,
|
||||||
material=material,
|
material=material,
|
||||||
belong_dept=handover.recive_dept,
|
belong_dept=handover.recive_dept,
|
||||||
material_origin=None,
|
mgroup=None,
|
||||||
notok_sign=None,
|
state=WMaterial.WM_OK,
|
||||||
count_xtest=None,
|
|
||||||
defaults={"batch": batch, "material": material, "belong_dept": handover.recive_dept}
|
defaults={"batch": batch, "material": material, "belong_dept": handover.recive_dept}
|
||||||
)
|
)
|
||||||
elif handover.type == Handover.H_REPAIR:
|
elif handover.type == Handover.H_REPAIR:
|
||||||
|
@ -545,7 +543,7 @@ def handover_submit(handover: Handover, user: User, now: Union[datetime.datetime
|
||||||
mgroup=handover.recive_mgroup,
|
mgroup=handover.recive_mgroup,
|
||||||
notok_sign=handover.wm.notok_sign,
|
notok_sign=handover.wm.notok_sign,
|
||||||
material_origin=handover.material,
|
material_origin=handover.material,
|
||||||
count_xtest=None,
|
state=WMaterial.WM_REPAIR,
|
||||||
defaults={
|
defaults={
|
||||||
"batch": batch,
|
"batch": batch,
|
||||||
"material": handover.material_changed,
|
"material": handover.material_changed,
|
||||||
|
@ -553,6 +551,7 @@ def handover_submit(handover: Handover, user: User, now: Union[datetime.datetime
|
||||||
"notok_sign": handover.wm.notok_sign,
|
"notok_sign": handover.wm.notok_sign,
|
||||||
"material_origin": handover.material,
|
"material_origin": handover.material,
|
||||||
"belong_dept": handover.recive_dept,
|
"belong_dept": handover.recive_dept,
|
||||||
|
"state": WMaterial.WM_REPAIR
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
@ -563,23 +562,23 @@ def handover_submit(handover: Handover, user: User, now: Union[datetime.datetime
|
||||||
batch=batch,
|
batch=batch,
|
||||||
material=material,
|
material=material,
|
||||||
mgroup=handover.recive_mgroup,
|
mgroup=handover.recive_mgroup,
|
||||||
material_origin=None,
|
state=WMaterial.WM_TEST,
|
||||||
notok_sign=None,
|
|
||||||
defaults={
|
defaults={
|
||||||
"batch": batch,
|
"batch": batch,
|
||||||
"material": material,
|
"material": material,
|
||||||
"mgroup": handover.recive_mgroup,
|
"mgroup": handover.recive_mgroup,
|
||||||
"belong_dept": handover.recive_dept,
|
"belong_dept": handover.recive_dept,
|
||||||
"count_xtest": 0},
|
"count_xtest": 0,
|
||||||
|
"state": WMaterial.WM_TEST},
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
wm_to, _ = WMaterial.objects.get_or_create(
|
wm_to, _ = WMaterial.objects.get_or_create(
|
||||||
batch=batch,
|
batch=batch,
|
||||||
material=material,
|
material=material,
|
||||||
belong_dept=handover.recive_dept,
|
belong_dept=handover.recive_dept,
|
||||||
material_origin=None,
|
mgroup=None,
|
||||||
notok_sign=None,
|
state=WMaterial.WM_TEST,
|
||||||
defaults={"batch": batch, "material": material, "belong_dept": handover.recive_dept, "count_xtest": 0},
|
defaults={"batch": batch, "material": material, "belong_dept": handover.recive_dept, "count_xtest": 0, "state": WMaterial.WM_TEST},
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
raise ParseError("不支持交接类型")
|
raise ParseError("不支持交接类型")
|
||||||
|
|
Loading…
Reference in New Issue