fix: 个到个的拆分bug5

This commit is contained in:
caoqianming 2025-03-14 16:01:54 +08:00
parent 6fa9c9182b
commit c8cde0a436
1 changed files with 13 additions and 38 deletions

View File

@ -33,7 +33,7 @@ from apps.wpmw.models import Wpr
from apps.qm.models import Qct, Ftest, TestItem
from apps.enm.models import EnStat
from django.db.models import Q
from apps.utils.tools import convert_ordereddict
from apps.utils.tools import convert_ordereddict, update_dict
from django.db.models import Count
@ -574,6 +574,8 @@ class MlogbInViewSet(CreateModelMixin, UpdateModelMixin, DestroyModelMixin, Cust
"mtask": mlogbin.mtask,
"mlog": mlog,
"material_out": material_out,
"batch_ofrom": wm_in.batch_ofrom, "material_ofrom": wm_in.material_ofrom,
"qct": qct
}
if mtype == Process.PRO_DIV and material_in.tracking == Material.MA_TRACKING_SINGLE:
pass
@ -583,11 +585,8 @@ class MlogbInViewSet(CreateModelMixin, UpdateModelMixin, DestroyModelMixin, Cust
if mtype == Process.PRO_NORMAL: # 正常 支持批到批, 个到个
d_count_real = mlogbin.count_use
d_count_ok = mlogbin.count_use
mlogbout, _ = Mlogb.objects.get_or_create(**m_dict, defaults=
{"batch_ofrom": wm_in.batch_ofrom, "material_ofrom": wm_in.material_ofrom, "count_real": d_count_real, "count_ok": d_count_ok,
"qct": qct, "mlogb_from": mlogbin})
if mlogbout.mlogb_from != mlogbin:
raise ParseError("生成产出出错1")
mlogbout, _ = Mlogb.objects.get_or_create(mlogb_from=mlogbin, defaults=
update_dict(m_dict, {"count_real": d_count_real, "count_ok": d_count_ok}))
if material_in.tracking == Material.MA_TRACKING_SINGLE and material_out.tracking == Material.MA_TRACKING_SINGLE:
for mlogbwin in Mlogbw.objects.filter(mlogb=mlogbin).order_by("number"):
Mlogbw.objects.get_or_create(wpr=wpr, mlogb=mlogbout, defaults={"number": wpr.number, "mlogbw_from": mlogbwin})
@ -596,52 +595,30 @@ class MlogbInViewSet(CreateModelMixin, UpdateModelMixin, DestroyModelMixin, Cust
if material_in.tracking == Material.MA_TRACKING_SINGLE and material_out.tracking == Material.MA_TRACKING_BATCH:
for mlogbwin in Mlogbw.objects.filter(mlogb=mlogbin).order_by("number"):
m_dict["batch"] = mlogbwin.number
mlogbout, _ = Mlogb.objects.get_or_create(**m_dict, defaults=
{"batch_ofrom": wm_in.batch_ofrom, "material_ofrom": wm_in.material_ofrom,
"count_real": div_number, "count_ok": div_number, "qct": qct, "mlogbw_from": mlogbwin})
if mlogbout.mlogbw_from != mlogbwin:
raise ParseError("生成产出出错2")
Mlogb.objects.get_or_create(mlogbw_from=mlogbwin, defaults=update_dict(m_dict, {"count_real": div_number, "count_ok": div_number}))
elif material_in.tracking == Material.MA_TRACKING_SINGLE and material_out.tracking == Material.MA_TRACKING_SINGLE:
mlogbout, _ = Mlogb.objects.get_or_create(mlogb_from=mlogbin, defaults=update_dict(m_dict, {"count_real": d_count_real*div_number, "count_ok": d_count_ok*div_number}))
for mlogbwin in Mlogbw.objects.filter(mlogb=mlogbin).order_by("number"):
m_dict["batch"] = mlogbwin.number
mlogbout, _ = Mlogb.objects.get_or_create(**m_dict, defaults=
{"batch_ofrom": wm_in.batch_ofrom, "material_ofrom": wm_in.material_ofrom,
"count_real": div_number, "count_ok": div_number, "qct": qct, "mlogbw_from": mlogbwin})
if mlogbout.mlogbw_from != mlogbwin:
raise ParseError("生成产出出错2-2")
wpr_ = mlogbwin.wpr
for i in range(div_number):
Mlogbw.objects.get_or_create(mlogb=mlogbout, number=f'{wpr_.number}-{i+1}', defaults={"mlogbw_from": mlogbwin})
elif material_in.tracking == Material.MA_TRACKING_BATCH and material_out.tracking == Material.MA_TRACKING_BATCH:
d_count_real = mlogbin.count_use * div_number
d_count_ok = d_count_real
mlogbout, _ = Mlogb.objects.get_or_create(**m_dict, defaults=
{"batch_ofrom": wm_in.batch_ofrom, "material_ofrom": wm_in.material_ofrom,
"count_real": d_count_real, "count_ok": d_count_ok, "qct": qct, "mlogb_from": mlogbin})
if mlogbout.mlogb_from != mlogbin:
raise ParseError("生成产出出错2-2")
Mlogb.objects.get_or_create(mlogb_from=mlogbin, defaults=update_dict(m_dict,{"count_real": d_count_real, "count_ok": d_count_ok}))
elif mtype == Process.PRO_MERGE: # 支持批到批
xcount = math.floor( mlogbin.count_use / route.div_number)
d_count_real = xcount
d_count_ok = xcount
mlogbout, _ = Mlogb.objects.get_or_create(**m_dict, defaults=
{"batch_ofrom": wm_in.batch_ofrom, "material_ofrom": wm_in.material_ofrom,
"count_real": d_count_real, "count_ok": d_count_ok, "qct": qct, "mlogb_from": mlogbin})
if mlogbout.mlogb_from != mlogbin:
raise ParseError("生成产出出错3")
Mlogb.objects.get_or_create(mlogb_from=mlogbin, defaults=update_dict(m_dict, {"count_real": d_count_real, "count_ok": d_count_ok}))
elif is_fix:# 支持批到批,个到个
d_count_real = mlogbin.count_use
d_count_ok = mlogbin.count_use
mlogbout, _ = Mlogb.objects.get_or_create(**m_dict, defaults=
{"batch_ofrom": wm_in.batch_ofrom, "material_ofrom": wm_in.material_ofrom,
"count_real": d_count_real, "count_ok": d_count_ok, "qct": qct, "mlogb_from": mlogbin})
if mlogbout.mlogb_from != mlogbin:
raise ParseError("生成产出出错4")
Mlogb.objects.get_or_create(mlogb_from=mlogbin, defaults=update_dict(m_dict,{"count_real": d_count_real, "count_ok": d_count_ok}))
if material_in.tracking == Material.MA_TRACKING_SINGLE and material_out.tracking == Material.MA_TRACKING_SINGLE:
for mlogbwin in Mlogbw.objects.filter(mlogb=mlogbin).order_by("number"):
bw, _ = Mlogbw.objects.get_or_create(wpr=wpr, mlogb=mlogbout, defaults={"number": wpr.number, "mlogbw_from": mlogbwin})
if bw.mlogbw_from != mlogbwin:
raise ParseError("生成产出出错5")
wpr = mlogbwin.wpr
Mlogbw.objects.get_or_create(wpr=wpr, mlogb=mlogbout, defaults={"number": wpr.number, "mlogbw_from": mlogbwin})
else:
raise ParseError("不支持生成产出物料!")
@ -735,9 +712,7 @@ class MlogbwViewSet(CustomModelViewSet):
elif mlogb_qs.exists() and material_out.tracking == Material.MA_TRACKING_SINGLE:
for mlogb in mlogb_qs:
if route.process.mtype == Process.PRO_NORMAL:
bw, _ = Mlogbw.objects.get_or_create(mlogb=mlogb, wpr=ins.wpr, defaults={"number": ins.number, "mlogbw_from": ins})
if bw.mlogbw_from != ins:
raise ParseError("生成产出出错7")
Mlogbw.objects.get_or_create(mlogb=mlogb, wpr=ins.wpr, defaults={"number": ins.number, "mlogbw_from": ins})
elif route.process.mtype == Process.PRO_DIV:
for i in range(route.div_number):
Mlogbw.objects.get_or_create(mlogb=mlogb, number=f'{ins.number}-{i+1}', defaults={"mlogbw_from": ins})