Skip to content

Commit

Permalink
invoice: Fix issue when there are multiple usage sections defined in …
Browse files Browse the repository at this point in the history
…a Plan.

The code needs to filter the rawUsage to only take into account what is needed on a per
usage section.

Also, fix toString implementation for ContiguousIntervalCapacityUsageInArrear
  • Loading branch information
sbrossie committed Mar 6, 2018
1 parent 2d369af commit 0022417
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
Expand Up @@ -128,4 +128,16 @@ UsageCapacityInArrearAggregate computeToBeBilledCapacityInArrear(final List<Roll
Preconditions.checkState(false, "Could not find tier for usage " + usage.getName() + "matching with data = " + joiner.join(roUnits));
return null;
}

@Override
public String toString() {
final StringBuilder sb = new StringBuilder("ContiguousIntervalCapacityUsageInArrear{");
sb.append("transitionTimes=").append(transitionTimes);
sb.append(", billingEvents=").append(billingEvents);
sb.append(", rawSubscriptionUsage=").append(rawSubscriptionUsage);
sb.append(", rawUsageStartDate=").append(rawUsageStartDate);
sb.append('}');
return sb.toString();
}

}
Expand Up @@ -97,7 +97,7 @@ public ContiguousIntervalUsageInArrear(final Usage usage,
this.accountId = accountId;
this.invoiceId = invoiceId;
this.unitTypes = usage.getUsageType() == UsageType.CAPACITY ? getCapacityInArrearUnitTypes(usage) : getConsumableInArrearUnitTypes(usage);
this.rawSubscriptionUsage = rawSubscriptionUsage;
this.rawSubscriptionUsage = filterInputRawUsage(rawSubscriptionUsage);
this.targetDate = targetDate;
this.rawUsageStartDate = rawUsageStartDate;
this.internalTenantContext = internalTenantContext;
Expand All @@ -107,6 +107,7 @@ public ContiguousIntervalUsageInArrear(final Usage usage,
this.usageDetailMode = usageDetailMode;
}


/**
* Builds the transitionTimes associated to that usage section. Those are determined based on billing events for when to start and when to stop,
* the per usage billingPeriod and finally the targetDate.
Expand Down Expand Up @@ -345,6 +346,16 @@ private Long computeUpdatedAmount(@Nullable Long currentAmount, @Nullable Long n
}
}

private List<RawUsage> filterInputRawUsage(final List<RawUsage> rawSubscriptionUsage) {
final Iterable<RawUsage> filteredList = Iterables.filter(rawSubscriptionUsage, new Predicate<RawUsage>() {
@Override
public boolean apply(final RawUsage input) {
return unitTypes.contains(input.getUnitType());
}
});
return ImmutableList.copyOf(filteredList);
}

/**
* @param filteredUsageForInterval the list of invoiceItem to consider
* @return the price amount that was already billed for that period and usage section (across unitTypes)
Expand Down Expand Up @@ -419,16 +430,6 @@ public Currency getCurrency() {
return billingEvents.get(0).getCurrency();
}

@Override
public String toString() {
final StringBuilder sb = new StringBuilder("ContiguousIntervalConsumableInArrear{");
sb.append("transitionTimes=").append(transitionTimes);
sb.append(", billingEvents=").append(billingEvents);
sb.append(", rawSubscriptionUsage=").append(rawSubscriptionUsage);
sb.append(", rawUsageStartDate=").append(rawUsageStartDate);
sb.append('}');
return sb.toString();
}

public class UsageInArrearItemsAndNextNotificationDate {

Expand Down

1 comment on commit 0022417

@pierre
Copy link
Member

@pierre pierre commented on 0022417 Mar 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.