feat: MaterialBatch 添加字段以支持追踪原料批次3

This commit is contained in:
caoqianming 2024-11-13 18:16:02 +08:00
parent 27c646e6df
commit 90e699155c
2 changed files with 18 additions and 13 deletions

View File

@ -80,8 +80,8 @@ class InmService:
out = -1 out = -1
默认使用count字段做加减 默认使用count字段做加减
""" """
mio = i.mio
if type is None or belong_dept is None: if type is None or belong_dept is None:
mio = i.mio
type = mio.type type = mio.type
belong_dept = mio.belong_dept belong_dept = mio.belong_dept
material = i.material material = i.material
@ -97,13 +97,15 @@ class InmService:
batch=i.batch, batch=i.batch,
defaults=ddict 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 from apps.wpm.models import WMaterial
wm_qs = WMaterial.objects.filter(material=material, batch=i.batch) 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: if batchs_count > 1:
raise ParseError("半成品/成品同批次号的原料批次应相同!") raise ParseError("半成品/成品同批次号的原料批次应相同!")
if batchs_count == 1: elif batchs_count == 1:
wm = wm_qs.first() wm = wm_qs.first()
mb.batch_ofrom = wm.batch_ofrom mb.batch_ofrom = wm.batch_ofrom
mb.material_ofrom = wm.material_ofrom mb.material_ofrom = wm.material_ofrom

View File

@ -155,19 +155,22 @@ def do_out(mio: MIO):
wm, new_create = WMaterial.objects.get_or_create(batch=xbatch, material=xmaterial, wm, new_create = WMaterial.objects.get_or_create(batch=xbatch, material=xmaterial,
belong_dept=belong_dept, mgroup=mgroup, belong_dept=belong_dept, mgroup=mgroup,
state=WMaterial.WM_OK, state=WMaterial.WM_OK,
defaults={ defaults=ddict)
"batch": xbatch,
"material": xmaterial,
"count": xcount,
"create_by": do_user,
"belong_dept": belong_dept,
"mgroup": mgroup,
"state": WMaterial.WM_OK,
})
if not new_create: if not new_create:
wm.count = wm.count + item.count wm.count = wm.count + item.count
wm.update_by = do_user wm.update_by = do_user
wm.save() 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): def do_in(mio: MIO):