From ccee7f2ccfbad3abc11ba0ef62ca4620d9cdbbf8 Mon Sep 17 00:00:00 2001 From: Jacques Le Roux Date: Sat, 9 Dec 2006 23:22:47 +0000 Subject: [PATCH] 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). git-svn-id: https://svn.apache.org/repos/asf/incubator/ofbiz/trunk@485087 13f79535-47bb-0310-9956-ffa450edef68 --- applications/order/servicedef/services.xml | 11 +++++++---- .../org/ofbiz/order/order/OrderServices.java | 19 ++++++++++++++----- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/applications/order/servicedef/services.xml b/applications/order/servicedef/services.xml index bb692099d3..bab2a917e4 100644 --- a/applications/order/servicedef/services.xml +++ b/applications/order/servicedef/services.xml @@ -315,10 +315,13 @@ under the License. - 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. + 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. diff --git a/applications/order/src/org/ofbiz/order/order/OrderServices.java b/applications/order/src/org/ofbiz/order/order/OrderServices.java index 6437227ac8..d36d760660 100644 --- a/applications/order/src/org/ofbiz/order/order/OrderServices.java +++ b/applications/order/src/org/ofbiz/order/order/OrderServices.java @@ -29,6 +29,7 @@ import org.ofbiz.base.util.*; 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 @@ public class OrderServices { return ServiceUtil.returnSuccess(); } + Timestamp nowTimestamp = UtilDateTime.nowTimestamp(); Iterator i = ordersToCheck.iterator(); while (i.hasNext()) { GenericValue orderHeader = (GenericValue) i.next(); @@ -2560,9 +2562,19 @@ public class OrderServices { } } 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 @@ public class OrderServices { 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);