From 6d87a69d8d30b8578a85320f4315fecd37bb78d3 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Fri, 13 Jun 2025 11:23:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20cal=5Fmlog=5Fcount=5Ffrom=5Fmlogb=20?= =?UTF-8?q?=E9=9C=80=E8=A6=81=E4=BC=A0=E5=8F=82=E8=A7=A6=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/wpm/models.py | 12 ++++++------ apps/wpm/serializers.py | 20 +++++++++++--------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/apps/wpm/models.py b/apps/wpm/models.py index a1920d26..600a52ad 100644 --- a/apps/wpm/models.py +++ b/apps/wpm/models.py @@ -431,16 +431,16 @@ class Mlogb(BaseModel): def mlogbdefect(self): return MlogbDefect.objects.filter(mlogb=self) - def cal_count_pn_jgqbl(self): + def cal_count_pn_jgqbl(self, cal_mlog=False): mqs = MlogbDefect.get_defect_qs_from_mlogb(self, ftype="in") count_pn_jgqbl = mqs.aggregate(total=Sum("count"))["total"] or 0 self.count_pn_jgqbl = count_pn_jgqbl self.save(update_fields=["count_pn_jgqbl"]) mlog = self.mlog - if mlog: + if mlog and cal_mlog: mlog.cal_mlog_count_from_mlogb() - def cal_count_notok(self): + def cal_count_notok(self, cal_mlog=True): mqs = MlogbDefect.get_defect_qs_from_mlogb(self, ftype="out") count_notok = mqs.filter(defect__okcate=30).aggregate(total=Sum("count"))["total"] or 0 count_notok_full = mqs.exclude(defect__okcate=10).aggregate(total=Sum("count"))["total"] or 0 @@ -448,10 +448,10 @@ class Mlogb(BaseModel): 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") + raise ParseError(f"完全合格数不能小于0:{self.count_real}-{self.count_ok}-{self.count_notok}-{self.count_ok_full}") self.save(update_fields=["count_ok", "count_notok", "count_ok_full"]) mlog = self.mlog - if mlog: + if mlog and cal_mlog: mlog.cal_mlog_count_from_mlogb() class MlogbDefect(BaseModel): @@ -518,7 +518,7 @@ class Mlogbw(BaseModel): mlogb.count_notok = count_notok mlogb.count_ok = count - mlogb.count_notok mlogb.save() - mlogb.cal_count_notok() + mlogb.cal_count_notok(cal_mlog=True) class Handover(CommonADModel): """ diff --git a/apps/wpm/serializers.py b/apps/wpm/serializers.py index ab7eb67a..292584f0 100644 --- a/apps/wpm/serializers.py +++ b/apps/wpm/serializers.py @@ -389,7 +389,7 @@ class MlogSerializer(CustomModelSerializer): ] if mlogbin_defect_objects: MlogbDefect.objects.bulk_create(mlogbin_defect_objects) - mlogbin.cal_count_pn_jgqbl() + mlogbin.cal_count_pn_jgqbl(cal_mlog=False) # mlogb只用于组合件输出物填写 brotherId_should_list = material_out.brothers @@ -416,7 +416,7 @@ class MlogSerializer(CustomModelSerializer): pass else: batch_out = generate_new_batch(batch_in, instance) - + add_dict_2 = { 'mlog': instance, 'batch': batch_out, 'mtask': instance.mtask, 'material_out': instance.material_out, @@ -445,7 +445,8 @@ class MlogSerializer(CustomModelSerializer): ] if mlogb_defect_objects: MlogbDefect.objects.bulk_create(mlogb_defect_objects) - mlogb.cal_count_notok() + mlogb.cal_count_notok(cal_mlog=False) + instance.cal_mlog_count_from_mlogb() return instance def update(self, instance, validated_data): @@ -495,7 +496,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(cal_mlog=False) # 修改产出 if instance.fill_way == Mlog.MLOG_2 and instance.material_out.brothers: @@ -540,7 +541,8 @@ class MlogSerializer(CustomModelSerializer): ] if mlogb_defect_objects: MlogbDefect.objects.bulk_create(mlogb_defect_objects) - mox.cal_count_notok() + mox.cal_count_notok(cal_mlog=False) + instance.cal_mlog_count_from_mlogb() return instance def validate(self, attrs): @@ -757,7 +759,7 @@ class MlogbInSerializer(CustomModelSerializer): ] if mlogb_defect_objects: MlogbDefect.objects.bulk_create(mlogb_defect_objects) - ins.cal_count_pn_jgqbl() + ins.cal_count_pn_jgqbl(cal_mlog=True) return ins class MlogbInUpdateSerializer(CustomModelSerializer): @@ -775,7 +777,7 @@ class MlogbInUpdateSerializer(CustomModelSerializer): mlogbdefect = validated_data.pop("mlogbdefect", None) if mlog.submit_time is not None: raise ParseError('生产日志已提交不可编辑') - ins = super().update(instance, validated_data) + ins:Mlogb = super().update(instance, validated_data) if mlogbdefect is not None and ins.material_in.tracking == Material.MA_TRACKING_BATCH: MlogbDefect.objects.filter(mlogb=ins).delete() mlogb_defect_objects = [ @@ -784,7 +786,7 @@ class MlogbInUpdateSerializer(CustomModelSerializer): ] if mlogb_defect_objects: MlogbDefect.objects.bulk_create(mlogb_defect_objects) - ins.cal_count_notok() + ins.cal_count_notok(cal_mlog=True) return ins class MlogbwCreateUpdateSerializer(CustomModelSerializer): @@ -900,7 +902,7 @@ class MlogbOutUpdateSerializer(CustomModelSerializer): ] if mlogb_defect_objects: MlogbDefect.objects.bulk_create(mlogb_defect_objects) - ins.cal_count_notok() + ins.cal_count_notok(cal_mlog=True) return ins def validate(self, attrs):