Author: ashish
Date: Sat Jun 20 13:57:48 2009 New Revision: 786827 URL: http://svn.apache.org/viewvc?rev=786827&view=rev Log: Applied patch from jira issue OFBIZ-2470 (In Cross-Ship Replacement we need to make sure return for refund is possible after a return for replacement) This patch covers following scenarios: 1) Refund of the replacement order possible now. Since the replacement order has no payment preferences associated to it, payment preferences of the original order are used to process the refund. When the replacement order refund is complete you can look for the related entry in payment information section of the original order. Also you can find the payments for this return in ReturnItem screen. 2) When a replacement order is cancelled, and replacement return against which it was created is already received, then that return is refunded. Thanks Mridul, Arun for your contribution. Modified: ofbiz/trunk/applications/order/servicedef/secas.xml ofbiz/trunk/applications/order/servicedef/services_return.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?rev=786827&r1=786826&r2=786827&view=diff ============================================================================== --- ofbiz/trunk/applications/order/servicedef/secas.xml (original) +++ ofbiz/trunk/applications/order/servicedef/secas.xml Sat Jun 20 13:57:48 2009 @@ -81,6 +81,7 @@ <eca service="changeOrderStatus" event="commit" run-on-error="false"> <condition field-name="statusId" operator="equals" value="ORDER_CANCELLED"/> <action service="releaseOrderPayments" mode="sync"/> + <action service="processRefundReturnForReplacement" mode="sync"/> </eca> <eca service="changeOrderStatus" event="commit" run-on-error="false"> <condition field-name="statusId" operator="equals" value="ORDER_COMPLETED"/> Modified: ofbiz/trunk/applications/order/servicedef/services_return.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/servicedef/services_return.xml?rev=786827&r1=786826&r2=786827&view=diff ============================================================================== --- ofbiz/trunk/applications/order/servicedef/services_return.xml (original) +++ ofbiz/trunk/applications/order/servicedef/services_return.xml Sat Jun 20 13:57:48 2009 @@ -271,6 +271,11 @@ <description>Process subscription changes from a return</description> <attribute name="returnId" type="String" mode="IN" optional="false"/> </service> + <service name="processRefundReturnForReplacement" engine="java" auth="true" + location="org.ofbiz.order.order.OrderReturnServices" invoke="processRefundReturnForReplacement"> + <description>Process the refund return for replacement order</description> + <attribute name="orderId" type="String" mode="IN" optional="false"/> + </service> <!-- other return services --> <service name="updateReturnStatusFromReceipt" engine="simple" 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?rev=786827&r1=786826&r2=786827&view=diff ============================================================================== --- ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReturnServices.java (original) +++ ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReturnServices.java Sat Jun 20 13:57:48 2009 @@ -1081,6 +1081,63 @@ } } + public static Map processRefundReturnForReplacement(DispatchContext dctx, Map context) { + GenericDelegator delegator = dctx.getDelegator(); + LocalDispatcher dispatcher = dctx.getDispatcher(); + Locale locale = (Locale) context.get("locale"); + GenericValue userLogin = (GenericValue) context.get("userLogin"); + String orderId = (String) context.get("orderId"); + Map serviceResult = FastMap.newInstance(); + + GenericValue orderHeader = null; + List<GenericValue> orderPayPrefs = FastList.newInstance(); + try { + orderHeader = delegator.findByPrimaryKey("OrderHeader", UtilMisc.toMap("orderId", orderId)); + orderPayPrefs = orderHeader.getRelated("OrderPaymentPreference", UtilMisc.toList("-maxAmount")); + } catch (GenericEntityException e) { + Debug.logError("Problem looking up order information for orderId #" + orderId, module); + ServiceUtil.returnError(UtilProperties.getMessage(resource_error, "OrderCannotGetOrderHeader", locale)); + } + + // Check for replacement order + if (UtilValidate.isEmpty(orderPayPrefs)){ + List<GenericValue> returnItemResponses = FastList.newInstance(); + try { + returnItemResponses = orderHeader.getRelated("ReplacementReturnItemResponse"); + } catch (GenericEntityException e) { + Debug.logError("Problem getting ReturnItemResponses", module); + ServiceUtil.returnError(e.getMessage()); + } + + for (GenericValue returnItemResponse : returnItemResponses) { + GenericValue returnItem = null; + GenericValue returnHeader = null; + try { + returnItem = EntityUtil.getFirst(returnItemResponse.getRelated("ReturnItem")); + returnHeader = returnItem.getRelatedOne("ReturnHeader"); + } catch (GenericEntityException e) { + Debug.logError("Problem getting ReturnItem", module); + ServiceUtil.returnError(e.getMessage()); + } + + if ("RETURN_RECEIVED".equals(returnHeader.getString("statusId"))) { + String returnId = returnItem.getString("returnId"); + String returnTypeId = returnItem.getString("returnTypeId"); + try { + serviceResult = dispatcher.runSync("processRefundReturn", UtilMisc.toMap("returnId", returnId, "returnTypeId", returnTypeId, "userLogin", userLogin)); + } catch (GenericServiceException e) { + Debug.logError(e, "Problem running the processRefundReturn service", module); + return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderProblemsWithTheRefundSeeLogs", locale)); + } + if (ServiceUtil.isError(serviceResult)) { + return ServiceUtil.returnError(ServiceUtil.getErrorMessage(serviceResult)); + } + } + } + } + return serviceResult; + } + // refund (cash/charge) return public static Map processRefundReturn(DispatchContext dctx, Map context) { GenericDelegator delegator = dctx.getDelegator(); @@ -1138,6 +1195,16 @@ orderHeader = delegator.findByPrimaryKey("OrderHeader", UtilMisc.toMap("orderId", orderId)); // sort these desending by maxAmount orderPayPrefs = orderHeader.getRelated("OrderPaymentPreference", UtilMisc.toList("-maxAmount")); + // Check for replacement order + if (UtilValidate.isEmpty(orderPayPrefs)){ + List<GenericValue> orderItemAssocs = delegator.findByAnd("OrderItemAssoc", UtilMisc.toMap("toOrderId", orderId, "orderItemAssocTypeId", "REPLACEMENT")); + if (UtilValidate.isNotEmpty(orderItemAssocs)) { + String originalOrderId = EntityUtil.getFirst(orderItemAssocs).getString("orderId"); + orderHeader = delegator.findByPrimaryKey("OrderHeader", UtilMisc.toMap("orderId", originalOrderId)); + orderPayPrefs = orderHeader.getRelated("OrderPaymentPreference", UtilMisc.toList("-maxAmount")); + orderId = originalOrderId; + } + } List exprs = UtilMisc.toList(EntityCondition.makeCondition("statusId", EntityOperator.EQUALS, "PAYMENT_SETTLED"), EntityCondition.makeCondition("statusId", EntityOperator.EQUALS, "PAYMENT_RECEIVED")); orderPayPrefs = EntityUtil.filterByOr(orderPayPrefs, exprs); } catch (GenericEntityException e) { |
Free forum by Nabble | Edit this page |