Skip to content

Commit

Permalink
#4599-app Error when posting a zero-sum invoice
Browse files Browse the repository at this point in the history
the fix is in FactTrxLines
Error when posting a zero-sum invoice #4599
  • Loading branch information
metas-ts committed Sep 21, 2018
1 parent 9dd6f6d commit b9fe035
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
Expand Up @@ -16,6 +16,8 @@
*****************************************************************************/
package org.compiere.acct;

import static java.math.BigDecimal.ZERO;

import java.math.BigDecimal;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
Expand Down Expand Up @@ -254,7 +256,7 @@ final boolean isCreditMemo()
@Override
public BigDecimal getBalance()
{
BigDecimal retValue = Env.ZERO;
BigDecimal retValue = ZERO;
StringBuilder sb = new StringBuilder(" [");
// Total
retValue = retValue.add(getAmount(Doc.AMTTYPE_Gross));
Expand Down Expand Up @@ -346,7 +348,7 @@ public List<Fact> createFacts(final MAcctSchema as)
|| getDocumentType().equals(DOCTYPE_ARProForma))
{
BigDecimal grossAmt = getAmount(Doc.AMTTYPE_Gross);
BigDecimal serviceAmt = Env.ZERO;
BigDecimal serviceAmt = ZERO;

// Header Charge CR
BigDecimal amt = getAmount(Doc.AMTTYPE_Charge);
Expand Down Expand Up @@ -409,12 +411,12 @@ public List<Fact> createFacts(final MAcctSchema as)
|| receivables_ID == receivablesServices_ID)
{
grossAmt = getAmount(Doc.AMTTYPE_Gross);
serviceAmt = Env.ZERO;
serviceAmt = ZERO;
}
else if (m_allLinesService)
{
serviceAmt = getAmount(Doc.AMTTYPE_Gross);
grossAmt = Env.ZERO;
grossAmt = ZERO;
}

// https://github.com/metasfresh/metasfresh/issues/4147
Expand All @@ -434,7 +436,7 @@ else if (m_allLinesService)
else if (getDocumentType().equals(DOCTYPE_ARCredit))
{
BigDecimal grossAmt = getAmount(Doc.AMTTYPE_Gross);
BigDecimal serviceAmt = Env.ZERO;
BigDecimal serviceAmt = ZERO;

// Header Charge DR
BigDecimal amt = getAmount(Doc.AMTTYPE_Charge);
Expand Down Expand Up @@ -496,12 +498,12 @@ else if (getDocumentType().equals(DOCTYPE_ARCredit))
|| receivables_ID == receivablesServices_ID)
{
grossAmt = getAmount(Doc.AMTTYPE_Gross);
serviceAmt = Env.ZERO;
serviceAmt = ZERO;
}
else if (m_allLinesService)
{
serviceAmt = getAmount(Doc.AMTTYPE_Gross);
grossAmt = Env.ZERO;
grossAmt = ZERO;
}
// https://github.com/metasfresh/metasfresh/issues/4147
// we need this line later, even if it is zero
Expand All @@ -522,7 +524,7 @@ else if (getDocumentType().equals(DOCTYPE_APInvoice)
|| getDocumentType().equals(Constants.DOCBASETYPE_AVIinvoice)) // metas-ts: treating invoice for recurrent payment like AP invoice
{
BigDecimal grossAmt = getAmount(Doc.AMTTYPE_Gross);
BigDecimal serviceAmt = Env.ZERO;
BigDecimal serviceAmt = ZERO;

// Charge DR
fact.createLine(null, getAccount(Doc.ACCTTYPE_Charge, as),
Expand Down Expand Up @@ -629,12 +631,12 @@ else if (getDocumentType().equals(DOCTYPE_APInvoice)
|| payables_ID == payablesServices_ID)
{
grossAmt = getAmount(Doc.AMTTYPE_Gross);
serviceAmt = Env.ZERO;
serviceAmt = ZERO;
}
else if (m_allLinesService)
{
serviceAmt = getAmount(Doc.AMTTYPE_Gross);
grossAmt = Env.ZERO;
grossAmt = ZERO;
}
// https://github.com/metasfresh/metasfresh/issues/4147
// we need this line later, even if it is zero
Expand All @@ -654,7 +656,7 @@ else if (m_allLinesService)
else if (getDocumentType().equals(DOCTYPE_APCredit))
{
BigDecimal grossAmt = getAmount(Doc.AMTTYPE_Gross);
BigDecimal serviceAmt = Env.ZERO;
BigDecimal serviceAmt = ZERO;
// Charge CR
fact.createLine(null, getAccount(Doc.ACCTTYPE_Charge, as),
getC_Currency_ID(), null, getAmount(Doc.AMTTYPE_Charge));
Expand Down Expand Up @@ -757,12 +759,12 @@ else if (getDocumentType().equals(DOCTYPE_APCredit))
|| payables_ID == payablesServices_ID)
{
grossAmt = getAmount(Doc.AMTTYPE_Gross);
serviceAmt = Env.ZERO;
serviceAmt = ZERO;
}
else if (m_allLinesService)
{
serviceAmt = getAmount(Doc.AMTTYPE_Gross);
grossAmt = Env.ZERO;
grossAmt = ZERO;
}
// https://github.com/metasfresh/metasfresh/issues/4147
// we need this line later, even if it is zero
Expand Down Expand Up @@ -844,7 +846,7 @@ public BigDecimal createFactCash(MAcctSchema as, Fact fact, BigDecimal multiplie
|| getDocumentType().equals(Constants.DOCBASETYPE_AVIinvoice) // metas-ts: treating invoice for recurrent payment like AP invoice
|| getDocumentType().equals(Constants.DOCBASETYPE_AEInvoice) // metas-ts: treating commission/salary invoice like AP invoice
|| getDocumentType().equals(DOCTYPE_APCredit);
BigDecimal acctAmt = Env.ZERO;
BigDecimal acctAmt = ZERO;
FactLine fl = null;
// Revenue/Cost
for (int i = 0; i < p_lines.length; i++)
Expand Down
Expand Up @@ -88,10 +88,13 @@ else if (isDR)
// https://github.com/metasfresh/metasfresh/issues/4147
// if
// * all not-zero lines are in dr and sum up to zero
// * and we have one zero line,
// then move that zero-line to cr
// * and we have at least one zero line,
// then move the last one of those zero-line to cr
// why the last: the line we add to cr defines which account is linked.
// we want to cover the case of invoices when customer receivables/vendor liability is zero and link that account
//
// ..likewise for cr
if (zeroLines.size() == 1)
if (!zeroLines.isEmpty())// if (zeroLines.size() == 1)
{
if (drLines.isEmpty())
{
Expand All @@ -100,8 +103,7 @@ else if (isDR)
.reduce(BigDecimal.ZERO, BigDecimal::add);
if (crLineSum.signum() == 0)
{
drLines.add(zeroLines.get(0));
zeroLines.clear();
drLines.add(zeroLines.remove(zeroLines.size() - 1));
}
}
else if (crLines.isEmpty())
Expand All @@ -111,8 +113,7 @@ else if (crLines.isEmpty())
.reduce(BigDecimal.ZERO, BigDecimal::add);
if (drLineSum.signum() == 0)
{
crLines.add(zeroLines.get(0));
zeroLines.clear();
crLines.add(zeroLines.remove(zeroLines.size() - 1));
}
}
}
Expand Down
Expand Up @@ -94,7 +94,7 @@ public void updateIsToClear(final I_C_Invoice_Candidate invoiceCand)
final boolean dateOrdereChanged = InterfaceWrapperHelper.isValueChanged(invoiceCand, I_C_Invoice_Candidate.COLUMNNAME_DateOrdered) && !InterfaceWrapperHelper.isNew(invoiceCand);
if (newIsToClear && dateOrdereChanged)
{
Check.assume(false, "Column I_C_Invoice_Cand." + I_C_Invoice_Candidate.COLUMNNAME_DateOrdered + " is not updatable");
Check.assume(false, "Column I_C_Invoice_Cand." + I_C_Invoice_Candidate.COLUMNNAME_DateOrdered + " is not updatable; I_C_Invoice_Cand={}", invoiceCand);
// If the column was updatable, we would have to
// *check if new and old term are the same
// *check if ICAs need update, creation or deletion and do it;
Expand Down

0 comments on commit b9fe035

Please sign in to comment.