manually applying @rchilumukoti patch, closes #491 (I hope)

This commit is contained in:
jstaerk
2024-10-03 12:04:29 +02:00
parent 70f89bb051
commit 36c6546551
3 changed files with 25 additions and 12 deletions

View File

@@ -1,7 +1,7 @@
- 481
- 494
- 391
-
- 491
2.14.0
=======

View File

@@ -37,7 +37,7 @@ public class LineCalculator {
BigDecimal vatPercent = currentItem.getProduct().getVATPercent();
if (vatPercent == null)
vatPercent = BigDecimal.ZERO;
BigDecimal multiplicator = vatPercent.divide(BigDecimal.valueOf(100));
BigDecimal multiplicator = vatPercent.divide(BigDecimal.valueOf(100), RoundingMode.HALF_UP);
priceGross = currentItem.getPrice(); // see https://github.com/ZUGFeRD/mustangproject/issues/159
price = priceGross.subtract(allowance).add(charge);
itemTotalNetAmount = currentItem.getQuantity().multiply(getPrice()).divide(currentItem.getBasisQuantity())

View File

@@ -17,14 +17,14 @@ import java.text.SimpleDateFormat;
*
*/
public class CalculationTest {
private static final Logger LOGGER = LoggerFactory.getLogger (CalculationTest.class);
private static final Logger LOGGER = LoggerFactory.getLogger(CalculationTest.class);
@Test
public void testLineCalculator_simpleAmounts_resultInValidVATAmount() {
final IZUGFeRDExportableProduct product = new IZUGFeRDExportableProductImpl().setVatPercent(valueOf(16));
final IZUGFeRDExportableItem currentItem = new IZUGFeRDExportableItemImpl().setPrice(valueOf(100))
.setQuantity(TEN)
.setProduct(product);
.setQuantity(TEN)
.setProduct(product);
final LineCalculator calculator = new LineCalculator(currentItem);
@@ -41,9 +41,9 @@ public class CalculationTest {
final IZUGFeRDAllowanceCharge allowance = new IZUGFeRDAllowanceChargeImpl().setTotalAmount(valueOf(14.8730));
final IZUGFeRDExportableItem currentItem = new IZUGFeRDExportableItemImpl().setPrice(valueOf(148.73))
.setQuantity(valueOf(12))
.setItemAllowances(new IZUGFeRDAllowanceCharge[]{allowance})
.setProduct(product);
.setQuantity(valueOf(12))
.setItemAllowances(new IZUGFeRDAllowanceCharge[]{allowance})
.setProduct(product);
final LineCalculator calculator = new LineCalculator(currentItem);
@@ -60,10 +60,10 @@ public class CalculationTest {
// 20 % charge
final IZUGFeRDAllowanceCharge charge = new IZUGFeRDAllowanceChargeImpl().setTotalAmount(valueOf(29.746));
final IZUGFeRDExportableItem currentItem = new IZUGFeRDExportableItemImpl().setPrice(valueOf(148.73))
.setQuantity(valueOf(12))
.setItemAllowances(new IZUGFeRDAllowanceCharge[]{allowance})
.setItemCharges(new IZUGFeRDAllowanceCharge[]{charge})
.setProduct(product);
.setQuantity(valueOf(12))
.setItemAllowances(new IZUGFeRDAllowanceCharge[]{allowance})
.setItemCharges(new IZUGFeRDAllowanceCharge[]{charge})
.setProduct(product);
final LineCalculator calculator = new LineCalculator(currentItem);
@@ -187,5 +187,18 @@ public class CalculationTest {
assertEquals(valueOf(101.86).stripTrailingZeros(), calculator.getGrandTotal().stripTrailingZeros());
}
/**
* LineCalculator should not throw an exception when calculating a non-terminating decimal expansion
*/
@Test
public void testNonTerminatingDecimalExpansion() {
final Product product = new Product();
final IZUGFeRDExportableItem currentItem = new Item().setPrice(valueOf(386.52))
.setQuantity(BigDecimal.valueOf(31))
.setBasisQuantity(BigDecimal.valueOf(366))
.setProduct(product);
final LineCalculator calculator = new LineCalculator(currentItem);
assertEquals(BigDecimal.valueOf(32.74), calculator.getItemTotalNetAmount());
}
}