killbill-memoizeit

Change subscription to compute effectiveDate from EOT policy

10/18/2013 3:59:07 PM

Details

diff --git a/subscription/src/main/java/com/ning/billing/subscription/api/user/DefaultSubscriptionBase.java b/subscription/src/main/java/com/ning/billing/subscription/api/user/DefaultSubscriptionBase.java
index 93c7831..34b5f26 100644
--- a/subscription/src/main/java/com/ning/billing/subscription/api/user/DefaultSubscriptionBase.java
+++ b/subscription/src/main/java/com/ning/billing/subscription/api/user/DefaultSubscriptionBase.java
@@ -500,7 +500,13 @@ public class DefaultSubscriptionBase extends EntityBase implements SubscriptionB
             case IMMEDIATE:
                 return clock.getUTCNow();
             case END_OF_TERM:
-                return (chargedThroughDate != null) ? chargedThroughDate : clock.getUTCNow();
+                //
+                // If we have a chargedThroughDate that is 'up to date' we use it, if not default to now
+                // chargedThroughDate could exist and be less than now if:
+                // 1. account is not being invoiced, for e.g AUTO_INVOICING_OFF nis set
+                // 2. In the case if FIXED item CTD is set using startDate of the service period
+                //
+                return (chargedThroughDate != null && chargedThroughDate.isAfter(clock.getUTCNow())) ? chargedThroughDate : clock.getUTCNow();
             default:
                 throw new SubscriptionBaseError(String.format(
                         "Unexpected policy type %s", policy.toString()));