feat: MaterialBatch 添加字段以支持追踪原料批次3
This commit is contained in:
parent
27c646e6df
commit
90e699155c
|
@ -80,8 +80,8 @@ class InmService:
|
|||
out = -1
|
||||
默认使用count字段做加减
|
||||
"""
|
||||
if type is None or belong_dept is None:
|
||||
mio = i.mio
|
||||
if type is None or belong_dept is None:
|
||||
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
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue