From 8d67c06e63a8c231e1e25abef202200433c1d378 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Wed, 12 Mar 2025 13:34:56 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=94=9F=E6=88=90=E4=BA=A7=E5=87=BA?= =?UTF-8?q?=E5=87=BA=E9=94=992=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/wpm/views.py | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/apps/wpm/views.py b/apps/wpm/views.py index 720c2ba1..4616142d 100644 --- a/apps/wpm/views.py +++ b/apps/wpm/views.py @@ -561,6 +561,7 @@ class MlogbInViewSet(CreateModelMixin, UpdateModelMixin, DestroyModelMixin, Cust qs.delete() if ftestIds: Ftest.objects.filter(id__in=ftestIds).delete() + Mlogb.objects.filter(id__in=Mlogbw.objects.filter(mlogb=ins).values_list("mlogb_to__id", flat=True)).delete() ins.delete() @transaction.atomic @@ -580,12 +581,6 @@ class MlogbInViewSet(CreateModelMixin, UpdateModelMixin, DestroyModelMixin, Cust # 如果是主要输入物料且是主批次,才需生成输出 if route and route.material_in != material_in or mlogbin.parent is not None: return - m_dict = { - "mtask": mlogbin.mtask, - "mlog": mlog, - "material_out": material_out, - } - m_dict['batch'] = generate_new_batch(mlogbin.batch, mlog) wm_in: WMaterial = mlogbin.wm_in @@ -598,6 +593,16 @@ class MlogbInViewSet(CreateModelMixin, UpdateModelMixin, DestroyModelMixin, Cust mlog.qct = Qct.get(material_out, "process") mlog.save(update_fields = ["qct"]) + m_dict = { + "mtask": mlogbin.mtask, + "mlog": mlog, + "material_out": material_out, + } + if mtype == Process.PRO_DIV and material_in.tracking == Material.MA_TRACKING_SINGLE: + pass + else: + m_dict['batch'] = generate_new_batch(mlogbin.batch, mlog) + if mtype == Process.PRO_NORMAL: d_count_real = mlogbin.count_use d_count_ok = mlogbin.count_use @@ -610,14 +615,26 @@ class MlogbInViewSet(CreateModelMixin, UpdateModelMixin, DestroyModelMixin, Cust raise ParseError("生成产出出错1") elif mtype == Process.PRO_DIV: div_number = route.div_number - for mlogbwin in Mlogbw.objects.filter(mlogb=mlogbin).order_by("number"): + if material_in.tracking == Material.MA_TRACKING_SINGLE: + 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}) + if mlogbwin.mlogb_to is None: + mlogbwin.mlogb_to = mlogbout + mlogbwin.save(update_fields = ["mlogb_to"]) + elif mlogbwin.mlogb_to != mlogbout: + raise ParseError("生成产出出错2") + elif 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": div_number, "count_ok": div_number, "qct": qct}) - if mlogbwin.mlogb_to is None: - mlogbwin.mlogb_to = mlogbout - mlogbwin.save(update_fields = ["mlogb_to"]) - elif mlogbwin.mlogb_to != mlogbout: - raise ParseError("生成产出出错2") + {"batch_ofrom": wm_in.batch_ofrom, "material_ofrom": wm_in.material_ofrom, "count_real": d_count_real, "count_ok": d_count_ok, "qct": qct}) + if mlogbin.mlogb_to is None: + mlogbin.mlogb_to = mlogbout + mlogbin.save(update_fields = ["mlogb_to"]) + elif mlogbin.mlogb_to != mlogbout: + raise ParseError("生成产出出错2-2") elif mtype == Process.PRO_MERGE: xcount = math.floor( mlogbin.count_use / route.div_number) d_count_real = xcount