feat: mlog撤回
This commit is contained in:
parent
695590589e
commit
4b327c0575
|
|
@ -226,6 +226,7 @@ def mlog_submit(mlog: Mlog, user: User, now: Union[datetime.datetime, None]):
|
||||||
|
|
||||||
|
|
||||||
if material_out: # 需要入车间库存
|
if material_out: # 需要入车间库存
|
||||||
|
tracking = material_out.tracking
|
||||||
into_wm_mgroup = material_out.process.into_wm_mgroup if material_out.process else False
|
into_wm_mgroup = material_out.process.into_wm_mgroup if material_out.process else False
|
||||||
need_store_notok = material_out.process.store_notok if material_out.process else False
|
need_store_notok = material_out.process.store_notok if material_out.process else False
|
||||||
m_outs = Mlogb.objects.filter(mlog=mlog, material_out__isnull=False)
|
m_outs = Mlogb.objects.filter(mlog=mlog, material_out__isnull=False)
|
||||||
|
|
@ -235,7 +236,7 @@ def mlog_submit(mlog: Mlog, user: User, now: Union[datetime.datetime, None]):
|
||||||
m_outs_list = [(mo.material_out, mo.batch if mo.batch else mlog.batch, mo.count_ok, mlog.count_real_eweight, None, mo) for mo in m_outs.all()]
|
m_outs_list = [(mo.material_out, mo.batch if mo.batch else mlog.batch, mo.count_ok, mlog.count_real_eweight, None, mo) for mo in m_outs.all()]
|
||||||
if need_store_notok:
|
if need_store_notok:
|
||||||
for item in m_outs:
|
for item in m_outs:
|
||||||
if Mlogbw.objects.filter(mlogb=item).exists():
|
if tracking == Material.MA_TRACKING_SINGLE:
|
||||||
# 获取所有主要的不合格项
|
# 获取所有主要的不合格项
|
||||||
bw_qs = Mlogbw.objects.filter(mlogb=item)
|
bw_qs = Mlogbw.objects.filter(mlogb=item)
|
||||||
defectIds= FtestDefect.objects.filter(ftest__mlogbw_ftest__in=bw_qs, is_main=True, has=True).values_list("defect__id", flat=True).distinct()
|
defectIds= FtestDefect.objects.filter(ftest__mlogbw_ftest__in=bw_qs, is_main=True, has=True).values_list("defect__id", flat=True).distinct()
|
||||||
|
|
@ -253,7 +254,6 @@ def mlog_submit(mlog: Mlog, user: User, now: Union[datetime.datetime, None]):
|
||||||
if xcount > 0:
|
if xcount > 0:
|
||||||
defect = defects_map[defect_id]
|
defect = defects_map[defect_id]
|
||||||
m_outs_list.append((item.material_out, item.batch, xcount, 0, defect, item))
|
m_outs_list.append((item.material_out, item.batch, xcount, 0, defect, item))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
for f in Mlogb._meta.fields:
|
for f in Mlogb._meta.fields:
|
||||||
if 'count_n_' in f.name and getattr(item, f.name) > 0:
|
if 'count_n_' in f.name and getattr(item, f.name) > 0:
|
||||||
|
|
@ -353,6 +353,25 @@ def mlog_revert(mlog: Mlog, user: User, now: Union[datetime.datetime, None]):
|
||||||
for mo in m_outs.all()]
|
for mo in m_outs.all()]
|
||||||
if stored_notok:
|
if stored_notok:
|
||||||
for item in m_outs:
|
for item in m_outs:
|
||||||
|
if material_out.tracking == Material.MA_TRACKING_SINGLE:
|
||||||
|
# 获取所有主要的不合格项
|
||||||
|
bw_qs = Mlogbw.objects.filter(mlogb=item)
|
||||||
|
defectIds= FtestDefect.objects.filter(ftest__mlogbw_ftest__in=bw_qs, is_main=True, has=True).values_list("defect__id", flat=True).distinct()
|
||||||
|
defects_map = {d.id: d for d in Defect.objects.filter(id__in=defectIds)}
|
||||||
|
# 过滤并统计相关数据
|
||||||
|
filtered_bw_qs = bw_qs.filter(
|
||||||
|
ftest__defects_ftest__defect__id__in=defects_map.keys(),
|
||||||
|
ftest__defects_ftest__has=True,
|
||||||
|
ftest__defects_ftest__is_main=True
|
||||||
|
).values('ftest__defects_ftest__defect__id').annotate(xcount=Count('id'))
|
||||||
|
# 整理结果
|
||||||
|
for defect_data in filtered_bw_qs:
|
||||||
|
defect_id = defect_data['ftest__defects_ftest__defect__id']
|
||||||
|
xcount = defect_data['xcount']
|
||||||
|
if xcount > 0:
|
||||||
|
defect = defects_map[defect_id]
|
||||||
|
m_outs_list.append((item.material_out, item.batch, xcount, 0, defect, item))
|
||||||
|
else:
|
||||||
for f in Mlogb._meta.fields:
|
for f in Mlogb._meta.fields:
|
||||||
if 'count_n_' in f.name and getattr(item, f.name) > 0:
|
if 'count_n_' in f.name and getattr(item, f.name) > 0:
|
||||||
notok_sign = f.name.replace('count_n_', '')
|
notok_sign = f.name.replace('count_n_', '')
|
||||||
|
|
@ -363,11 +382,15 @@ 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, mlog_or_b = mo
|
mo_ma, mo_batch, mo_count, _, notok_sign_or_defect, mlog_or_b = mo
|
||||||
if mo_count == 0:
|
if mo_count == 0:
|
||||||
continue
|
continue
|
||||||
wm_state = WMaterial.WM_OK if notok_sign is None else WMaterial.WM_NOTOK
|
wm_state = WMaterial.WM_OK if notok_sign_or_defect is None else WMaterial.WM_NOTOK
|
||||||
lookup = {'batch': mo_batch, 'material': mo_ma, 'mgroup': None, 'notok_sign': notok_sign, 'state': wm_state}
|
lookup = {'batch': mo_batch, 'material': mo_ma, 'mgroup': None, 'notok_sign': None, 'defect': None, 'state': wm_state}
|
||||||
|
if isinstance(notok_sign_or_defect, Defect):
|
||||||
|
lookup['defect'] = notok_sign_or_defect
|
||||||
|
else:
|
||||||
|
lookup['notok_sign'] = notok_sign_or_defect
|
||||||
if stored_mgroup:
|
if stored_mgroup:
|
||||||
lookup['mgroup'] = mgroup
|
lookup['mgroup'] = mgroup
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue