diff --git a/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/factory/RemoteWmsFallbackFactory.java b/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/factory/RemoteWmsFallbackFactory.java index 19b01814a..e187b6c4a 100644 --- a/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/factory/RemoteWmsFallbackFactory.java +++ b/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/factory/RemoteWmsFallbackFactory.java @@ -85,7 +85,7 @@ public class RemoteWmsFallbackFactory implements FallbackFactory 库存,扣全部库存 - detail.setMaterialInventoryId(materialInventory.getMaterialInventoryId()); - detail.setStorageLocationId(materialInventory.getStorageLocationId()); - detail.setStorageLocationName(materialInventory.getStorageLocationName()); - detail.setStorageLocationCode(materialInventory.getStorageLocationCode()); - detail.setStorageSectionId(materialInventory.getStorageSectionId()); - detail.setStorageName(materialInventory.getStorageName()); - detail.setStorageCode(materialInventory.getStorageCode()); - detail.setInventoryQuantity(materialInventory.getInventoryQuantity()); - detail.setAllocationQuantity(deductQuantity); - materialDetailList2.add(detail); - // 更新剩余计划数量 - remainingQuantity = remainingQuantity.subtract(deductQuantity); + // 当前物料的可用库存 + BigDecimal availableStock = materialInventory.getAllocationQuantity(); + // 如果当前物料没有库存,跳过 + if (availableStock == null || availableStock.compareTo(BigDecimal.ZERO) <= 0) { + continue; } + if (availableStock.compareTo(remainingQuantity) < 0) { + throw new RuntimeException( + String.format("可用库存不足,计划数量:%s,当前可用库存:%s", + remainingQuantity, availableStock) + ); + } +// detail.setMaterialInventoryId(materialInventory.getMaterialInventoryId()); + detail.setStorageLocationId(materialInventory.getStorageLocationId()); + detail.setStorageLocationName(materialInventory.getStorageLocationName()); + detail.setStorageLocationCode(materialInventory.getStorageLocationCode()); + detail.setStorageSectionId(materialInventory.getStorageSectionId()); + detail.setStorageName(materialInventory.getStorageName()); + detail.setStorageCode(materialInventory.getStorageCode()); + detail.setInventoryQuantity(materialInventory.getInventoryQuantity()); + detail.setAllocationQuantity(remainingQuantity); + materialDetailList2.add(detail); } stockOutOrderD.setMaterialDetailList(materialDetailList2); StockOutOrderDO assembleStockOutOrderDO = assembleParamByOutOrder(stockOutOrderD);