Author: mor
Date: Fri May 15 11:48:46 2009 New Revision: 775091 URL: http://svn.apache.org/viewvc?rev=775091&view=rev Log: A zero amount replacement order gets created in held status when a return is accepted by using return type "Wait Replacement Reserved". If the return is not received within 30 days then all these replacement orders are canceled by a scheduled batch process. Applied a slightly modified patch from Mukesh Choudhary, part of OFBIZ-2464 (https://issues.apache.org/jira/browse/OFBIZ-2464) IMO, we can define a new field daysToCancelRepOrder (or any better name) on ProductStore entity instead of reading days till cancel from a properties file. This would be a very easy change. Thoughts? Added: ofbiz/trunk/applications/order/config/order.properties (with props) Modified: ofbiz/trunk/applications/order/data/OrderScheduledServices.xml ofbiz/trunk/applications/order/servicedef/services_return.xml ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReturnServices.java Added: ofbiz/trunk/applications/order/config/order.properties URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/config/order.properties?rev=775091&view=auto ============================================================================== --- ofbiz/trunk/applications/order/config/order.properties (added) +++ ofbiz/trunk/applications/order/config/order.properties Fri May 15 11:48:46 2009 @@ -0,0 +1,21 @@ +############################################################################### +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +############################################################################### + +# Days Till Cancel Replacement Order +daysTillCancelReplacementOrder=30 \ No newline at end of file Propchange: ofbiz/trunk/applications/order/config/order.properties ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/trunk/applications/order/config/order.properties ------------------------------------------------------------------------------ svn:keywords = "Date Rev Author URL Id" Propchange: ofbiz/trunk/applications/order/config/order.properties ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: ofbiz/trunk/applications/order/data/OrderScheduledServices.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/data/OrderScheduledServices.xml?rev=775091&r1=775090&r2=775091&view=diff ============================================================================== --- ofbiz/trunk/applications/order/data/OrderScheduledServices.xml (original) +++ ofbiz/trunk/applications/order/data/OrderScheduledServices.xml Fri May 15 11:48:46 2009 @@ -28,5 +28,6 @@ <JobSandbox jobId="8004" jobName="Re-Try Failed Auths NSF" runTime="2000-01-01 01:00:00.000" serviceName="retryFailedAuthNsfs" poolId="pool" runAsUser="system" tempExprId="MIDNIGHT_DAILY" maxRecurrenceCount="-1"/> <JobSandbox jobId="8005" jobName="Extend expired Subscriptions" runTime="2000-01-01 03:00:00.000" serviceName="runSubscriptionAutoReorders" poolId="pool" runAsUser="system" tempExprId="MIDNIGHT_DAILY" maxRecurrenceCount="-1"/> <JobSandbox jobId="8006" jobName="Cancels all orders after date" runTime="2009-12-03 03:00:00.000" serviceName="cancelAllBackOrders" poolId="pool" runAsUser="system" tempExprId="MIDNIGHT_DAILY" maxRecurrenceCount="-1"/> + <JobSandbox jobId="8007" jobName="Replacement Held Order Auto-Cancel" runTime="2000-01-01 00:00:00.000" serviceName="autoCancelReplacementOrders" poolId="pool" runAsUser="system" tempExprId="MIDNIGHT_DAILY" maxRecurrenceCount="-1"/> </entity-engine-xml> Modified: ofbiz/trunk/applications/order/servicedef/services_return.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/servicedef/services_return.xml?rev=775091&r1=775090&r2=775091&view=diff ============================================================================== --- ofbiz/trunk/applications/order/servicedef/services_return.xml (original) +++ ofbiz/trunk/applications/order/servicedef/services_return.xml Fri May 15 11:48:46 2009 @@ -209,6 +209,10 @@ <description>Send a notification that a return has been cancelled</description> <attribute name="returnId" type="String" mode="IN" optional="false"/> </service> + <service name="autoCancelReplacementOrders" engine="java" max-retry="3" transaction-timeout="36000" + location="org.ofbiz.order.order.OrderReturnServices" invoke="autoCancelReplacementOrders"> + <description>Automatic cancellation of replacement order if return is not received within 30 days</description> + </service> <!-- return processing services --> <service name="processCreditReturn" engine="java" auth="true" 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=775091&r1=775090&r2=775091&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 Fri May 15 11:48:46 2009 @@ -22,6 +22,8 @@ import java.math.BigDecimal; import java.sql.Timestamp; import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; @@ -300,7 +302,64 @@ public static Map sendReturnCancelNotification(DispatchContext dctx, Map context) { return sendReturnNotificationScreen(dctx, context, "PRDS_RTN_CANCEL"); } - + + // cancel replacement order if return not received within 30 days and send notification + public static Map<String,Object> autoCancelReplacementOrders(DispatchContext dctx, Map<String, ? extends Object> context) { + GenericDelegator delegator = dctx.getDelegator(); + LocalDispatcher dispatcher = dctx.getDispatcher(); + GenericValue userLogin = (GenericValue) context.get("userLogin"); + List<GenericValue> returnHeaders = null; + try { + returnHeaders = delegator.findList("ReturnHeader", EntityCondition.makeCondition( + EntityCondition.makeCondition("statusId", EntityOperator.EQUALS, "RETURN_ACCEPTED"), EntityOperator.AND, + EntityCondition.makeCondition("returnHeaderTypeId", EntityOperator.EQUALS, "CUSTOMER_RETURN")), null, UtilMisc.toList("entryDate"), null, false); + } catch (GenericEntityException e) { + Debug.logError(e, "Problem getting Return headers", module); + } + for (GenericValue returnHeader : returnHeaders) { + String returnId = returnHeader.getString("returnId"); + Timestamp entryDate = returnHeader.getTimestamp("entryDate"); + String daysTillCancelStr = UtilProperties.getPropertyValue("order.properties", "daysTillCancelReplacementOrder", "30"); + int daysTillCancel = 0; + try { + daysTillCancel = Integer.parseInt(daysTillCancelStr); + } catch (NumberFormatException e) { + Debug.logError(e, "Unable to get daysTillCancel", module); + } + if (daysTillCancel > 0) { + Calendar cal = Calendar.getInstance(); + cal.setTimeInMillis(entryDate.getTime()); + cal.add(Calendar.DAY_OF_YEAR, daysTillCancel); + Date cancelDate = cal.getTime(); + Date nowDate = new Date(); + if (cancelDate.equals(nowDate) || nowDate.after(cancelDate)) { + try { + List<GenericValue> returnItems = delegator.findList("ReturnItem", EntityCondition.makeCondition( + EntityCondition.makeCondition("returnId", EntityOperator.EQUALS, returnId), EntityOperator.AND, + EntityCondition.makeCondition("returnTypeId", EntityOperator.EQUALS, "RTN_WAIT_REPLACE_RES")), null, UtilMisc.toList("createdStamp"), null, false); + for (GenericValue returnItem : returnItems) { + GenericValue returnItemResponse = returnItem.getRelatedOne("ReturnItemResponse"); + if (returnItemResponse != null) { + String replacementOrderId = returnItemResponse.getString("replacementOrderId"); + Map svcCtx = UtilMisc.toMap("orderId", replacementOrderId, "userLogin", userLogin); + GenericValue orderHeader = delegator.findOne("OrderHeader", UtilMisc.toMap("orderId", replacementOrderId), false); + if ("ORDER_HOLD".equals(orderHeader.getString("statusId"))) { + try { + dispatcher.runSync("cancelOrderItem", svcCtx); + } catch (GenericServiceException e) { + Debug.logError(e, "Problem calling service cancelOrderItem: " + svcCtx, module); + } + } + } + } + } catch (GenericEntityException e) { + Debug.logError(e, module);; + } + } + } + } + return ServiceUtil.returnSuccess(); + } // get the returnable quantiy for an order item public static Map getReturnableQuantity(DispatchContext dctx, Map context) { GenericValue orderItem = (GenericValue) context.get("orderItem"); |
Free forum by Nabble | Edit this page |