From 9014e90652dae445e1e63b2aed19039f7521256f Mon Sep 17 00:00:00 2001 From: dantam Date: Tue, 26 Jan 2016 17:25:08 +0100 Subject: [PATCH] IDEMPIERE-3012 - Reversed MatchPO messes up matching --- org.adempiere.base/src/org/compiere/model/MMatchPO.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/model/MMatchPO.java b/org.adempiere.base/src/org/compiere/model/MMatchPO.java index 87458d8ad4..0a68c9ef53 100644 --- a/org.adempiere.base/src/org/compiere/model/MMatchPO.java +++ b/org.adempiere.base/src/org/compiere/model/MMatchPO.java @@ -345,7 +345,7 @@ public class MMatchPO extends X_M_MatchPO MInOutLine sLine, int C_OrderLine_ID, Timestamp dateTrx, BigDecimal qty, String trxName) { MMatchPO retValue = null; - String sql = "SELECT * FROM M_MatchPO WHERE C_OrderLine_ID=? ORDER BY M_MatchPO_ID"; + String sql = "SELECT * FROM M_MatchPO WHERE C_OrderLine_ID=? and Reversal_ID IS NULL ORDER BY M_MatchPO_ID"; PreparedStatement pstmt = null; ResultSet rs = null; try @@ -932,13 +932,13 @@ public class MMatchPO extends X_M_MatchPO if (validateOrderedQty) { MOrderLine line = new MOrderLine(getCtx(), getC_OrderLine_ID(), get_TrxName()); - BigDecimal invoicedQty = DB.getSQLValueBD(get_TrxName(), "SELECT Coalesce(SUM(Qty),0) FROM M_MatchPO WHERE C_InvoiceLine_ID > 0 and C_OrderLine_ID=?" , getC_OrderLine_ID()); + BigDecimal invoicedQty = DB.getSQLValueBD(get_TrxName(), "SELECT Coalesce(SUM(Qty),0) FROM M_MatchPO WHERE C_InvoiceLine_ID > 0 and C_OrderLine_ID=? AND Reversal_ID IS NULL" , getC_OrderLine_ID()); if (invoicedQty != null && invoicedQty.compareTo(line.getQtyOrdered()) > 0) { throw new IllegalStateException("Total matched invoiced qty > ordered qty. MatchedInvoicedQty="+invoicedQty+", OrderedQty="+line.getQtyOrdered()+", Line="+line); } - BigDecimal deliveredQty = DB.getSQLValueBD(get_TrxName(), "SELECT Coalesce(SUM(Qty),0) FROM M_MatchPO WHERE M_InOutLine_ID > 0 and C_OrderLine_ID=?" , getC_OrderLine_ID()); + BigDecimal deliveredQty = DB.getSQLValueBD(get_TrxName(), "SELECT Coalesce(SUM(Qty),0) FROM M_MatchPO WHERE M_InOutLine_ID > 0 and C_OrderLine_ID=? AND Reversal_ID IS NULL" , getC_OrderLine_ID()); if (deliveredQty != null && deliveredQty.compareTo(line.getQtyOrdered()) > 0) { throw new IllegalStateException("Total matched delivered qty > ordered qty. MatchedDeliveredQty="+deliveredQty+", OrderedQty="+line.getQtyOrdered()+", Line="+line);