Author: mbrohl
Date: Sat Dec 16 14:00:24 2017 New Revision: 1818409 URL: http://svn.apache.org/viewvc?rev=1818409&view=rev Log: Improved: General refactoring and code improvements, package org.apache.ofbiz.product.inventory. (OFBIZ-10072) Thanks Julian Leichert for reporting and providing the patches. Modified: ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/inventory/InventoryServices.java ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/inventory/InventoryWorker.java Modified: ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/inventory/InventoryServices.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/inventory/InventoryServices.java?rev=1818409&r1=1818408&r2=1818409&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/inventory/InventoryServices.java (original) +++ ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/inventory/InventoryServices.java Sat Dec 16 14:00:24 2017 @@ -75,12 +75,12 @@ public class InventoryServices { try { inventoryItem = EntityQuery.use(delegator).from("InventoryItem").where("inventoryItemId", inventoryItemId).queryOne(); } catch (GenericEntityException e) { - return ServiceUtil.returnError(UtilProperties.getMessage(resource, + return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ProductNotFindInventoryItemWithId", locale) + inventoryItemId); } if (inventoryItem == null) { - return ServiceUtil.returnError(UtilProperties.getMessage(resource, + return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ProductNotFindInventoryItemWithId", locale) + inventoryItemId); } @@ -93,7 +93,7 @@ public class InventoryServices { BigDecimal qoh = inventoryItem.getBigDecimal("quantityOnHandTotal"); if (atp == null) { - return ServiceUtil.returnError(UtilProperties.getMessage(resource, + return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ProductInventoryItemATPNotAvailable", UtilMisc.toMap("inventoryItemId", inventoryItem.getString("inventoryItemId")), locale)); } @@ -103,7 +103,7 @@ public class InventoryServices { // first make sure we have enough to cover the request transfer amount if (xferQty.compareTo(atp) > 0) { - return ServiceUtil.returnError(UtilProperties.getMessage(resource, + return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ProductInventoryItemATPIsNotSufficient", UtilMisc.toMap("inventoryItemId", inventoryItem.getString("inventoryItemId"), "atp", atp, "xferQty", xferQty), locale)); @@ -142,19 +142,19 @@ public class InventoryServices { try { Map<String, Object> resultNew = dctx.getDispatcher().runSync("createInventoryItemDetail", createNewDetailMap); if (ServiceUtil.isError(resultNew)) { - return ServiceUtil.returnError(UtilProperties.getMessage(resource, - "ProductInventoryItemDetailCreateProblem", + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductInventoryItemDetailCreateProblem", UtilMisc.toMap("errorString", ""), locale), null, null, resultNew); } Map<String, Object> resultUpdate = dctx.getDispatcher().runSync("createInventoryItemDetail", createUpdateDetailMap); if (ServiceUtil.isError(resultUpdate)) { - return ServiceUtil.returnError(UtilProperties.getMessage(resource, - "ProductInventoryItemDetailCreateProblem", + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductInventoryItemDetailCreateProblem", UtilMisc.toMap("errorString", ""), locale), null, null, resultUpdate); } } catch (GenericServiceException e1) { - return ServiceUtil.returnError(UtilProperties.getMessage(resource, - "ProductInventoryItemDetailCreateProblem", + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductInventoryItemDetailCreateProblem", UtilMisc.toMap("errorString", e1.getMessage()), locale)); } } else { @@ -162,7 +162,7 @@ public class InventoryServices { } } else if ("SERIALIZED_INV_ITEM".equals(inventoryType)) { if (!"INV_AVAILABLE".equals(inventoryItem.getString("statusId"))) { - return ServiceUtil.returnError(UtilProperties.getMessage(resource, + return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ProductSerializedInventoryNotAvailable", locale)); } } @@ -181,13 +181,13 @@ public class InventoryServices { try { Map<String, Object> result = dctx.getDispatcher().runSync("createInventoryItemDetail", createDetailMap); if (ServiceUtil.isError(result)) { - return ServiceUtil.returnError(UtilProperties.getMessage(resource, - "ProductInventoryItemDetailCreateProblem", + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductInventoryItemDetailCreateProblem", UtilMisc.toMap("errorString", ""), locale), null, null, result); } } catch (GenericServiceException e1) { - return ServiceUtil.returnError(UtilProperties.getMessage(resource, - "ProductInventoryItemDetailCreateProblem", + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductInventoryItemDetailCreateProblem", UtilMisc.toMap("errorString", e1.getMessage()), locale)); } } @@ -208,8 +208,8 @@ public class InventoryServices { return results; } catch (GenericEntityException e) { - return ServiceUtil.returnError(UtilProperties.getMessage(resource, - "ProductInventoryItemStoreProblem", + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductInventoryItemStoreProblem", UtilMisc.toMap("errorString", e.getMessage()), locale)); } } @@ -229,14 +229,14 @@ public class InventoryServices { inventoryItem = inventoryTransfer.getRelatedOne("InventoryItem", false); destinationFacility = inventoryTransfer.getRelatedOne("ToFacility", false); } catch (GenericEntityException e) { - return ServiceUtil.returnError(UtilProperties.getMessage(resource, - "ProductInventoryItemLookupProblem", + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductInventoryItemLookupProblem", UtilMisc.toMap("errorString", e.getMessage()), locale)); } if (inventoryItem == null) { - return ServiceUtil.returnError(UtilProperties.getMessage(resource, - "ProductInventoryItemLookupProblem", + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductInventoryItemLookupProblem", UtilMisc.toMap("errorString", ""), locale)); } @@ -260,20 +260,20 @@ public class InventoryServices { try { Map<String, Object> result = dctx.getDispatcher().runSync("createInventoryItemDetail", createDetailMap); if (ServiceUtil.isError(result)) { - return ServiceUtil.returnError(UtilProperties.getMessage(resource, - "ProductInventoryItemDetailCreateProblem", + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductInventoryItemDetailCreateProblem", UtilMisc.toMap("errorString", ""), locale), null, null, result); } } catch (GenericServiceException e1) { - return ServiceUtil.returnError(UtilProperties.getMessage(resource, - "ProductInventoryItemDetailCreateProblem", + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductInventoryItemDetailCreateProblem", UtilMisc.toMap("errorString", e1.getMessage()), locale)); } try { inventoryItem.refresh(); } catch (GenericEntityException e) { - return ServiceUtil.returnError(UtilProperties.getMessage(resource, - "ProductInventoryItemRefreshProblem", + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductInventoryItemRefreshProblem", UtilMisc.toMap("errorString", e.getMessage()), locale)); } } @@ -303,13 +303,13 @@ public class InventoryServices { try { Map<String, Object> result = dctx.getDispatcher().runSync("updateInventoryItem", updateInventoryItemMap); if (ServiceUtil.isError(result)) { - return ServiceUtil.returnError(UtilProperties.getMessage(resource, - "ProductInventoryItemStoreProblem", + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductInventoryItemStoreProblem", UtilMisc.toMap("errorString", ""), locale), null, null, result); } } catch (GenericServiceException exc) { - return ServiceUtil.returnError(UtilProperties.getMessage(resource, - "ProductInventoryItemStoreProblem", + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductInventoryItemStoreProblem", UtilMisc.toMap("errorString", exc.getMessage()), locale)); } @@ -320,8 +320,8 @@ public class InventoryServices { try { inventoryTransfer.store(); } catch (GenericEntityException e) { - return ServiceUtil.returnError(UtilProperties.getMessage(resource, - "ProductInventoryItemStoreProblem", + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductInventoryItemStoreProblem", UtilMisc.toMap("errorString", e.getMessage()), locale)); } @@ -339,20 +339,20 @@ public class InventoryServices { try { inventoryTransfer = EntityQuery.use(delegator).from("InventoryTransfer").where("inventoryTransferId", inventoryTransferId).queryOne(); if (UtilValidate.isEmpty(inventoryTransfer)) { - return ServiceUtil.returnError(UtilProperties.getMessage(resource, - "ProductInventoryItemTransferNotFound", + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductInventoryItemTransferNotFound", UtilMisc.toMap("inventoryTransferId", inventoryTransferId), locale)); } inventoryItem = inventoryTransfer.getRelatedOne("InventoryItem", false); } catch (GenericEntityException e) { - return ServiceUtil.returnError(UtilProperties.getMessage(resource, - "ProductInventoryItemLookupProblem", + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductInventoryItemLookupProblem", UtilMisc.toMap("errorString", e.getMessage()), locale)); } if (inventoryItem == null) { - return ServiceUtil.returnError(UtilProperties.getMessage(resource, - "ProductInventoryItemLookupProblem", + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductInventoryItemLookupProblem", UtilMisc.toMap("errorString", ""), locale)); } @@ -369,13 +369,13 @@ public class InventoryServices { try { Map<String, Object> result = dctx.getDispatcher().runSync("createInventoryItemDetail", createDetailMap); if (ServiceUtil.isError(result)) { - return ServiceUtil.returnError(UtilProperties.getMessage(resource, - "ProductInventoryItemDetailCreateProblem", + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductInventoryItemDetailCreateProblem", UtilMisc.toMap("errorString", ""), locale), null, null, result); } } catch (GenericServiceException e1) { - return ServiceUtil.returnError(UtilProperties.getMessage(resource, - "ProductInventoryItemDetailCreateProblem", + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductInventoryItemDetailCreateProblem", UtilMisc.toMap("errorString", e1.getMessage()), locale)); } } else if ("SERIALIZED_INV_ITEM".equals(inventoryType)) { @@ -384,8 +384,8 @@ public class InventoryServices { try { inventoryItem.store(); } catch (GenericEntityException e) { - return ServiceUtil.returnError(UtilProperties.getMessage(resource, - "ProductInventoryItemStoreProblem", + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductInventoryItemStoreProblem", UtilMisc.toMap("errorString", e.getMessage()), locale)); } } @@ -397,8 +397,8 @@ public class InventoryServices { try { inventoryTransfer.store(); } catch (GenericEntityException e) { - return ServiceUtil.returnError(UtilProperties.getMessage(resource, - "ProductInventoryItemStoreProblem", + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductInventoryItemStoreProblem", UtilMisc.toMap("errorString", e.getMessage()), locale)); } @@ -411,8 +411,8 @@ public class InventoryServices { LocalDispatcher dispatcher = dctx.getDispatcher(); GenericValue userLogin = (GenericValue) context.get("userLogin"); Locale locale = (Locale) context.get("locale"); - Map<String, Map<String, Timestamp>> ordersToUpdate = new HashMap<String, Map<String,Timestamp>>(); - Map<String, Map<String, Timestamp>> ordersToCancel = new HashMap<String, Map<String,Timestamp>>(); + Map<String, Map<String, Timestamp>> ordersToUpdate = new HashMap<>(); + Map<String, Map<String, Timestamp>> ordersToCancel = new HashMap<>(); // find all inventory items w/ a negative ATP List<GenericValue> inventoryItems = null; @@ -420,7 +420,7 @@ public class InventoryServices { inventoryItems = EntityQuery.use(delegator).from("InventoryItem").where(EntityCondition.makeCondition("availableToPromiseTotal", EntityOperator.LESS_THAN, BigDecimal.ZERO)).queryList(); } catch (GenericEntityException e) { Debug.logError(e, "Trouble getting inventory items", module); - return ServiceUtil.returnError(UtilProperties.getMessage(resource, + return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ProductPriceCannotRetrieveInventoryItem", locale)); } @@ -435,7 +435,7 @@ public class InventoryServices { // get the incomming shipment information for the item List<GenericValue> shipmentAndItems = null; try { - List<EntityExpr> exprs = new ArrayList<EntityExpr>(); + List<EntityExpr> exprs = new ArrayList<>(); exprs.add(EntityCondition.makeCondition("productId", EntityOperator.EQUALS, inventoryItem.get("productId"))); exprs.add(EntityCondition.makeCondition("destinationFacilityId", EntityOperator.EQUALS, inventoryItem.get("facilityId"))); exprs.add(EntityCondition.makeCondition("statusId", EntityOperator.NOT_EQUAL, "SHIPMENT_DELIVERED")); @@ -444,7 +444,7 @@ public class InventoryServices { shipmentAndItems = EntityQuery.use(delegator).from("ShipmentAndItem").where(EntityCondition.makeCondition(exprs, EntityOperator.AND)).orderBy("estimatedArrivalDate").queryList(); } catch (GenericEntityException e) { Debug.logError(e, "Problem getting ShipmentAndItem records", module); - return ServiceUtil.returnError(UtilProperties.getMessage(resource, + return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ProductPriceCannotRetrieveShipmentAndItem", locale)); } @@ -454,7 +454,7 @@ public class InventoryServices { reservations = inventoryItem.getRelated("OrderItemShipGrpInvRes", null, UtilMisc.toList("-reservedDatetime"), false); } catch (GenericEntityException e) { Debug.logError(e, "Problem getting related reservations", module); - return ServiceUtil.returnError(UtilProperties.getMessage(resource, + return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ProductPriceCannotRetrieveRelativeReservation", locale)); } @@ -519,7 +519,7 @@ public class InventoryServices { Debug.logInfo("We won't ship on time, getting notification info", module); Map<String, Timestamp> notifyItems = ordersToUpdate.get(orderId); if (notifyItems == null) { - notifyItems = new HashMap<String, Timestamp>(); + notifyItems = new HashMap<>(); } notifyItems.put(orderItemSeqId, nextShipDate); ordersToUpdate.put(orderId, notifyItems); @@ -547,7 +547,7 @@ public class InventoryServices { Debug.logInfo("Flagging the item to auto-cancel", module); Map<String, Timestamp> cancelItems = ordersToCancel.get(orderId); if (cancelItems == null) { - cancelItems = new HashMap<String, Timestamp>(); + cancelItems = new HashMap<>(); } cancelItems.put(orderItemSeqId, farPastPromised); ordersToCancel.put(orderId, cancelItems); @@ -569,7 +569,7 @@ public class InventoryServices { } // all items to cancel will also be in the notify list so start with that - List<String> ordersToNotify = new LinkedList<String>(); + List<String> ordersToNotify = new LinkedList<>(); for (Map.Entry<String, Map<String, Timestamp>> entry: ordersToUpdate.entrySet()) { String orderId = entry.getKey(); Map<String, Timestamp> backOrderedItems = entry.getValue(); @@ -585,7 +585,7 @@ public class InventoryServices { } for (GenericValue orderItemShipGroup: orderItemShipGroups) { - List<GenericValue> orderItems = new LinkedList<GenericValue>(); + List<GenericValue> orderItems = new LinkedList<>(); List<GenericValue> orderItemShipGroupAssoc = null; try { orderItemShipGroupAssoc = EntityQuery.use(delegator).from("OrderItemShipGroupAssoc").where("shipGroupSeqId", orderItemShipGroup.get("shipGroupSeqId"), "orderId", orderId).queryList(); @@ -616,10 +616,10 @@ public class InventoryServices { // if there are none to cancel just create an empty map if (cancelItems == null) { - cancelItems = new HashMap<String, Timestamp>(); + cancelItems = new HashMap<>(); } - List<GenericValue> toBeStored = new LinkedList<GenericValue>(); + List<GenericValue> toBeStored = new LinkedList<>(); for (GenericValue orderItem: orderItems) { String orderItemSeqId = orderItem.getString("orderItemSeqId"); Timestamp shipDate = backOrderedItems.get(orderItemSeqId); @@ -752,10 +752,10 @@ public class InventoryServices { List<GenericValue> orderItems = UtilGenerics.checkList(context.get("orderItems")); String facilityId = (String) context.get("facilityId"); Locale locale = (Locale) context.get("locale"); - Map<String, BigDecimal> atpMap = new HashMap<String, BigDecimal>(); - Map<String, BigDecimal> qohMap = new HashMap<String, BigDecimal>(); - Map<String, BigDecimal> mktgPkgAtpMap = new HashMap<String, BigDecimal>(); - Map<String, BigDecimal> mktgPkgQohMap = new HashMap<String, BigDecimal>(); + Map<String, BigDecimal> atpMap = new HashMap<>(); + Map<String, BigDecimal> qohMap = new HashMap<>(); + Map<String, BigDecimal> mktgPkgAtpMap = new HashMap<>(); + Map<String, BigDecimal> mktgPkgQohMap = new HashMap<>(); Map<String, Object> results = ServiceUtil.returnSuccess(); // get a list of all available facilities for looping @@ -767,8 +767,8 @@ public class InventoryServices { facilities = EntityQuery.use(delegator).from("Facility").queryList(); } } catch (GenericEntityException e) { - return ServiceUtil.returnError(UtilProperties.getMessage(resource, - "ProductErrorFacilityIdNotFound", + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductErrorFacilityIdNotFound", UtilMisc.toMap("facilityId", facilityId), locale)); } @@ -776,14 +776,16 @@ public class InventoryServices { for (GenericValue orderItem: orderItems) { String productId = orderItem.getString("productId"); - if ((productId == null) || productId.equals("")) continue; + if ((productId == null) || productId.equals("")) { + continue; + } GenericValue product = null; try { product = orderItem.getRelatedOne("Product", true); } catch (GenericEntityException e) { Debug.logError(e, "Couldn't get product.", module); - return ServiceUtil.returnError(UtilProperties.getMessage(resource, + return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ProductProductNotFound", locale) + productId); } @@ -805,8 +807,8 @@ public class InventoryServices { invResult = dispatcher.runSync("getInventoryAvailableByFacility", UtilMisc.toMap("productId", productId, "facilityId", facility.getString("facilityId"))); } catch (GenericServiceException e) { Debug.logError(e, "Could not find inventory for facility " + facility.getString("facilityId"), module); - return ServiceUtil.returnError(UtilProperties.getMessage(resource, - "ProductInventoryNotAvailableForFacility", + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductInventoryNotAvailableForFacility", UtilMisc.toMap("facilityId", facility.getString("facilityId")), locale)); } @@ -814,14 +816,22 @@ public class InventoryServices { if (ServiceUtil.isSuccess(invResult)) { BigDecimal fatp = (BigDecimal) invResult.get("availableToPromiseTotal"); BigDecimal fqoh = (BigDecimal) invResult.get("quantityOnHandTotal"); - if (fatp != null) atp = atp.add(fatp); - if (fqoh != null) qoh = qoh.add(fqoh); + if (fatp != null) { + atp = atp.add(fatp); + } + if (fqoh != null) { + qoh = qoh.add(fqoh); + } } if (EntityTypeUtil.hasParentType(delegator, "ProductType", "productTypeId", product.getString("productTypeId"), "parentTypeId", "MARKETING_PKG") && ServiceUtil.isSuccess(mktgPkgInvResult)) { BigDecimal fatp = (BigDecimal) mktgPkgInvResult.get("availableToPromiseTotal"); BigDecimal fqoh = (BigDecimal) mktgPkgInvResult.get("quantityOnHandTotal"); - if (fatp != null) mktgPkgAtp = mktgPkgAtp.add(fatp); - if (fqoh != null) mktgPkgQoh = mktgPkgQoh.add(fqoh); + if (fatp != null) { + mktgPkgAtp = mktgPkgAtp.add(fatp); + } + if (fqoh != null) { + mktgPkgQoh = mktgPkgQoh.add(fqoh); + } } } @@ -848,8 +858,8 @@ public class InventoryServices { BigDecimal minimumStock = (BigDecimal)context.get("minimumStock"); String statusId = (String)context.get("statusId"); - Map<String, Object> result = new HashMap<String, Object>(); - Map<String, Object> resultOutput = new HashMap<String, Object>(); + Map<String, Object> result = new HashMap<>(); + Map<String, Object> resultOutput = new HashMap<>(); Map<String, String> contextInput = UtilMisc.toMap("productId", productId, "facilityId", facilityId, "statusId", statusId); GenericValue product = null; @@ -949,7 +959,7 @@ public class InventoryServices { productionUsageViewEntity.addAlias("WE", "workEffortTypeId"); productionUsageViewEntity.addAlias("II", "facilityId"); productionUsageViewEntity.addAlias("II", "productId"); - + // Make a query against the sales usage view entity EntityCondition cond = EntityCondition.makeCondition( UtilMisc.toList( @@ -960,9 +970,9 @@ public class InventoryServices { EntityCondition.makeCondition("orderDate", EntityOperator.GREATER_THAN_EQUAL_TO, checkTime) ), EntityOperator.AND); - + try (EntityListIterator salesUsageIt = EntityQuery.use(delegator).from(salesUsageViewEntity).where(cond).queryIterator()) { - + // Sum the sales usage quantities found BigDecimal salesUsageQuantity = BigDecimal.ZERO; GenericValue salesUsageItem = null; Modified: ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/inventory/InventoryWorker.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/inventory/InventoryWorker.java?rev=1818409&r1=1818408&r2=1818409&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/inventory/InventoryWorker.java (original) +++ ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/inventory/InventoryWorker.java Sat Dec 16 14:00:24 2017 @@ -81,18 +81,17 @@ public final class InventoryWorker { List<GenericValue> purchaseOrders = getOutstandingPurchaseOrders(productId, delegator); if (UtilValidate.isEmpty(purchaseOrders)) { return qty; - } else { - for (GenericValue nextOrder: purchaseOrders) { - if (nextOrder.get("quantity") != null) { - BigDecimal itemQuantity = nextOrder.getBigDecimal("quantity"); - BigDecimal cancelQuantity = BigDecimal.ZERO; - if (nextOrder.get("cancelQuantity") != null) { - cancelQuantity = nextOrder.getBigDecimal("cancelQuantity"); - } - itemQuantity = itemQuantity.subtract(cancelQuantity); - if (itemQuantity.compareTo(BigDecimal.ZERO) >= 0) { - qty = qty.add(itemQuantity); - } + } + for (GenericValue nextOrder : purchaseOrders) { + if (nextOrder.get("quantity") != null) { + BigDecimal itemQuantity = nextOrder.getBigDecimal("quantity"); + BigDecimal cancelQuantity = BigDecimal.ZERO; + if (nextOrder.get("cancelQuantity") != null) { + cancelQuantity = nextOrder.getBigDecimal("cancelQuantity"); + } + itemQuantity = itemQuantity.subtract(cancelQuantity); + if (itemQuantity.compareTo(BigDecimal.ZERO) >= 0) { + qty = qty.add(itemQuantity); } } } @@ -125,7 +124,7 @@ public final class InventoryWorker { condList.add(EntityCondition.makeCondition("orderItemStatusId", EntityOperator.NOT_EQUAL, "ITEM_CANCELLED")); EntityConditionList<EntityCondition> conditions = EntityCondition.makeCondition(condList, EntityOperator.AND); - Map<String, BigDecimal> results = new HashMap<String, BigDecimal>(); + Map<String, BigDecimal> results = new HashMap<>(); try { List<GenericValue> orderedProducts = EntityQuery.use(delegator).select(fieldsToSelect).from("OrderItemQuantityReportGroupByProduct").where(conditions).queryList(); for (GenericValue value: orderedProducts) { |
Free forum by Nabble | Edit this page |