svn commit: r537258 - in /ofbiz/trunk/applications/order: servicedef/secas.xml src/org/ofbiz/order/order/OrderReturnServices.java

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

svn commit: r537258 - in /ofbiz/trunk/applications/order: servicedef/secas.xml src/org/ofbiz/order/order/OrderReturnServices.java

jacopoc
Author: jacopoc
Date: Fri May 11 11:22:55 2007
New Revision: 537258

URL: http://svn.apache.org/viewvc?view=rev&rev=537258
Log:
When returning a non-physical good (productType.isPhysical == N as well as non-product order items) returns should not require inventory to be received. In this case, a return will move directly from APPROVED to COMPLETED handing the refund/order/credit right away.

Modified:
    ofbiz/trunk/applications/order/servicedef/secas.xml
    ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReturnServices.java

Modified: ofbiz/trunk/applications/order/servicedef/secas.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/servicedef/secas.xml?view=diff&rev=537258&r1=537257&r2=537258
==============================================================================
--- ofbiz/trunk/applications/order/servicedef/secas.xml (original)
+++ ofbiz/trunk/applications/order/servicedef/secas.xml Fri May 11 11:22:55 2007
@@ -138,6 +138,9 @@
 
     <!-- Return ECAs -->
     <eca service="updateReturnHeader" event="commit">
+        <action service="checkReturnComplete" mode="sync"/>
+    </eca>
+    <eca service="updateReturnHeader" event="commit">
         <condition field-name="statusId" operator="equals" value="RETURN_ACCEPTED"/>
         <condition field-name="currentStatusId" operator="not-equals" value="RETURN_ACCEPTED"/>
         <action service="processCrossShipReplacementReturn" mode="sync"/>
@@ -153,24 +156,17 @@
         <action service="processRefundReturn" mode="sync"/>
     </eca>
     <eca service="updateReturnHeader" event="commit">
-        <action service="checkReturnComplete" mode="sync"/>
-    </eca>
-    <eca service="updateReturnHeader" event="commit">
         <condition field-name="statusId" operator="equals" value="RETURN_CANCELLED"/>
         <condition field-name="currentStatusId" operator="not-equals" value="RETURN_CANCELLED"/>
+        <action service="cancelReturnItems" mode="sync"/>
         <action service="sendReturnCancelNotification" mode="async" persist="true"/>
     </eca>
-    <eca service="updateReturnHeader" event="commit">
-        <condition field-name="statusId" operator="equals" value="RETURN_CANCELLED"/>
-        <action service="cancelReturnItems" mode="sync" persist="true"/>
-    </eca>
-
+
     <eca service="updateReturnItem" event="commit">
         <condition field-name="statusId" operator="equals" value="RETURN_RECEIVED"/>
         <condition field-name="currentStatusId" operator="not-equals" value="RETURN_RECEIVED"/>
         <action service="resetGrandTotal" mode="sync"/>
     </eca>
-
     <eca service="updateReturnItem" event="commit">
         <condition field-name="statusId" operator="equals" value="RETURN_CANCELLED"/>
         <condition field-name="currentStatusId" operator="not-equals" value="RETURN_CANCELLED"/>

Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReturnServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReturnServices.java?view=diff&rev=537258&r1=537257&r2=537258
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReturnServices.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReturnServices.java Fri May 11 11:22:55 2007
@@ -50,6 +50,7 @@
 import org.ofbiz.entity.condition.EntityOperator;
 import org.ofbiz.entity.util.EntityUtil;
 import org.ofbiz.product.product.ProductContentWrapper;
+import org.ofbiz.product.product.ProductWorker;
 import org.ofbiz.product.store.ProductStoreWorker;
 import org.ofbiz.service.DispatchContext;
 import org.ofbiz.service.GenericServiceException;
@@ -405,6 +406,7 @@
             EntityConditionList havingConditions = new EntityConditionList(UtilMisc.toList(
                     new EntityExpr("quantityIssued", EntityOperator.GREATER_THAN, new Double(0))
                 ), EntityOperator.AND);
