svn commit: r565718 - /ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisShipmentServices.java

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

svn commit: r565718 - /ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisShipmentServices.java

jonesde
Author: jonesde
Date: Tue Aug 14 04:48:22 2007
New Revision: 565718

URL: http://svn.apache.org/viewvc?view=rev&rev=565718
Log:
Added code to fill in serial number; this stuff is fairly tricky and will only work in limited circumstances, but here is a start at least

Modified:
    ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisShipmentServices.java

Modified: ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisShipmentServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisShipmentServices.java?view=diff&rev=565718&r1=565717&r2=565718
==============================================================================
--- ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisShipmentServices.java (original)
+++ ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisShipmentServices.java Tue Aug 14 04:48:22 2007
@@ -854,11 +854,45 @@
       
                 // calculate total qty of return items in a shipping unit received, order associated with return
                 double totalQty = 0.0;
+                Map serialNumberListByReturnItemSeqIdMap = FastMap.newInstance();
+                bodyParameters.put("serialNumberListByReturnItemSeqIdMap", serialNumberListByReturnItemSeqIdMap);
                 Iterator riIter = returnItems.iterator();
                 while (riIter.hasNext()) {
                     GenericValue returnItem = (GenericValue) riIter.next();
                     double itemQty = returnItem.getDouble("returnQuantity").doubleValue();
                     totalQty += itemQty;
+                    
+                    // for each ReturnItem also get serial numbers using ItemIssuanceAndInventoryItem
+                    // NOTE: technically if the ReturnItem.quantity != OrderItem.quantity then we don't know which serial number is being returned, so rather than guessing we will send it only in that case
+                    try {
+                        GenericValue orderItem = returnItem.getRelatedOne("OrderItem");
+                        if (orderItem != null) {
+                            if (orderItem.getDouble("quantity").doubleValue() == itemQty) {
+                                List itemIssuanceAndInventoryItemList = delegator.findByAnd("ItemIssuanceAndInventoryItem",
+                                        UtilMisc.toMap("orderId", orderItem.get("orderId"), "orderItemSeqId", orderItem.get("orderItemSeqId"),
+                                                "inventoryItemTypeId", "SERIALIZED_INV_ITEM"));
+                                if (itemIssuanceAndInventoryItemList.size() == itemQty) {
+                                    List serialNumberList = FastList.newInstance();
+                                    serialNumberListByReturnItemSeqIdMap.put(returnItem.get("returnItemSeqId"), serialNumberList);
+                                    Iterator itemIssuanceAndInventoryItemIter = itemIssuanceAndInventoryItemList.iterator();
+                                    while (itemIssuanceAndInventoryItemIter.hasNext()) {
+                                        GenericValue itemIssuanceAndInventoryItem = (GenericValue) itemIssuanceAndInventoryItemIter.next();
+                                        serialNumberList.add(itemIssuanceAndInventoryItem.get("serialNumber"));
+                                    }
+                                } else {
+                                    // TODO: again a quantity mismatch, whatever to do?
+                                    Debug.logWarning("Number of serial numbers [" + itemIssuanceAndInventoryItemList.size() + "] did not match quantity [" + itemQty + "] for return item: " + returnItem.getPrimaryKey(), module);
+                                }
+                            } else {
+                                // TODO: we don't know which serial numbers are returned, should we throw an error? probably not, just do what we can
+                                Debug.logWarning("Could not get matching serial numbers because order item quantity [" + orderItem.getDouble("quantity") + "] did not match quantity [" + itemQty + "] for return item: " + returnItem.getPrimaryKey(), module);
+                            }
+                        }
+                    } catch (GenericEntityException e) {
+                        String errMsg = "Error getting data for processing return message: " + e.toString();
+                        Debug.logError(e, errMsg, module);
+                        return ServiceUtil.returnError(errMsg);
+                    }
                 }
                 bodyParameters.put("totalQty", new Double(totalQty));