From c4e0fdd2659ba08589d48f10fbfb593cd17498b1 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Mon, 13 Jul 2026 22:30:15 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E6=8B=86=E6=89=B9/=E6=8A=A5=E5=B7=A5?= =?UTF-8?q?=E6=94=B9=E5=8F=B7=E6=8F=90=E4=BA=A4=E6=97=B6=E7=BA=AF=E7=BB=A7?= =?UTF-8?q?=E6=89=BFzt=5Fbatch=E5=BD=92=E5=B1=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 仅来源料子集式流转(拆批交接/报工改号)继承, 合批不继承以免 不良集中批等共享池被错误归属; 冲突不覆盖记日志 Co-Authored-By: Claude Fable 5 --- apps/wpm/scripts/batch_gxerp.md | 1 + apps/wpm/services.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/apps/wpm/scripts/batch_gxerp.md b/apps/wpm/scripts/batch_gxerp.md index 72e16e84..9cfc7181 100644 --- a/apps/wpm/scripts/batch_gxerp.md +++ b/apps/wpm/scripts/batch_gxerp.md @@ -228,6 +228,7 @@ FtestWork where type2 = TYPE2_SOME - 无任何拆合批上游 → 自身即大批(未拆批直接检验、外购直检)。 2. 归属写入 `zt_batch`(锁定,已锁定的直接复用);随后重算大批(`cal_zt_big`)。 3. 大批自身重算时(有子批 `zt_batch` 指向它)也会触发重算。 +4. **提交时纯继承**(`services.inherit_zt_batch`):拆批交接、报工改号提交时,目标批直接继承来源批已有的 `zt_batch`(来源料子集式流转,永远安全);**合批不继承**——不良集中批(如 `黑检片-00`)等共享池会汇入多个大批的料,继承会造成错误归属,合批复检批(`-A-1`)的归属仍由统计侧"所有来源同大批"判定。已有归属冲突时不覆盖并记日志。 ### 分子 diff --git a/apps/wpm/services.py b/apps/wpm/services.py index 23956746..a9250370 100644 --- a/apps/wpm/services.py +++ b/apps/wpm/services.py @@ -26,6 +26,20 @@ from django.db.models import F myLogger = logging.getLogger('log') +def inherit_zt_batch(source: BatchSt, target: BatchSt): + """拆批/报工改号时目标批继承来源批的直通统计大批归属(纯继承, 不做判定) + + 仅用于来源料子集式的流转(拆批/改号); 合批不继承——不良集中批等共享池 + 会汇入多个大批的料, 继承会造成错误归属。归属的判定与合批复检批(如 大批-A-1) + 的归属由批次统计脚本(如 batch_gxerp)负责。 + """ + if source.zt_batch and target.zt_batch != source.zt_batch: + if target.zt_batch: + myLogger.error(f"直通统计-{target.batch}已归属{target.zt_batch}, 与来源{source.batch}的{source.zt_batch}冲突, 不覆盖") + return + target.zt_batch = source.zt_batch + target.save(update_fields=["zt_batch"]) + def check_wpr_number(number: str): return (len(number) >= 5 and (number[-4:].isdigit() or number[-2] == "-" or number[-3] == "-") and @@ -196,11 +210,13 @@ def mlog_submit(mlog: Mlog, user: User, now: Union[datetime.datetime, None]): target, _ = BatchSt.g_create(batch=item.batch, mlog=mlog, material_start=item.material_out) exclude_batchst_ids.append(target.id) BatchLog.g_create(source= source, target=target, mlog=mlog) + inherit_zt_batch(source, target) if item.mlogbw_from and item.batch != item.mlogbw_from.mlogb.batch: source, _ = BatchSt.g_create(batch=item.mlogbw_from.mlogb.batch, exclude_batchst_ids=exclude_batchst_ids) target, _ = BatchSt.g_create(batch=item.batch, mlog=mlog, material_start=item.material_out) exclude_batchst_ids.append(target.id) BatchLog.g_create(source=source, target=target, mlog=mlog) + inherit_zt_batch(source, target) # 消耗物料处理 m_ins_list = [] @@ -821,6 +837,7 @@ def handover_submit(handover:Handover, user: User, now: Union[datetime.datetime, exclude_batchst_ids.append(target.id) # 这里暂时忽略check_batch_exist,因为拆批一般不会重复 BatchLog.g_create(source=source_b, target=target, handover=handover, relation_type="split") + inherit_zt_batch(source_b, target) else: batch = wm_from.batch batches.append(batch)