+            havingConditions = null;
             List orderItemQuantitiesIssued = null;
             try {
                 orderItemQuantitiesIssued = delegator.findByCondition("OrderItemQuantityReportGroupByItem", whereConditions, havingConditions, UtilMisc.toList("orderId", "orderItemSeqId"), UtilMisc.toList("orderItemSeqId"), null);
@@ -478,8 +480,9 @@
 
     // check return items status and update return header status
     public static Map checkReturnComplete(DispatchContext dctx, Map context) {
-        //appears to not be used: LocalDispatcher dispatcher = ctx.getDispatcher();
         GenericDelegator delegator = dctx.getDelegator();
+        LocalDispatcher dispatcher = dctx.getDispatcher();
+        GenericValue userLogin = (GenericValue) context.get("userLogin");
         String returnId = (String) context.get("returnId");
         Locale locale = (Locale) context.get("locale");
 
@@ -496,8 +499,9 @@
         }
 
         // if already completed just return
+        String currentStatus = null;
         if (returnHeader != null && returnHeader.get("statusId") != null) {
-            String currentStatus = returnHeader.getString("statusId");
+            currentStatus = returnHeader.getString("statusId");
             if ("RETURN_COMPLETED".equals(currentStatus) || "RETURN_CANCELLED".equals(currentStatus)) {
                 return ServiceUtil.returnSuccess();
             }
@@ -516,28 +520,48 @@
                     // both completed and cancelled items qualify for completed status change
                     if ("RETURN_COMPLETED".equals(itemStatus) || "RETURN_CANCELLED".equals(itemStatus)) {
                         completedItems.add(item);
+                    } else {
+                        // Non-physical items don't need an inventory receive and so are
+                        // considered completed after the return is accepted
+                        if ("RETURN_ACCEPTED".equals(returnHeader.getString("statusId"))) {
+                            try {
+                                GenericValue itemProduct = item.getRelatedOne("Product");
+                                if (!ProductWorker.isPhysical(itemProduct)) {
+                                    completedItems.add(item);
+                                }
+                            } catch (GenericEntityException e) {
+                                Debug.logError(e, "Problems looking up returned product type information", module);
+                                return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderErrorGettingReturnHeaderItemInformation", locale));
+                            }
+                        }
                     }
                 }
             }
 
             // if all items are completed/cancelled these should match
             if (completedItems.size() == returnItems.size()) {
-                List toStore = new LinkedList();
-                returnHeader.set("statusId", "RETURN_COMPLETED");
-                toStore.add(returnHeader);
-
-                // create the status change history and set it to be stored
-                String returnStatusId = delegator.getNextSeqId("ReturnStatus");
-                GenericValue returnStatus = delegator.makeValue("ReturnStatus", UtilMisc.toMap("returnStatusId", returnStatusId));
-                returnStatus.set("statusId", "RETURN_COMPLETED");
-                returnStatus.set("returnId", returnId);
-                returnStatus.set("statusDatetime", now);
-                toStore.add(returnStatus);
-                try {
-                    delegator.storeAll(toStore);
-                } catch (GenericEntityException e) {
-                    Debug.logError(e, module);
-                    return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderErrorUnableToCreateReturnStatusHistory", locale));
+                // The return is just moved to its next status by calling the
+                // updateReturnHeader service; this will trigger all the appropriate ecas
+                // including this service again, so that the return is moved
+                // to the final status
+                if (currentStatus != null && "RETURN_ACCEPTED".equals(currentStatus)) {
+                    try {
+                        dispatcher.runSync("updateReturnHeader", UtilMisc.toMap("returnId", returnId,
+                                                                                "statusId", "RETURN_RECEIVED",
+                                                                                "userLogin", userLogin));
+                    } catch (GenericServiceException e) {
+                        Debug.logError(e, module);
+                        return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderErrorUnableToCreateReturnStatusHistory", locale));
+                    }
+                } else if (currentStatus != null && "RETURN_RECEIVED".equals(currentStatus)) {
+                    try {
+                        dispatcher.runSync("updateReturnHeader", UtilMisc.toMap("returnId", returnId,
+                                                                                "statusId", "RETURN_COMPLETED",
+                                                                                "userLogin", userLogin));
+                    } catch (GenericServiceException e) {
+                        Debug.logError(e, module);
+                        return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderErrorUnableToCreateReturnStatusHistory", locale));
+                    }
                 }
             }