From 70f2d0d2dd4d036e5c4a45e619ad01cf5b576c8f Mon Sep 17 00:00:00 2001 From: caoqianming Date: Tue, 12 May 2026 08:51:08 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20inm=20=E7=94=9F=E4=BA=A7=E9=A2=86?= =?UTF-8?q?=E6=96=99/=E5=85=A5=E5=BA=93=E6=94=AF=E6=8C=81=E5=B8=A6=20defec?= =?UTF-8?q?t=20=E7=89=A9=E6=96=99=E5=B9=B6=E6=8C=89=20okcate=20=E6=8E=A8?= =?UTF-8?q?=E5=AF=BC=20state?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 去除 do_out 对 defect 非空的硬拦截,do_out/do_in 中查询与创建 MaterialBatch、WMaterial 时按 defect.okcate==DEFECT_NOTOK 推导 state=WM_NOTOK,与 update_mb_item 保持一致,撤销路径同步打通。 Co-Authored-By: Claude Opus 4.7 (1M context) --- apps/inm/services.py | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/apps/inm/services.py b/apps/inm/services.py index c0046a9a..8de7c4bf 100644 --- a/apps/inm/services.py +++ b/apps/inm/services.py @@ -13,9 +13,6 @@ def do_out(item: MIOItem, is_reverse: bool = False): """ 生产领料到车间 """ - if item.mb and item.mb.defect is not None: - raise ParseError("生产领料不支持不合格品") - from apps.inm.models import MaterialBatch mio:MIO = item.mio belong_dept = mio.belong_dept @@ -75,6 +72,10 @@ def do_out(item: MIOItem, is_reverse: bool = False): xcount:str = al[2] defect:Defect = al[3] + state = WMaterial.WM_OK + if defect and defect.okcate in [Defect.DEFECT_NOTOK]: + state = WMaterial.WM_NOTOK + xbatches.append(xbatch) if xcount <= 0: raise ParseError("存在非正数!") @@ -82,13 +83,13 @@ def do_out(item: MIOItem, is_reverse: bool = False): if not is_zhj: try: mb = MaterialBatch.objects.get( - material=xmaterial, - warehouse=item.warehouse, + material=xmaterial, + warehouse=item.warehouse, batch=xbatch, - state=WMaterial.WM_OK, + state=state, defect=defect ) - except (MaterialBatch.DoesNotExist, MaterialBatch.MultipleObjectsReturned) as e: + except (MaterialBatch.DoesNotExist, MaterialBatch.MultipleObjectsReturned) as e: raise ParseError(f"{str(xmaterial)}批次{xbatch}错误!{e}") mb.count = mb.count - xcount if mb.count < 0: @@ -100,8 +101,8 @@ def do_out(item: MIOItem, is_reverse: bool = False): # 领到车间库存(或工段) wm, new_create = WMaterial.objects.get_or_create( batch=xbatch, material=xmaterial, - belong_dept=belong_dept, mgroup=mgroup, - state=WMaterial.WM_OK, defect=defect) + belong_dept=belong_dept, mgroup=mgroup, + state=state, defect=defect) if new_create: wm.create_by = do_user wm.batch_ofrom = mb.batch if mb else None @@ -175,19 +176,23 @@ def do_in(item: MIOItem): xmaterial, xbatch, xcount, defect, xwm = al if xcount <= 0: raise ParseError("存在非正数!") - + + state = WMaterial.WM_OK + if defect and defect.okcate in [Defect.DEFECT_NOTOK]: + state = WMaterial.WM_NOTOK + xbatchs.append(xbatch) if xmaterial.into_wm: if xwm: wm = xwm else: wm_qs = WMaterial.objects.filter( - batch=xbatch, - material=xmaterial, - belong_dept=belong_dept, + batch=xbatch, + material=xmaterial, + belong_dept=belong_dept, mgroup=mgroup, - defect=defect, - state=WMaterial.WM_OK) + defect=defect, + state=state) count_x = wm_qs.count() if count_x == 1: wm = wm_qs.first() @@ -216,10 +221,10 @@ def do_in(item: MIOItem): # 增加mb if not is_zhj: mb, _ = MaterialBatch.objects.get_or_create( - material=xmaterial, - warehouse=item.warehouse, + material=xmaterial, + warehouse=item.warehouse, batch=xbatch, - state=WMaterial.WM_OK, + state=state, defect=defect, defaults={ "count": 0,