svn commit: r1802766 - /ofbiz/ofbiz-framework/trunk/applications/manufacturing/src/main/java/org/apache/ofbiz/manufacturing/mrp/MrpServices.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1802766 - /ofbiz/ofbiz-framework/trunk/applications/manufacturing/src/main/java/org/apache/ofbiz/manufacturing/mrp/MrpServices.java

jacopoc
Author: jacopoc
Date: Mon Jul 24 09:09:38 2017
New Revision: 1802766

URL: http://svn.apache.org/viewvc?rev=1802766&view=rev
Log:
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.

Modified:
    ofbiz/ofbiz-framework/trunk/applications/manufacturing/src/main/java/org/apache/ofbiz/manufacturing/mrp/MrpServices.java

Modified: ofbiz/ofbiz-framework/trunk/applications/manufacturing/src/main/java/org/apache/ofbiz/manufacturing/mrp/MrpServices.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/manufacturing/src/main/java/org/apache/ofbiz/manufacturing/mrp/MrpServices.java?rev=1802766&r1=1802765&r2=1802766&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/manufacturing/src/main/java/org/apache/ofbiz/manufacturing/mrp/MrpServices.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/manufacturing/src/main/java/org/apache/ofbiz/manufacturing/mrp/MrpServices.java Mon Jul 24 09:09:38 2017
@@ -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");