From 90e699155cc64564e3ac1269ec6fa03a0ba80eb4 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Wed, 13 Nov 2024 18:16:02 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20MaterialBatch=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E4=BB=A5=E6=94=AF=E6=8C=81=E8=BF=BD=E8=B8=AA?= =?UTF-8?q?=E5=8E=9F=E6=96=99=E6=89=B9=E6=AC=A13?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/inm/services.py | 10 ++++++---- apps/wpm/services.py | 21 ++++++++++++--------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/apps/inm/services.py b/apps/inm/services.py index 8dcc0ee6..c4d756a4 100644 --- a/apps/inm/services.py +++ b/apps/inm/services.py @@ -80,8 +80,8 @@ class InmService: out = -1 默认使用count字段做加减 """ + mio = i.mio if type is None or belong_dept is None: - mio = i.mio type = mio.type belong_dept = mio.belong_dept material = i.material @@ -97,13 +97,15 @@ class InmService: batch=i.batch, defaults=ddict ) - if mb.batch_ofrom is None and material.type in [Material.MA_TYPE_GOOD, Material.MA_TYPE_GOOD]: + if (mio.type in [MIO.MIO_TYPE_DO_IN, MIO.MIO_TYPE_OTHER_IN] and + mb.batch_ofrom is None and + material.type in [Material.MA_TYPE_GOOD, Material.MA_TYPE_HALFGOOD]): from apps.wpm.models import WMaterial wm_qs = WMaterial.objects.filter(material=material, batch=i.batch) - batchs_count = wm_qs.values_list('batch_ofrom', flat=True).distinct().count() + batchs_count = wm_qs.exclude(batch_ofrom=None).values_list('batch_ofrom', flat=True).distinct().count() if batchs_count > 1: raise ParseError("半成品/成品同批次号的原料批次应相同!") - if batchs_count == 1: + elif batchs_count == 1: wm = wm_qs.first() mb.batch_ofrom = wm.batch_ofrom mb.material_ofrom = wm.material_ofrom diff --git a/apps/wpm/services.py b/apps/wpm/services.py index 5dfa3879..51da55d2 100644 --- a/apps/wpm/services.py +++ b/apps/wpm/services.py @@ -155,19 +155,22 @@ def do_out(mio: MIO): wm, new_create = WMaterial.objects.get_or_create(batch=xbatch, material=xmaterial, belong_dept=belong_dept, mgroup=mgroup, state=WMaterial.WM_OK, - defaults={ - "batch": xbatch, - "material": xmaterial, - "count": xcount, - "create_by": do_user, - "belong_dept": belong_dept, - "mgroup": mgroup, - "state": WMaterial.WM_OK, - }) + defaults=ddict) if not new_create: wm.count = wm.count + item.count wm.update_by = do_user wm.save() + if wm.batch_ofrom is None and wm.material.type in [Material.MA_TYPE_HALFGOOD, Material.MA_TYPE_GOOD]: + from apps.inm.models import MaterialBatch + mb_qs = MaterialBatch.objects.filter(material=wm.material, batch=wm.batch) + batchs_count = mb_qs.exclude(batch_ofrom=None).values_list('batch_ofrom', flat=True).distinct().count() + if batchs_count > 1: + raise ParseError("半成品/成品同批次号的原料批次应相同!") + elif batchs_count == 1: + mb = mb_qs.first() + wm.batch_ofrom = mb.batch_ofrom + wm.material_ofrom = mb.material_ofrom + wm.save() def do_in(mio: MIO):