IDEMPIERE-3983 Matched PO posting status "Deferred" never transitions to "Posted" if no matching MR is assigned

This commit is contained in:
Heng Sin Low 2019-06-19 18:21:55 +08:00
parent a4ab94895d
commit 3a6f8f08e2
1 changed files with 141 additions and 128 deletions

View File

@ -404,6 +404,14 @@ public class MMatchPO extends X_M_MatchPO
if (iLine == null && mpo.isPosted()) if (iLine == null && mpo.isPosted())
continue; continue;
} }
if (iLine != null && sLine == null && mpo.getC_InvoiceLine_ID() == 0)
{
//verify m_matchinv not created for other invoice
int cnt = DB.getSQLValue(iLine.get_TrxName(), "SELECT Count(*) FROM M_MatchInv WHERE M_InOutLine_ID="+mpo.getM_InOutLine_ID()
+" AND C_InvoiceLine_ID != "+iLine.getC_InvoiceLine_ID());
if (cnt > 0)
continue;
}
if ((iLine != null || mpo.getC_InvoiceLine_ID() > 0) && (sLine != null || mpo.getM_InOutLine_ID() > 0)) if ((iLine != null || mpo.getC_InvoiceLine_ID() > 0) && (sLine != null || mpo.getM_InOutLine_ID() > 0))
{ {
int M_InOutLine_ID = sLine != null ? sLine.getM_InOutLine_ID() : mpo.getM_InOutLine_ID(); int M_InOutLine_ID = sLine != null ? sLine.getM_InOutLine_ID() : mpo.getM_InOutLine_ID();
@ -633,16 +641,17 @@ public class MMatchPO extends X_M_MatchPO
throw new RuntimeException(msg); throw new RuntimeException(msg);
} }
//auto create m_matchinv if not created yet //auto create m_matchinv
int cnt = DB.getSQLValue(iLine.get_TrxName(), "SELECT Count(*) FROM M_MatchInv WHERE C_InvoiceLine_ID="+iLine.getC_InvoiceLine_ID());
if (cnt == 0)
{
Map<Integer, BigDecimal[]> noInvoiceLines = new HashMap<>(); Map<Integer, BigDecimal[]> noInvoiceLines = new HashMap<>();
Map<Integer, List<MMatchPO>> invoiceMatched = new HashMap<Integer, List<MMatchPO>>(); Map<Integer, List<MMatchPO>> invoiceMatched = new HashMap<Integer, List<MMatchPO>>();
List<MMatchPO> noInvoiceList = new ArrayList<MMatchPO>(); List<MMatchPO> noInvoiceList = new ArrayList<MMatchPO>();
//get all matchpo with inoutline for C_OrderLine_ID
MMatchPO[] matchPOs = MMatchPO.getOrderLine(iLine.getCtx(), C_OrderLine_ID, iLine.get_TrxName()); MMatchPO[] matchPOs = MMatchPO.getOrderLine(iLine.getCtx(), C_OrderLine_ID, iLine.get_TrxName());
for (MMatchPO matchPO : matchPOs) for (MMatchPO matchPO : matchPOs)
{ {
if (matchPO.getM_MatchPO_ID() == retValue.getM_MatchPO_ID())
continue;
if (matchPO.getM_InOutLine_ID() > 0 && matchPO.getReversal_ID() == 0) if (matchPO.getM_InOutLine_ID() > 0 && matchPO.getReversal_ID() == 0)
{ {
if (matchPO.getC_InvoiceLine_ID() == 0) if (matchPO.getC_InvoiceLine_ID() == 0)
@ -667,6 +676,7 @@ public class MMatchPO extends X_M_MatchPO
} }
} }
//sort in created sequence
Collections.sort(noInvoiceList, new Comparator<MMatchPO>() { Collections.sort(noInvoiceList, new Comparator<MMatchPO>() {
@Override @Override
public int compare(MMatchPO arg0, MMatchPO arg1) { public int compare(MMatchPO arg0, MMatchPO arg1) {
@ -675,6 +685,9 @@ public class MMatchPO extends X_M_MatchPO
: (arg0.getM_MatchPO_ID()==arg1.getM_MatchPO_ID() ? 0 : -1); : (arg0.getM_MatchPO_ID()==arg1.getM_MatchPO_ID() ? 0 : -1);
} }
}); });
//goes through all matchpo that potentially have not been matched to any invoice yet
//calculate balance that have not been matched to invoice line
for (MMatchPO matchPO : noInvoiceList) for (MMatchPO matchPO : noInvoiceList)
{ {
BigDecimal[] qtyHolder = noInvoiceLines.get(matchPO.getM_MatchPO_ID()); BigDecimal[] qtyHolder = noInvoiceLines.get(matchPO.getM_MatchPO_ID());
@ -705,6 +718,7 @@ public class MMatchPO extends X_M_MatchPO
} }
} }
//do matching
BigDecimal toMatch = retValue.getQty(); BigDecimal toMatch = retValue.getQty();
for (MMatchPO matchPO : noInvoiceList) for (MMatchPO matchPO : noInvoiceList)
{ {
@ -782,7 +796,6 @@ public class MMatchPO extends X_M_MatchPO
} }
} }
} }
}
return retValue; return retValue;
} // create } // create