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,