diff --git a/apps/wpm/models.py b/apps/wpm/models.py index f0c9691b..ee73e776 100644 --- a/apps/wpm/models.py +++ b/apps/wpm/models.py @@ -553,13 +553,18 @@ class Mlogb(BaseModel): def sync_inherited_defect(self, cal_count=True): inherited_qs = MlogbDefect.objects.filter(mlogb=self, is_inherited=True) + had_inherited = inherited_qs.exists() if MlogbDefect.objects.filter(mlogb=self, is_inherited=False).exists() or self.has_legacy_defect_count(): inherited_qs.delete() + if had_inherited and cal_count: + self.cal_count_notok(cal_mlog=False) return defect = self.get_default_inherited_defect() if defect is None: inherited_qs.delete() + if had_inherited and cal_count: + self.cal_count_notok(cal_mlog=False) return count = self.count_real diff --git a/apps/wpm/services.py b/apps/wpm/services.py index 2ca76193..c283ac5f 100644 --- a/apps/wpm/services.py +++ b/apps/wpm/services.py @@ -610,6 +610,18 @@ def mlog_revert(mlog: Mlog, user: User, now: Union[datetime.datetime, None]): mlog.submit_user = None mlog.save() + # 兜底清理历史 is_fix 错误带入的继承缺陷 + if is_fix: + legacy_mlogbouts = list(Mlogb.objects.filter( + mlog=mlog, + material_out__isnull=False, + mlogbdefect__is_inherited=True, + ).distinct()) + if legacy_mlogbouts: + for mlogbout in legacy_mlogbouts: + mlogbout.sync_inherited_defect(cal_count=True) + mlog.cal_mlog_count_from_mlogb() + # mtask变更状态 update_mtaskIds = [] if mlog.mtask: