Fix issue when returning credit items for new bulk credit endpoint. See ##1141
@@ -324,7 +324,20 @@ public class DefaultInvoiceUserApi implements InvoiceUserApi {
if (creditItem == null) {
throw new InvoiceApiException(ErrorCode.INVOICE_NO_SUCH_CREDIT, creditId);
}
+ return negateCreditItems(ImmutableList.of(creditItem)).get(0);
+ }
+
+ @Override
+ public List<InvoiceItem> insertCredits(final UUID accountId, final LocalDate effectiveDate, final Iterable<InvoiceItem> creditItems,
+ final boolean autoCommit, final Iterable<PluginProperty> properties, final CallContext context) throws InvoiceApiException {
+ final List<InvoiceItem> items = insertItems(accountId, effectiveDate, InvoiceItemType.CREDIT_ADJ, creditItems, autoCommit, properties, context);
+ return negateCreditItems(items);
+ }
+ private static List<InvoiceItem> negateCreditItems(final List<InvoiceItem> input) {
+ final Iterable<InvoiceItem> tmp = Iterables.transform(input, new Function<InvoiceItem, InvoiceItem>() {
+ @Override
+ public InvoiceItem apply(final InvoiceItem creditItem) {
return new CreditAdjInvoiceItem(creditItem.getId(),
creditItem.getCreatedDate(),
creditItem.getInvoiceId(),
@@ -337,11 +350,8 @@ public class DefaultInvoiceUserApi implements InvoiceUserApi {
creditItem.getQuantity(),
creditItem.getItemDetails());
}
-
- @Override
- public List<InvoiceItem> insertCredits(final UUID accountId, final LocalDate effectiveDate, final Iterable<InvoiceItem> creditItems,
- final boolean autoCommit, final Iterable<PluginProperty> properties, final CallContext context) throws InvoiceApiException {
- return insertItems(accountId, effectiveDate, InvoiceItemType.CREDIT_ADJ, creditItems, autoCommit, properties, context);
+ });
+ return ImmutableList.copyOf(tmp);
}
@Override
