You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jo...@apache.org on 2007/07/19 05:38:12 UTC

svn commit: r557476 - /ofbiz/trunk/applications/product/src/org/ofbiz/product/subscription/SubscriptionServices.java

Author: jonesde
Date: Wed Jul 18 20:38:11 2007
New Revision: 557476

URL: http://svn.apache.org/viewvc?view=rev&rev=557476
Log:
Fixed some bugs with processExtendSubscription related to inventoryItemId and excluding future subscriptions too

Modified:
    ofbiz/trunk/applications/product/src/org/ofbiz/product/subscription/SubscriptionServices.java

Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/subscription/SubscriptionServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/subscription/SubscriptionServices.java?view=diff&rev=557476&r1=557475&r2=557476
==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/product/subscription/SubscriptionServices.java (original)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/product/subscription/SubscriptionServices.java Wed Jul 18 20:38:11 2007
@@ -54,6 +54,7 @@
         
         String partyId = (String) context.get("partyId");
         String subscriptionResourceId = (String) context.get("subscriptionResourceId");
+        String inventoryItemId = (String) context.get("inventoryItemId");
         String roleTypeId = (String) context.get("useRoleTypeId");
         GenericValue userLogin = (GenericValue) context.get("userLogin");
         Integer useTime = (Integer) context.get("useTime");
@@ -63,9 +64,12 @@
         
         GenericValue lastSubscription = null;
         try {
-            List subscriptionList = delegator.findByAndCache("Subscription", UtilMisc.toMap("partyId", partyId, "subscriptionResourceId", subscriptionResourceId));
-            List listFiltered = EntityUtil.filterByDate(subscriptionList, true);
-            List listOrdered = EntityUtil.orderBy(listFiltered, UtilMisc.toList("-fromDate"));
+            Map subscriptionFindMap = UtilMisc.toMap("partyId", partyId, "subscriptionResourceId", subscriptionResourceId);
+            // if this subscription is attached to something the customer owns, filter by that too
+            if (UtilValidate.isNotEmpty(inventoryItemId)) subscriptionFindMap.put("inventoryItemId", inventoryItemId);
+            List subscriptionList = delegator.findByAnd("Subscription", subscriptionFindMap);
+            // DEJ20070718 DON'T filter by date, we want to consider all subscriptions: List listFiltered = EntityUtil.filterByDate(subscriptionList, true);
+            List listOrdered = EntityUtil.orderBy(subscriptionList, UtilMisc.toList("-fromDate"));
             if (listOrdered.size() > 0) {
                 lastSubscription = (GenericValue) listOrdered.get(0);
             }
@@ -85,12 +89,11 @@
         } else {
             newSubscription = lastSubscription;
         }
-        newSubscription.set("inventoryItemId", context.get("inventoryItemId"));
+        newSubscription.set("inventoryItemId", inventoryItemId);
 
         Timestamp thruDate = lastSubscription != null ? (Timestamp) lastSubscription.get("thruDate") : null;
         if (thruDate == null) {
             // no thruDate? start with NOW
-            thruDate = nowTimestamp;
             newSubscription.set("fromDate", nowTimestamp);
         } else {
             // there is a thru date... if it is in the past, bring it up to NOW before adding on the time period
@@ -109,6 +112,7 @@
             calendar.add(times[0], (useTime.intValue() * times[1]));
         } else {
             Debug.logWarning("Don't know anything about useTimeUomId [" + useTimeUomId + "], defaulting to month", module);
+            calendar.add(Calendar.MONTH, (useTime.intValue() * times[1]));
         }
        
         thruDate = new Timestamp(calendar.getTimeInMillis());