feat: 生产入库和领料支持b类合格品
This commit is contained in:
parent
a2cba2128f
commit
da69e654bc
|
@ -18,6 +18,7 @@ def do_out(item: MIOItem):
|
|||
"""
|
||||
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
|
||||
|
@ -26,6 +27,16 @@ def do_out(item: MIOItem):
|
|||
material:Material = item.material
|
||||
if material.into_wm is False: # 用于混料的原料不与车间库存交互, 这个是配置项目
|
||||
return
|
||||
|
||||
# 获取defect
|
||||
defect:Defect = None
|
||||
if item.wm and item.mb:
|
||||
raise ParseError("车间和仓库库存不能同时存在")
|
||||
if item.wm:
|
||||
defect = item.wm.defect
|
||||
elif item.mb:
|
||||
defect = item.mb.defect
|
||||
|
||||
action_list = []
|
||||
mias = MIOItemA.objects.filter(mioitem=item)
|
||||
is_zhj = False # 是否组合件领料
|
||||
|
@ -35,16 +46,18 @@ def do_out(item: MIOItem):
|
|||
for i in range(len(mias_list)):
|
||||
material, batch, rate = mias_list[i]
|
||||
new_count = rate * item.count # 假设 item.count 存在
|
||||
action_list.append([material, batch, new_count])
|
||||
action_list.append([material, batch, new_count, None])
|
||||
else:
|
||||
action_list = [[item.material, item.batch, item.count]]
|
||||
action_list = [[item.material, item.batch, item.count, defect]]
|
||||
|
||||
if is_zhj:
|
||||
try:
|
||||
mb = MaterialBatch.objects.get(
|
||||
material=item.material,
|
||||
warehouse=item.warehouse,
|
||||
batch=item.batch
|
||||
batch=item.batch,
|
||||
state=WMaterial.WM_OK,
|
||||
defect=None
|
||||
)
|
||||
except (MaterialBatch.DoesNotExist, MaterialBatch.MultipleObjectsReturned) as e:
|
||||
raise ParseError(f"组合件批次错误!{e}")
|
||||
|
@ -64,6 +77,8 @@ def do_out(item: MIOItem):
|
|||
xmaterial:Material = al[0]
|
||||
xbatch:str = al[1]
|
||||
xcount:str = al[2]
|
||||
defect:Defect = al[3]
|
||||
|
||||
xbatches.append(xbatch)
|
||||
if xcount <= 0:
|
||||
raise ParseError("存在非正数!")
|
||||
|
@ -74,8 +89,8 @@ def do_out(item: MIOItem):
|
|||
material=xmaterial,
|
||||
warehouse=item.warehouse,
|
||||
batch=xbatch,
|
||||
state=10,
|
||||
defect=None
|
||||
state=WMaterial.WM_OK,
|
||||
defect=defect
|
||||
)
|
||||
except (MaterialBatch.DoesNotExist, MaterialBatch.MultipleObjectsReturned) as e:
|
||||
raise ParseError(f"批次错误!{e}")
|
||||
|
@ -87,9 +102,10 @@ def do_out(item: MIOItem):
|
|||
|
||||
|
||||
# 领到车间库存(或工段)
|
||||
wm, new_create = WMaterial.objects.get_or_create(batch=xbatch, material=xmaterial,
|
||||
belong_dept=belong_dept, mgroup=mgroup,
|
||||
state=WMaterial.WM_OK)
|
||||
wm, new_create = WMaterial.objects.get_or_create(
|
||||
batch=xbatch, material=xmaterial,
|
||||
belong_dept=belong_dept, mgroup=mgroup,
|
||||
state=WMaterial.WM_OK, defect=defect)
|
||||
if new_create:
|
||||
wm.create_by = do_user
|
||||
wm.batch_ofrom = mb.batch if mb else None
|
||||
|
@ -118,8 +134,9 @@ def do_in(item: MIOItem):
|
|||
生产入库后更新车间物料
|
||||
"""
|
||||
mio = item.mio
|
||||
if item.wm and item.wm.defect is not None:
|
||||
raise ParseError("不合格物料无法入库")
|
||||
wmin:WMaterial = item.wm
|
||||
if wmin and wmin.state != WMaterial.WM_OK:
|
||||
raise ParseError("非合格物料无法入库")
|
||||
belong_dept = mio.belong_dept
|
||||
mgroup = mio.mgroup
|
||||
do_user = mio.do_user
|
||||
|
@ -129,15 +146,25 @@ def do_in(item: MIOItem):
|
|||
action_list = []
|
||||
mias = MIOItemA.objects.filter(mioitem=item)
|
||||
is_zhj = False # 是否组合件入仓库
|
||||
|
||||
# 获取defect
|
||||
defect:Defect = None
|
||||
if item.wm and item.mb:
|
||||
raise ParseError("车间和仓库库存不能同时存在")
|
||||
if item.wm:
|
||||
defect = item.wm.defect
|
||||
elif item.mb:
|
||||
defect = item.mb.defect
|
||||
|
||||
if mias.exists():
|
||||
is_zhj = True
|
||||
mias_list = mias.values_list('material', 'batch', 'rate')
|
||||
for i in mias_list:
|
||||
material, batch, rate = i
|
||||
new_count = rate * item.count # 假设 item.count 存在
|
||||
action_list.append([material, batch, new_count])
|
||||
action_list.append([material, batch, new_count, None])
|
||||
else:
|
||||
action_list = [[item.material, item.batch, item.count]]
|
||||
action_list = [[item.material, item.batch, item.count, defect]]
|
||||
|
||||
production_dept = None
|
||||
|
||||
|
@ -145,16 +172,18 @@ def do_in(item: MIOItem):
|
|||
if is_zhj:
|
||||
xbatchs = [item.batch]
|
||||
for al in action_list:
|
||||
xmaterial, xbatch, xcount = al
|
||||
xmaterial, xbatch, xcount, defect = al
|
||||
if xcount <= 0:
|
||||
raise ParseError("存在非正数!")
|
||||
|
||||
xbatchs.append(xbatch)
|
||||
# 扣减车间库存
|
||||
|
||||
wm_qs = WMaterial.objects.filter(
|
||||
batch=xbatch,
|
||||
material=xmaterial,
|
||||
belong_dept=belong_dept,
|
||||
mgroup=mgroup,
|
||||
mgroup=mgroup,
|
||||
defect=defect,
|
||||
state=WMaterial.WM_OK)
|
||||
count_x = wm_qs.count()
|
||||
if count_x == 1:
|
||||
|
@ -165,6 +194,8 @@ def do_in(item: MIOItem):
|
|||
else:
|
||||
raise ParseError(
|
||||
f'{str(xmaterial)}-{xbatch}-存在多个相同批次!')
|
||||
|
||||
# 扣减车间库存
|
||||
new_count = wm.count - xcount
|
||||
if new_count >= 0:
|
||||
wm.count = new_count
|
||||
|
@ -184,8 +215,8 @@ def do_in(item: MIOItem):
|
|||
material=xmaterial,
|
||||
warehouse=item.warehouse,
|
||||
batch=xbatch,
|
||||
state=10,
|
||||
defect=None,
|
||||
state=WMaterial.WM_OK,
|
||||
defect=defect,
|
||||
defaults={
|
||||
"count": 0,
|
||||
"batch_ofrom": wm.batch_ofrom,
|
||||
|
@ -212,6 +243,8 @@ def do_in(item: MIOItem):
|
|||
material=item.material,
|
||||
warehouse=item.warehouse,
|
||||
batch=item.batch,
|
||||
defect=None,
|
||||
state=WMaterial.WM_OK,
|
||||
defaults={"count": 0, "production_dept": production_dept}
|
||||
)
|
||||
if not is_created:
|
||||
|
|
Loading…
Reference in New Issue