diff --git a/apps/inm/services.py b/apps/inm/services.py index 2f130a26..6865bb0b 100644 --- a/apps/inm/services.py +++ b/apps/inm/services.py @@ -56,7 +56,10 @@ class InmService: mb.count = mb.count - i.count if mb.count < 0: raise ParseError('批次库存不足,操作失败') - mb.save() + elif mb.count == 0: + mb.delete() + else: + mb.save() else: raise ParseError('不支持的操作') material_count = MaterialBatch.objects.filter( diff --git a/apps/wpm/services.py b/apps/wpm/services.py index c9f9f46f..35405228 100644 --- a/apps/wpm/services.py +++ b/apps/wpm/services.py @@ -167,7 +167,10 @@ 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 - material_has.save() + if material_has.count == 0: + material_has.delete() + else: + material_has.save() if material_out: # 需要入车间库存 # 有多个产物的情况 if material_out.brothers and Mlogb.objects.filter(mlog=mlog).exists(): @@ -214,7 +217,10 @@ 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('车间库存不足, 产物无法回退') - wmaterial.save() + 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={ 'batch': mlog.batch, 'material': material_out, 'belong_dept': belong_dept @@ -222,7 +228,10 @@ 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('车间库存不足, 产物无法回退') - wmaterial.save() + elif wmaterial.count == 0: + wmaterial.delete() + else: + wmaterial.save() mlog.submit_time = None mlog.submit_user = None mlog.save() @@ -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()