fix: cal_mlog_count_from_mlogb 需要传参触发

This commit is contained in:
caoqianming 2025-06-13 11:23:02 +08:00
parent c02bb6d3db
commit 6d87a69d8d
2 changed files with 17 additions and 15 deletions

View File

@ -431,16 +431,16 @@ class Mlogb(BaseModel):
def mlogbdefect(self): def mlogbdefect(self):
return MlogbDefect.objects.filter(mlogb=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") mqs = MlogbDefect.get_defect_qs_from_mlogb(self, ftype="in")
count_pn_jgqbl = mqs.aggregate(total=Sum("count"))["total"] or 0 count_pn_jgqbl = mqs.aggregate(total=Sum("count"))["total"] or 0
self.count_pn_jgqbl = count_pn_jgqbl self.count_pn_jgqbl = count_pn_jgqbl
self.save(update_fields=["count_pn_jgqbl"]) self.save(update_fields=["count_pn_jgqbl"])
mlog = self.mlog mlog = self.mlog
if mlog: if mlog and cal_mlog:
mlog.cal_mlog_count_from_mlogb() 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") 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 = 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 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 = self.count_real - count_notok
self.count_ok_full = self.count_real - count_notok_full self.count_ok_full = self.count_real - count_notok_full
if self.count_ok_full < 0: 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"]) self.save(update_fields=["count_ok", "count_notok", "count_ok_full"])
mlog = self.mlog mlog = self.mlog
if mlog: if mlog and cal_mlog:
mlog.cal_mlog_count_from_mlogb() mlog.cal_mlog_count_from_mlogb()
class MlogbDefect(BaseModel): class MlogbDefect(BaseModel):
@ -518,7 +518,7 @@ class Mlogbw(BaseModel):
mlogb.count_notok = count_notok mlogb.count_notok = count_notok
mlogb.count_ok = count - mlogb.count_notok mlogb.count_ok = count - mlogb.count_notok
mlogb.save() mlogb.save()
mlogb.cal_count_notok() mlogb.cal_count_notok(cal_mlog=True)
class Handover(CommonADModel): class Handover(CommonADModel):
""" """

View File

@ -389,7 +389,7 @@ class MlogSerializer(CustomModelSerializer):
] ]
if mlogbin_defect_objects: if mlogbin_defect_objects:
MlogbDefect.objects.bulk_create(mlogbin_defect_objects) MlogbDefect.objects.bulk_create(mlogbin_defect_objects)
mlogbin.cal_count_pn_jgqbl() mlogbin.cal_count_pn_jgqbl(cal_mlog=False)
# mlogb只用于组合件输出物填写 # mlogb只用于组合件输出物填写
brotherId_should_list = material_out.brothers brotherId_should_list = material_out.brothers
@ -445,7 +445,8 @@ class MlogSerializer(CustomModelSerializer):
] ]
if mlogb_defect_objects: if mlogb_defect_objects:
MlogbDefect.objects.bulk_create(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 return instance
def update(self, instance, validated_data): def update(self, instance, validated_data):
@ -495,7 +496,7 @@ class MlogSerializer(CustomModelSerializer):
] ]
if mlogbin_defect_objects: if mlogbin_defect_objects:
MlogbDefect.objects.bulk_create(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: if instance.fill_way == Mlog.MLOG_2 and instance.material_out.brothers:
@ -540,7 +541,8 @@ class MlogSerializer(CustomModelSerializer):
] ]
if mlogb_defect_objects: if mlogb_defect_objects:
MlogbDefect.objects.bulk_create(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 return instance
def validate(self, attrs): def validate(self, attrs):
@ -757,7 +759,7 @@ class MlogbInSerializer(CustomModelSerializer):
] ]
if mlogb_defect_objects: if mlogb_defect_objects:
MlogbDefect.objects.bulk_create(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 return ins
class MlogbInUpdateSerializer(CustomModelSerializer): class MlogbInUpdateSerializer(CustomModelSerializer):
@ -775,7 +777,7 @@ class MlogbInUpdateSerializer(CustomModelSerializer):
mlogbdefect = validated_data.pop("mlogbdefect", None) mlogbdefect = validated_data.pop("mlogbdefect", None)
if mlog.submit_time is not None: if mlog.submit_time is not None:
raise ParseError('生产日志已提交不可编辑') 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: if mlogbdefect is not None and ins.material_in.tracking == Material.MA_TRACKING_BATCH:
MlogbDefect.objects.filter(mlogb=ins).delete() MlogbDefect.objects.filter(mlogb=ins).delete()
mlogb_defect_objects = [ mlogb_defect_objects = [
@ -784,7 +786,7 @@ class MlogbInUpdateSerializer(CustomModelSerializer):
] ]
if mlogb_defect_objects: if mlogb_defect_objects:
MlogbDefect.objects.bulk_create(mlogb_defect_objects) MlogbDefect.objects.bulk_create(mlogb_defect_objects)
ins.cal_count_notok() ins.cal_count_notok(cal_mlog=True)
return ins return ins
class MlogbwCreateUpdateSerializer(CustomModelSerializer): class MlogbwCreateUpdateSerializer(CustomModelSerializer):
@ -900,7 +902,7 @@ class MlogbOutUpdateSerializer(CustomModelSerializer):
] ]
if mlogb_defect_objects: if mlogb_defect_objects:
MlogbDefect.objects.bulk_create(mlogb_defect_objects) MlogbDefect.objects.bulk_create(mlogb_defect_objects)
ins.cal_count_notok() ins.cal_count_notok(cal_mlog=True)
return ins return ins
def validate(self, attrs): def validate(self, attrs):