From 94bfda45e927e4e5504a436845fd69de92fa22f8 Mon Sep 17 00:00:00 2001 From: Jacopo Cappellato Date: Mon, 24 Jul 2017 09:09:38 +0000 Subject: [PATCH] Fixed: MRP generates duplicate requirements when items are initially under minimum quantity and have with pending approved purchase orders. (OFBIZ-9526) With this change the requirements to replenish the inventory up to the minimum stock quantity is generated, if needed, only when the first demand event is processed or at the end. Thanks: Amit Gadaley for the help in recreating the issue and testing the fix. git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1802766 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/ofbiz/manufacturing/mrp/MrpServices.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/applications/manufacturing/src/main/java/org/apache/ofbiz/manufacturing/mrp/MrpServices.java b/applications/manufacturing/src/main/java/org/apache/ofbiz/manufacturing/mrp/MrpServices.java index 6274c826ab..fbb07f2850 100644 --- a/applications/manufacturing/src/main/java/org/apache/ofbiz/manufacturing/mrp/MrpServices.java +++ b/applications/manufacturing/src/main/java/org/apache/ofbiz/manufacturing/mrp/MrpServices.java @@ -688,8 +688,12 @@ public class MrpServices { bomLevelWithNoEvent = 0; oldProductId = ""; + int eventCount = 0; for (GenericValue inventoryEventForMRP : listInventoryEventForMRP) { + eventCount++; + productId = inventoryEventForMRP.getString("productId"); + boolean isLastEvent = (eventCount == listInventoryEventForMRP.size() || !productId.equals(listInventoryEventForMRP.get(eventCount).getString("productId"))); eventQuantity = inventoryEventForMRP.getBigDecimal("quantity"); if (!productId.equals(oldProductId)) { @@ -746,7 +750,7 @@ public class MrpServices { } stockTmp = stockTmp.add(eventQuantity); - if (stockTmp.compareTo(minimumStock) < 0) { + if (stockTmp.compareTo(minimumStock) < 0 && (eventQuantity.compareTo(BigDecimal.ZERO) < 0 || isLastEvent)) { // No need to create a supply event/requirement if the current event is not a demand and there are other events to process BigDecimal qtyToStock = minimumStock.subtract(stockTmp); //need to buy or build the product as we have not enough stock eventDate = inventoryEventForMRP.getTimestamp("eventDate");