Skip to content

Commit

Permalink
Added test for #40
Browse files Browse the repository at this point in the history
  • Loading branch information
phax committed Sep 21, 2021
1 parent 87119f2 commit 6bd32f3
Showing 1 changed file with 70 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.io.File;
import java.math.BigDecimal;
import java.time.temporal.ChronoUnit;

import org.junit.Test;
import org.w3c.dom.Document;
Expand Down Expand Up @@ -258,4 +259,73 @@ public void testCreateInvoiceFromScratchWithEmptyExtensionIssue38 ()
.write (aInvoice, new File ("target/dummy-invoice-with-empty-extension.xml"));
assertTrue (eSuccess.isSuccess ());
}

@Test
public void testCreateInvoiceFromScratchNoSecondFractionIssue40 ()
{
final String sCurrency = "EUR";

// Create domain object
final InvoiceType aInvoice = new InvoiceType ();

// Fill it
aInvoice.setID ("Dummy Invoice number");
aInvoice.setIssueDate (PDTFactory.getCurrentXMLOffsetDateUTC ());
aInvoice.setIssueTime (PDTFactory.getCurrentLocalTime ().truncatedTo (ChronoUnit.SECONDS));

final SupplierPartyType aSupplier = new SupplierPartyType ();
aInvoice.setAccountingSupplierParty (aSupplier);

final CustomerPartyType aCustomer = new CustomerPartyType ();
aInvoice.setAccountingCustomerParty (aCustomer);

final MonetaryTotalType aMT = new MonetaryTotalType ();
aMT.setPayableAmount (BigDecimal.TEN).setCurrencyID (sCurrency);
aInvoice.setLegalMonetaryTotal (aMT);

final InvoiceLineType aLine = new InvoiceLineType ();
aLine.setID ("1");

final ItemType aItem = new ItemType ();
aLine.setItem (aItem);

aLine.setLineExtensionAmount (BigDecimal.TEN).setCurrencyID (sCurrency);

aInvoice.addInvoiceLine (aLine);

// Add some TaxTotal
{
final TaxSubtotalType aTaxSubtotal = new TaxSubtotalType ();
aTaxSubtotal.setTaxableAmount (BigDecimal.TEN).setCurrencyID (sCurrency);
aTaxSubtotal.setTaxAmount (BigDecimal.TEN).setCurrencyID (sCurrency);

final TaxCategoryType aTaxCategory = new TaxCategoryType ();
final IDType aTCID = new IDType ();
aTCID.setSchemeID ("UNCL5305");
aTCID.setSchemeAgencyID ("6");
aTCID.setValue ("Z");
aTaxCategory.setID (aTCID);

aTaxCategory.setPercent (BigDecimal.TEN);

final TaxSchemeType aTaxScheme = new TaxSchemeType ();
final IDType aTSID = new IDType ();
aTSID.setSchemeID ("UNCL5305");
aTSID.setSchemeAgencyID ("6");
aTSID.setValue ("VAT");
aTaxScheme.setID (aTSID);
aTaxCategory.setTaxScheme (aTaxScheme);

aTaxSubtotal.setTaxCategory (aTaxCategory);

final TaxTotalType aTaxTotal = new TaxTotalType ();
aTaxTotal.setTaxAmount (BigDecimal.TEN).setCurrencyID (sCurrency);
aTaxTotal.addTaxSubtotal (aTaxSubtotal);
aInvoice.addTaxTotal (aTaxTotal);
}

// Write to disk
final ESuccess eSuccess = UBL21Writer.invoice ().write (aInvoice, new File ("target/dummy-invoice-no-second-fraction.xml"));
assertTrue (eSuccess.isSuccess ());
}
}

0 comments on commit 6bd32f3

Please sign in to comment.