Author: jleroux
Date: Sat Dec 9 15:22:47 2006 New Revision: 485087 URL: http://svn.apache.org/viewvc?view=rev&rev=485087 Log: A patch from Ray Barlow " Small change that can greatly reduce the amount of processing that autoCancelOrderItems does..." (https://issues.apache.org/jira/browse/OFBIZ-523). Modified: incubator/ofbiz/trunk/applications/order/servicedef/services.xml incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java Modified: incubator/ofbiz/trunk/applications/order/servicedef/services.xml URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/order/servicedef/services.xml?view=diff&rev=485087&r1=485086&r2=485087 ============================================================================== --- incubator/ofbiz/trunk/applications/order/servicedef/services.xml (original) +++ incubator/ofbiz/trunk/applications/order/servicedef/services.xml Sat Dec 9 15:22:47 2006 @@ -315,10 +315,13 @@ <service name="autoCancelOrderItems" engine="java" location="org.ofbiz.order.order.OrderServices" invoke="cancelFlaggedSalesOrders"> - <description>Batch service which automatically canels sales order items. Items will be canceled if (a) they are on - orders in the CREATED state and it has been either 30 days or ProductStore.daysCancelNoPay since the order was created or - (b) if the item is flagged with an autoCancelDate and does not have a dontCancelDate and dontCancelUserLogin associated with it, - and it is past the autoCancelDate.</description> + <description>Batch service which automatically cancels sales order and/or sales order items. + Sales orders : These will be cancelled if the order status equals CREATED and it has been + either 30 days or ProductStore.daysCancelNoPay since the order was created. A value of 0 for + ProductStore.daysCancelNoPay means do not auto-cancel. + Sales order items : This is only for orders on the APPROVED status. Items will be cancelled if the + item is flagged with an autoCancelDate and does not have a dontCancelDate and dontCancelUserLogin + associated with it, and it is past the autoCancelDate.</description> <!-- this service has no parameters IN or OUT --> </service> Modified: incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java?view=diff&rev=485087&r1=485086&r2=485087 ============================================================================== --- incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java (original) +++ incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java Sat Dec 9 15:22:47 2006 @@ -29,6 +29,7 @@ import org.ofbiz.base.util.collections.ResourceBundleMapWrapper; import org.ofbiz.common.DataModelConstants; import org.ofbiz.entity.GenericDelegator; +import org.ofbiz.entity.GenericEntity; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericValue; import org.ofbiz.entity.condition.EntityCondition; @@ -2512,6 +2513,7 @@ return ServiceUtil.returnSuccess(); } + Timestamp nowTimestamp = UtilDateTime.nowTimestamp(); Iterator i = ordersToCheck.iterator(); while (i.hasNext()) { GenericValue orderHeader = (GenericValue) i.next(); @@ -2560,9 +2562,19 @@ } } else { // check for auto-cancel items + List itemsExprs = new ArrayList(); + + // create the query expressions + itemsExprs.add(new EntityExpr("orderId", EntityOperator.EQUALS, orderId)); + itemsExprs.add(new EntityConditionList(UtilMisc.toList(new EntityExpr("statusId", EntityOperator.EQUALS, "ITEM_CREATED"), + new EntityExpr("statusId", EntityOperator.EQUALS, "ITEM_APPROVED")), EntityOperator.OR)); + itemsExprs.add(new EntityExpr("dontCancelSetUserLogin", EntityOperator.EQUALS, GenericEntity.NULL_FIELD)); + itemsExprs.add(new EntityExpr("dontCancelSetDate", EntityOperator.EQUALS, GenericEntity.NULL_FIELD)); + itemsExprs.add(new EntityExpr("autoCancelDate", EntityOperator.NOT_EQUAL, GenericEntity.NULL_FIELD)); + List orderItems = null; try { - orderItems = orderHeader.getRelated("OrderItem"); + orderItems = delegator.findByAnd("OrderItem", itemsExprs, null); } catch (GenericEntityException e) { Debug.logError(e, "Problem getting order item records", module); } @@ -2571,12 +2583,9 @@ while (oii.hasNext()) { GenericValue orderItem = (GenericValue) oii.next(); String orderItemSeqId = orderItem.getString("orderItemSeqId"); - Timestamp nowTimestamp = UtilDateTime.nowTimestamp(); Timestamp autoCancelDate = orderItem.getTimestamp("autoCancelDate"); - Timestamp dontCancelDate = orderItem.getTimestamp("dontCancelSetDate"); - String dontCancelUserLogin = orderItem.getString("dontCancelSetUserLogin"); - if (dontCancelUserLogin == null && dontCancelDate == null && autoCancelDate != null) { + if (autoCancelDate != null) { if (nowTimestamp.equals(autoCancelDate) || nowTimestamp.after(autoCancelDate)) { // cancel the order item Map svcCtx = UtilMisc.toMap("orderId", orderId, "orderItemSeqId", orderItemSeqId, "statusId", "ITEM_CANCELLED", "userLogin", userLogin); |
Free forum by Nabble | Edit this page |