From fa221218f9b7740493160a4baa6809fa420817f5 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Fri, 6 Jun 2025 15:58:33 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20cal=5Fcount=5Fnotok=20=E5=AE=8C?= =?UTF-8?q?=E5=85=A8=E5=90=88=E6=A0=BC=E6=95=B0=E6=9C=89bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/wpm/models.py | 6 +++++- apps/wpm/serializers.py | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/apps/wpm/models.py b/apps/wpm/models.py index 6ccbec23..82fcf7ae 100644 --- a/apps/wpm/models.py +++ b/apps/wpm/models.py @@ -417,6 +417,8 @@ class Mlogb(BaseModel): self.count_notok = count_notok self.count_ok = self.count_real - count_notok self.count_ok_full = self.count_real - count_notok_full + if self.count_ok_full < 0: + raise ParseError("完全合格数不能小于0") self.save(update_fields=["count_ok", "count_notok", "count_ok_full"]) mlog = self.mlog if mlog: @@ -424,6 +426,8 @@ class Mlogb(BaseModel): count_notok = mqs2.aggregate(total=Sum("count"))["total"] or 0 count_notok_full = mqs2.exclude(defect__okcate=10).aggregate(total=Sum("count"))["total"] or 0 mlog.count_ok_full = self.count_real - count_notok_full + if mlog.count_ok_full < 0: + raise ParseError("完全合格数不能小于0") mlog.count_notok = count_notok mlog.count_ok = self.count_real - count_notok mlog.save(update_fields=["count_ok", "count_notok", "count_ok_full"]) @@ -470,7 +474,7 @@ class Mlogbw(BaseModel): def cal_count_notok(cls, mlogb: Mlog): from apps.qm.models import Defect # 锁定mlogb以防止并发修改 - mlogb = Mlogb.objects.select_for_update().get(pk=mlogb.pk) + # mlogb:Mlogb = Mlogb.objects.select_for_update().get(pk=mlogb.pk) count = Mlogbw.objects.filter(mlogb=mlogb).count() if mlogb.material_in: mlogb.count_use = count diff --git a/apps/wpm/serializers.py b/apps/wpm/serializers.py index 19e4c697..02574854 100644 --- a/apps/wpm/serializers.py +++ b/apps/wpm/serializers.py @@ -494,7 +494,7 @@ class MlogSerializer(CustomModelSerializer): ] if mlogbin_defect_objects: MlogbDefect.objects.bulk_create(mlogbin_defect_objects) - minx.cal_count_pn_jgqbl() + minx.cal_count_pn_jgqbl() # 修改产出 if instance.fill_way == Mlog.MLOG_2 and instance.material_out.brothers: @@ -539,7 +539,7 @@ class MlogSerializer(CustomModelSerializer): ] if mlogb_defect_objects: MlogbDefect.objects.bulk_create(mlogb_defect_objects) - mox.cal_count_notok() + mox.cal_count_notok() return instance def validate(self, attrs):