feat: 库存减到0时删除该记录

This commit is contained in:
caoqianming 2024-01-11 17:56:00 +08:00
parent 90e0513db6
commit 7ca12228e2
2 changed files with 18 additions and 4 deletions

View File

@ -56,6 +56,9 @@ class InmService:
mb.count = mb.count - i.count
if mb.count < 0:
raise ParseError('批次库存不足,操作失败')
elif mb.count == 0:
mb.delete()
else:
mb.save()
else:
raise ParseError('不支持的操作')

View File

@ -167,6 +167,9 @@ def mlog_submit(mlog: Mlog, user: User, now: Union[datetime.datetime, None]):
f'{str(material_in)}-{mlog.batch}-该批次车间库存不足!')
else:
material_has.count = material_has.count - mlog.count_use
if material_has.count == 0:
material_has.delete()
else:
material_has.save()
if material_out: # 需要入车间库存
# 有多个产物的情况
@ -214,6 +217,9 @@ def mlog_revert(mlog: Mlog, user: User, now: Union[datetime.datetime, None]):
wmaterial.count = wmaterial.count - item.count_ok
if wmaterial.count < 0:
raise ParseError('车间库存不足, 产物无法回退')
elif wmaterial.count == 0:
wmaterial.delete()
else:
wmaterial.save()
else:
wmaterial, _ = WMaterial.objects.get_or_create(batch=mlog.batch, material=material_out, belong_dept=belong_dept, defaults={
@ -222,6 +228,9 @@ def mlog_revert(mlog: Mlog, user: User, now: Union[datetime.datetime, None]):
wmaterial.count = wmaterial.count - mlog.count_ok
if wmaterial.count < 0:
raise ParseError('车间库存不足, 产物无法回退')
elif wmaterial.count == 0:
wmaterial.delete()
else:
wmaterial.save()
mlog.submit_time = None
mlog.submit_user = None
@ -262,6 +271,8 @@ def handover_submit(handover: Handover, user: User, now: Union[datetime.datetime
count_x = wm.count - handover.count
if count_x < 0:
raise ParseError('车间库存不足!')
elif count_x == 0:
wm.delete()
else:
wm.count = count_x
wm.save()