IDEMPIERE-2459 Calculated Child Taxes Amount Sum is not equal to Parent Tax Amount Sum (cause wrong grand total)

This commit is contained in:
Carlos Ruiz 2017-02-14 08:40:25 +01:00
parent 358328d0c9
commit 60244ffc97
1 changed files with 24 additions and 16 deletions

View File

@ -256,24 +256,32 @@ public class MTax extends X_C_Tax
if (isZeroTax()) if (isZeroTax())
return Env.ZERO; return Env.ZERO;
BigDecimal multiplier = getRate().divide(Env.ONEHUNDRED, 12, BigDecimal.ROUND_HALF_UP); MTax[] taxarray;
if (isSummary())
taxarray = getChildTaxes(false);
else
taxarray = new MTax[] {this};
BigDecimal tax = null; BigDecimal tax = Env.ZERO;
for (MTax taxc : taxarray) {
BigDecimal multiplier = taxc.getRate().divide(Env.ONEHUNDRED, 12, BigDecimal.ROUND_HALF_UP);
if (!taxIncluded) // $100 * 6 / 100 == $6 == $100 * 0.06 if (!taxIncluded) // $100 * 6 / 100 == $6 == $100 * 0.06
{ {
tax = amount.multiply (multiplier); BigDecimal itax = amount.multiply(multiplier).setScale(scale, BigDecimal.ROUND_HALF_UP);
tax = tax.add(itax);
} }
else // $106 - ($106 / (100+6)/100) == $6 == $106 - ($106/1.06) else // $106 - ($106 / (100+6)/100) == $6 == $106 - ($106/1.06)
{ {
multiplier = multiplier.add(Env.ONE); multiplier = multiplier.add(Env.ONE);
BigDecimal base = amount.divide(multiplier, 12, BigDecimal.ROUND_HALF_UP); BigDecimal base = amount.divide(multiplier, 12, BigDecimal.ROUND_HALF_UP);
tax = amount.subtract(base); BigDecimal itax = amount.subtract(base).setScale(scale, BigDecimal.ROUND_HALF_UP);
tax = tax.add(itax);
}
} }
BigDecimal finalTax = tax.setScale(scale, BigDecimal.ROUND_HALF_UP);
if (log.isLoggable(Level.FINE)) log.fine("calculateTax " + amount if (log.isLoggable(Level.FINE)) log.fine("calculateTax " + amount
+ " (incl=" + taxIncluded + ",mult=" + multiplier + ",scale=" + scale + " (incl=" + taxIncluded + ",scale=" + scale
+ ") = " + finalTax + " [" + tax + "]"); + ") = " + tax + " [" + tax + "]");
return finalTax; return tax;
} // calculateTax } // calculateTax
@Override @Override