From 1f7e17b6c131b59a45244ffe27d8e3c4948d7cf8 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Thu, 30 Apr 2026 11:44:29 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=92=A4=E5=9B=9E=20is=5Ffix=20?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E6=97=B6=E5=85=9C=E5=BA=95=E6=B8=85=E7=90=86?= =?UTF-8?q?=E8=AF=AF=E5=B8=A6=E5=85=A5=E7=9A=84=E7=BB=A7=E6=89=BF=E7=BC=BA?= =?UTF-8?q?=E9=99=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - sync_inherited_defect 早返回路径删除继承记录后补算 mlogb 数量 - mlog_revert 末尾针对 is_fix 已残留继承缺陷的产出 mlogb 触发 sync 并刷新 mlog 汇总 Co-Authored-By: Claude Opus 4.7 (1M context) --- apps/wpm/models.py | 5 +++++ apps/wpm/services.py | 12 ++++++++++++ 2 files changed, 17 insertions(+) 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: