Skip to content

Commit

Permalink
save effective rate in tax invoice items
Browse files Browse the repository at this point in the history
  • Loading branch information
vlaskhilkevich committed Jul 22, 2024
1 parent 3acf0d6 commit 8c3fac3
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -300,37 +300,38 @@ private Collection<InvoiceItem> toInvoiceItems(final UUID invoiceId,
final BigDecimal calculatedTax = transactionLineDetailModel.getCalculatedTax() != null ? BigDecimal.valueOf(transactionLineDetailModel.getCalculatedTax()) : null;
final InvoiceItem taxItem = buildTaxItem(taxableItem, invoiceId, adjustmentItem, calculatedTax, description);
if (taxItem != null) {
final InvoiceItem taxItemDerived = new PluginInvoiceItem(new Builder<>()
.withId(taxItem.getId())
.withInvoiceItemType(taxItem.getInvoiceItemType())
.withInvoiceId(taxItem.getInvoiceId())
.withAccountId(taxItem.getAccountId())
.withChildAccountId(taxItem.getChildAccountId())
.withStartDate(taxItem.getStartDate())
.withEndDate(taxItem.getEndDate())
.withAmount(taxItem.getAmount())
.withCurrency(taxItem.getCurrency())
.withDescription(taxItem.getDescription())
.withSubscriptionId(taxItem.getSubscriptionId())
.withBundleId(taxItem.getBundleId())
.withCatalogEffectiveDate(taxItem.getCatalogEffectiveDate())
.withProductName(taxItem.getProductName())
.withPrettyProductName(taxItem.getPrettyProductName())
.withPlanName(taxItem.getPlanName())
.withPrettyPlanName(taxItem.getPrettyPlanName())
.withPhaseName(taxItem.getPhaseName())
.withPrettyPhaseName(taxItem.getPrettyPhaseName())
.withRate(taxItem.getRate())
.withLinkedItemId(taxItem.getLinkedItemId())
.withUsageName(taxItem.getUsageName())
.withPrettyUsageName(taxItem.getPrettyUsageName())
.withQuantity(taxItem.getQuantity())
.withItemDetails("gelatic fussion")
.withCreatedDate(taxItem.getCreatedDate())
.withUpdatedDate(taxItem.getUpdatedDate())
.validate().build()
);
invoiceItems.add(taxItemDerived);
final InvoiceItem taxItemWithEffectiveRate = transactionLineDetailModel.getEffectiveRate() != null
? new PluginInvoiceItem(new Builder<>()
.withId(taxItem.getId())
.withInvoiceItemType(taxItem.getInvoiceItemType())
.withInvoiceId(taxItem.getInvoiceId())
.withAccountId(taxItem.getAccountId())
.withChildAccountId(taxItem.getChildAccountId())
.withStartDate(taxItem.getStartDate())
.withEndDate(taxItem.getEndDate())
.withAmount(taxItem.getAmount())
.withCurrency(taxItem.getCurrency())
.withDescription(taxItem.getDescription())
.withSubscriptionId(taxItem.getSubscriptionId())
.withBundleId(taxItem.getBundleId())
.withCatalogEffectiveDate(taxItem.getCatalogEffectiveDate())
.withProductName(taxItem.getProductName())
.withPrettyProductName(taxItem.getPrettyProductName())
.withPlanName(taxItem.getPlanName())
.withPrettyPlanName(taxItem.getPrettyPlanName())
.withPhaseName(taxItem.getPhaseName())
.withPrettyPhaseName(taxItem.getPrettyPhaseName())
.withRate(taxItem.getRate())
.withLinkedItemId(taxItem.getLinkedItemId())
.withUsageName(taxItem.getUsageName())
.withPrettyUsageName(taxItem.getPrettyUsageName())
.withQuantity(taxItem.getQuantity())
.withItemDetails(String.valueOf(transactionLineDetailModel.getEffectiveRate()))
.withCreatedDate(taxItem.getCreatedDate())
.withUpdatedDate(taxItem.getUpdatedDate())
.validate().build())
: taxItem;
invoiceItems.add(taxItemWithEffectiveRate);
}
}
return invoiceItems;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertNull;

public class VertexTaxCalculatorTest {

Expand Down Expand Up @@ -157,7 +158,6 @@ public void testCompute() throws Exception {
//given
given(taxResponse.getData()).willReturn(apiResponseData);
given(invoice.getInvoiceItems()).willReturn(Collections.singletonList(taxableInvoiceItem));

final boolean isDryRun = false;

//when
Expand Down Expand Up @@ -231,6 +231,40 @@ public void testTaxDescription() throws Exception {
assertEquals("CA STATE TAX", result.get(0).getDescription());
}

@Test(groups = "fast")
public void testTaxEffectiveRate() throws Exception {
//given
given(invoice.getInvoiceItems()).willReturn(Collections.singletonList(taxableInvoiceItem));
given(taxResponse.getData()).willReturn(apiResponseData);
final TaxesType taxesType = new TaxesType();
taxesType.setCalculatedTax(MOCK_TAX_AMOUNT_1_01);
given(responseLineItem.getTaxes()).willReturn(Collections.singletonList(taxesType));

//given tax effective rate is present
taxesType.setEffectiveRate(0.09975d);

//then it persisted in item details invoice item field
List<InvoiceItem> result = vertexTaxCalculator.compute(account, invoice, true, Collections.emptyList(), tenantContext);
assertEquals("0.09975", result.get(0).getItemDetails());
checkTaxItemFields(result.get(0));

//given effective rate is not present
taxesType.setEffectiveRate(null);

//then no item details persisted
result = vertexTaxCalculator.compute(account, invoice, true, Collections.emptyList(), tenantContext);
assertNull(result.get(0).getItemDetails());
checkTaxItemFields(result.get(0));
}

private void checkTaxItemFields(final InvoiceItem taxItem) {
assertEquals(InvoiceItemType.TAX, taxItem.getInvoiceItemType());
assertEquals("Tax", taxItem.getDescription());
assertEquals(INVOICE_ID, taxItem.getInvoiceId());
assertEquals(INVOICE_DATE, taxItem.getStartDate());
assertEquals(INVOICE_DATE.plusMonths(1), taxItem.getEndDate());
}

@Test(groups = "fast", expectedExceptions = {IllegalStateException.class})
public void testComputeWithAnomalousAdjustmentsException() throws Exception {
//given
Expand Down

0 comments on commit 8c3fac3

Please sign in to comment.