Author: jaz
Date: Thu May 17 12:25:13 2007
New Revision: 539086
URL: http://svn.apache.org/viewvc?view=rev&rev=539086
Log:
implemented cancel of subscriptions when the order item is returned; fixed
return notification bugs
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?view=diff&rev=539086&r1=539085&r2=539086
==============================================================================
--- ofbiz/trunk/applications/order/servicedef/secas.xml (original)
+++ ofbiz/trunk/applications/order/servicedef/secas.xml Thu May 17 12:25:13 2007
@@ -69,12 +69,9 @@
</eca>
-->
- <!-- This ECA is for content usage subscriptions
- Andy: not all orders will be subscriptions; ITS NOT RECOMMENDED TO
TRIGGER ON THIS - Use the fulfillment services for processing subscriptions
- David: let's leave it this way for now, need to rethink somewhat how
other things are done since the ECA based design has some nice features
- -->
+ <!-- This ECA is for content usage subscriptions -->
<eca service="changeOrderStatus" event="commit" run-on-error="false">
- <condition field-name="statusId" operator="equals"
value="ORDER_APPROVED"/>
+ <condition field-name="statusId" operator="equals"
value="ORDER_COMPLETED"/>
<condition field-name="orderTypeId" operator="equals"
value="SALES_ORDER"/>
<condition-field field-name="statusId" operator="not-equals"
to-field-name="oldStatusId"/>
<action service="updateContentSubscriptionByOrder" mode="sync"/>
@@ -162,6 +159,12 @@
<action service="processRefundReturn" mode="sync"/>
</eca>
<eca service="updateReturnHeader" event="commit">
+ <condition field-name="statusId" operator="equals"
value="RETURN_COMPLETED"/>
+ <condition field-name="currentStatusId" operator="not-equals"
value="RETURN_COMPLETED"/>
+ <action service="sendReturnCompleteNotification" mode="async"
persist="true"/>
+ <action service="processSubscriptionReturn" 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"/>
@@ -196,13 +199,7 @@
<eca service="processRefundReturn" event="commit">
<action service="checkReturnComplete" mode="sync"/>
</eca>
-
- <eca service="checkReturnComplete" event="commit">
- <condition field-name="statusId" operator="is-not-empty"/>
- <condition field-name="statusId" operator="equals"
value="RETURN_COMPLETED"/>
- <action service="sendReturnCompleteNotification" mode="async"
persist="true"/>
- </eca>
-
+
<!-- ShoppingList ECAs -->
<eca service="createShoppingList" event="in-validate">
<condition field-name="shippingMethodString" operator="is-not-empty"/>
Modified: ofbiz/trunk/applications/order/servicedef/services_return.xml
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/servicedef/services_return.xml?view=diff&rev=539086&r1=539085&r2=539086
==============================================================================
--- ofbiz/trunk/applications/order/servicedef/services_return.xml (original)
+++ ofbiz/trunk/applications/order/servicedef/services_return.xml Thu May 17
12:25:13 2007
@@ -190,6 +190,7 @@
<attribute name="statusId" type="String" mode="OUT" optional="true"/>
</service>
+ <!-- return notification services -->
<service name="sendReturnAcceptNotification" engine="java" max-retry="3"
location="org.ofbiz.order.order.OrderReturnServices"
invoke="sendReturnAcceptNotification">
<description>Send a notification that a return has been
accepted</description>
@@ -206,6 +207,7 @@
<attribute name="returnId" type="String" mode="IN" optional="false"/>
</service>
+ <!-- return processing services -->
<service name="processCreditReturn" engine="java" auth="true"
location="org.ofbiz.order.order.OrderReturnServices"
invoke="processCreditReturn">
<description>Process the credits in a return</description>
@@ -237,6 +239,13 @@
<description>Process the replacements in a repair return</description>
<attribute name="returnId" type="String" mode="IN" optional="false"/>
</service>
+ <service name="processSubscriptionReturn" engine="java" auth="true"
+ location="org.ofbiz.order.order.OrderReturnServices"
invoke="processSubscriptionReturn">
+ <description>Process subscription changes from a return</description>
+ <attribute name="returnId" type="String" mode="IN" optional="false"/>
+ </service>
+
+ <!-- other return services -->
<service name="updateReturnStatusFromReceipt" engine="simple"
location="org/ofbiz/order/order/OrderReturnServices.xml"
invoke="updateReturnStatusFromReceipt">
<description>Update return/item status when items have been
received</description>
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=539086&r1=539085&r2=539086
==============================================================================
---
ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReturnServices.java
(original)
+++
ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReturnServices.java
Thu May 17 12:25:13 2007
@@ -275,11 +275,11 @@
}
// check for errors
- if (sendResp != null && !ServiceUtil.isError(sendResp)) {
+ if (sendResp != null && ServiceUtil.isError(sendResp)) {
sendResp.put("emailType", emailType);
return
ServiceUtil.returnError(UtilProperties.getMessage(resource_error,
"OrderProblemSendingEmail", locale), null, null, sendResp);
}
- return sendResp;
+ return ServiceUtil.returnSuccess();
}
}
@@ -956,13 +956,15 @@
BigDecimal amountLeftToRefund = new
BigDecimal(orderTotal.doubleValue()).setScale(decimals, rounding);
// This can be extended to support additional electronic types
- List electronicTypes = UtilMisc.toList("CREDIT_CARD",
"EFT_ACCOUNT", "GIFT_CARD");
+ List electronicTypes = UtilMisc.toList("CREDIT_CARD",
"EFT_ACCOUNT", "FIN_ACCOUNT", "GIFT_CARD");
// This defines the ordered part of the sequence of refund
processing
List orderedRefundPaymentMethodTypes = new ArrayList();
orderedRefundPaymentMethodTypes.add("EXT_BILLACT");
+ orderedRefundPaymentMethodTypes.add("FIN_ACCOUNT");
orderedRefundPaymentMethodTypes.add("GIFT_CARD");
orderedRefundPaymentMethodTypes.add("CREDIT_CARD");
+ orderedRefundPaymentMethodTypes.add("EFT_ACCOUNT");
// Add all the other paymentMethodTypes, in no particular order
EntityConditionList pmtConditionList = new
EntityConditionList(UtilMisc.toList(new EntityExpr("paymentMethodTypeId",
EntityOperator.NOT_IN, orderedRefundPaymentMethodTypes)), EntityOperator.AND);
@@ -1725,6 +1727,62 @@
}
return ServiceUtil.returnSuccess(successMessage.toString());
+ }
+
+ public static Map processSubscriptionReturn(DispatchContext dctx, Map
context) {
+ GenericDelegator delegator = dctx.getDelegator();
+ String returnId = (String) context.get("returnId");
+ Timestamp now = UtilDateTime.nowTimestamp();
+
+ GenericValue returnHeader;
+ List returnItems = null;
+ try {
+ returnHeader = delegator.findByPrimaryKey("ReturnHeader",
UtilMisc.toMap("returnId", returnId));
+ if (returnHeader != null) {
+ returnItems = returnHeader.getRelatedByAnd("ReturnItem",
UtilMisc.toMap("returnTypeId", "RTN_REFUND"));
+ }
+ } catch (GenericEntityException e) {
+ Debug.logError(e, module);
+ return ServiceUtil.returnError(e.getMessage());
+ }
+
+ if (returnItems != null) {
+ Iterator ri = returnItems.iterator();
+ while (ri.hasNext()) {
+ GenericValue returnItem = (GenericValue) ri.next();
+ String orderItemSeqId = returnItem.getString("orderItemSeqId");
+ String orderId = returnItem.getString("orderId");
+
+ // lookup subscriptions
+ List subscriptions;
+ try {
+ subscriptions = delegator.findByAnd("Subscription",
UtilMisc.toMap("orderId", orderId, "orderItemSeqId", orderItemSeqId));
+ } catch (GenericEntityException e) {
+ Debug.logError(e, module);
+ return ServiceUtil.returnError(e.getMessage());
+ }
+
+ // cancel all current subscriptions
+ if (subscriptions != null) {
+ Iterator si = subscriptions.iterator();
+ while (si.hasNext()) {
+ GenericValue subscription = (GenericValue) si.next();
+ Timestamp thruDate =
subscription.getTimestamp("thruDate");
+ if (thruDate == null || thruDate.after(now)) {
+ subscription.set("thruDate", now);
+ try {
+ delegator.store(subscription);
+ } catch (GenericEntityException e) {
+ Debug.logError(e, module);
+ return ServiceUtil.returnError(e.getMessage());
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return ServiceUtil.returnSuccess();
}
/**