From b1aabc6c789037edad6bea940d6f2597e455aee1 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Thu, 17 Mar 2016 00:58:46 +0100 Subject: [PATCH] IDEMPIERE-3054 Issue with summary tax / fix roundings on posting for summary taxes --- .../src/org/compiere/acct/Doc_Invoice.java | 56 ++++++++++++++++--- 1 file changed, 47 insertions(+), 9 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/acct/Doc_Invoice.java b/org.adempiere.base/src/org/compiere/acct/Doc_Invoice.java index 03bb9bb554..5ff738f3b9 100644 --- a/org.adempiere.base/src/org/compiere/acct/Doc_Invoice.java +++ b/org.adempiere.base/src/org/compiere/acct/Doc_Invoice.java @@ -183,14 +183,42 @@ public class Doc_Invoice extends Doc BigDecimal LineNetAmtTax = tax.calculateTax(LineNetAmt, true, getStdPrecision()); if (log.isLoggable(Level.FINE)) log.fine("LineNetAmt=" + LineNetAmt + " - Tax=" + LineNetAmtTax); LineNetAmt = LineNetAmt.subtract(LineNetAmtTax); - for (int t = 0; t < m_taxes.length; t++) - { - if (m_taxes[t].getC_Tax_ID() == C_Tax_ID) + + if (tax.isSummary()) { + BigDecimal sumChildLineNetAmtTax = Env.ZERO; + DocTax taxToApplyDiff = null; + for (MTax childTax : tax.getChildTaxes(false)) { + if (!childTax.isZeroTax()) + { + BigDecimal childLineNetAmtTax = childTax.calculateTax(LineNetAmt, false, getStdPrecision()); + if (log.isLoggable(Level.FINE)) log.fine("LineNetAmt=" + LineNetAmt + " - Child Tax=" + childLineNetAmtTax); + for (int t = 0; t < m_taxes.length; t++) + { + if (m_taxes[t].getC_Tax_ID() == childTax.getC_Tax_ID()) + { + m_taxes[t].addIncludedTax(childLineNetAmtTax); + taxToApplyDiff = m_taxes[t]; + sumChildLineNetAmtTax = sumChildLineNetAmtTax.add(childLineNetAmtTax); + break; + } + } + } + } + BigDecimal diffChildVsSummary = LineNetAmtTax.subtract(sumChildLineNetAmtTax); + if (diffChildVsSummary.signum() != 0 && taxToApplyDiff != null) { + taxToApplyDiff.addIncludedTax(diffChildVsSummary); + } + } else { + for (int t = 0; t < m_taxes.length; t++) { - m_taxes[t].addIncludedTax(LineNetAmtTax); - break; + if (m_taxes[t].getC_Tax_ID() == C_Tax_ID) + { + m_taxes[t].addIncludedTax(LineNetAmtTax); + break; + } } } + BigDecimal PriceListTax = tax.calculateTax(PriceList, true, getStdPrecision()); PriceList = PriceList.subtract(PriceListTax); } @@ -220,10 +248,20 @@ public class Doc_Invoice extends Doc BigDecimal diff = m_taxes[i].getIncludedTaxDifference(); for (int j = 0; j < dls.length; j++) { - if (dls[j].getC_Tax_ID() == m_taxes[i].getC_Tax_ID()) - { - dls[j].setLineNetAmtDifference(diff); - break; + MTax lineTax = MTax.get(getCtx(), dls[j].getC_Tax_ID()); + MTax[] composingTaxes = null; + if (lineTax.isSummary()) { + composingTaxes = lineTax.getChildTaxes(false); + } else { + composingTaxes = new MTax[1]; + composingTaxes[0] = lineTax; + } + for (MTax mTax : composingTaxes) { + if (mTax.getC_Tax_ID() == m_taxes[i].getC_Tax_ID()) + { + dls[j].setLineNetAmtDifference(diff); + break; + } } } // for all lines } // tax difference