IDEMPIERE-5616 Reverse Shipments don't post because of Not Balanced in special case (#1706)
* IDEMPIERE-5616 Reverse Shipments don't post because of Not Balanced in special case * - Add case for Inventory Move - Add explanatory comment * - Add extra cases for other documents * - uploaded a different approach --------- Co-authored-by: hengsin <hengsin@gmail.com>
This commit is contained in:
parent
4c77efecb4
commit
c29184fbf1
|
@ -317,7 +317,7 @@ public class Doc_InOut extends Doc
|
||||||
{
|
{
|
||||||
// Set AmtAcctCr from Original Shipment/Receipt
|
// Set AmtAcctCr from Original Shipment/Receipt
|
||||||
if (!cr.updateReverseLine (MInOut.Table_ID,
|
if (!cr.updateReverseLine (MInOut.Table_ID,
|
||||||
m_Reversal_ID, line.getReversalLine_ID(),Env.ONE))
|
m_Reversal_ID, line.getReversalLine_ID(),Env.ONE, dr))
|
||||||
{
|
{
|
||||||
p_Error = Msg.getMsg(getCtx(),"Original Shipment/Receipt not posted yet");
|
p_Error = Msg.getMsg(getCtx(),"Original Shipment/Receipt not posted yet");
|
||||||
return null;
|
return null;
|
||||||
|
@ -616,7 +616,7 @@ public class Doc_InOut extends Doc
|
||||||
{
|
{
|
||||||
// Set AmtAcctCr from Original Shipment/Receipt
|
// Set AmtAcctCr from Original Shipment/Receipt
|
||||||
if (!cr.updateReverseLine (MInOut.Table_ID,
|
if (!cr.updateReverseLine (MInOut.Table_ID,
|
||||||
m_Reversal_ID, line.getReversalLine_ID(),Env.ONE))
|
m_Reversal_ID, line.getReversalLine_ID(),Env.ONE, dr))
|
||||||
{
|
{
|
||||||
p_Error = Msg.getMsg(getCtx(),"Original Shipment/Receipt not posted yet");
|
p_Error = Msg.getMsg(getCtx(),"Original Shipment/Receipt not posted yet");
|
||||||
return null;
|
return null;
|
||||||
|
@ -832,7 +832,7 @@ public class Doc_InOut extends Doc
|
||||||
{
|
{
|
||||||
// Set AmtAcctCr from Original Shipment/Receipt
|
// Set AmtAcctCr from Original Shipment/Receipt
|
||||||
if (!cr.updateReverseLine (MInOut.Table_ID,
|
if (!cr.updateReverseLine (MInOut.Table_ID,
|
||||||
m_Reversal_ID, line.getReversalLine_ID(),Env.ONE))
|
m_Reversal_ID, line.getReversalLine_ID(),Env.ONE, dr))
|
||||||
{
|
{
|
||||||
p_Error = Msg.getMsg(getCtx(),"Original Receipt not posted yet");
|
p_Error = Msg.getMsg(getCtx(),"Original Receipt not posted yet");
|
||||||
return null;
|
return null;
|
||||||
|
@ -1048,7 +1048,7 @@ public class Doc_InOut extends Doc
|
||||||
{
|
{
|
||||||
// Set AmtAcctCr from Original Shipment/Receipt
|
// Set AmtAcctCr from Original Shipment/Receipt
|
||||||
if (!cr.updateReverseLine (MInOut.Table_ID,
|
if (!cr.updateReverseLine (MInOut.Table_ID,
|
||||||
m_Reversal_ID, line.getReversalLine_ID(),Env.ONE))
|
m_Reversal_ID, line.getReversalLine_ID(),Env.ONE, dr))
|
||||||
{
|
{
|
||||||
p_Error = Msg.getMsg(getCtx(),"Original Receipt not posted yet");
|
p_Error = Msg.getMsg(getCtx(),"Original Receipt not posted yet");
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -353,7 +353,7 @@ public class Doc_Inventory extends Doc
|
||||||
{
|
{
|
||||||
// Set AmtAcctCr from Original Phys.Inventory
|
// Set AmtAcctCr from Original Phys.Inventory
|
||||||
if (!cr.updateReverseLine (MInventory.Table_ID,
|
if (!cr.updateReverseLine (MInventory.Table_ID,
|
||||||
m_Reversal_ID, line.getReversalLine_ID(),Env.ONE))
|
m_Reversal_ID, line.getReversalLine_ID(),Env.ONE, dr))
|
||||||
{
|
{
|
||||||
p_Error = "Original Physical Inventory not posted yet";
|
p_Error = "Original Physical Inventory not posted yet";
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -256,7 +256,7 @@ public class Doc_MatchInv extends Doc
|
||||||
if (m_matchInv.isReversal())
|
if (m_matchInv.isReversal())
|
||||||
{
|
{
|
||||||
if (!cr.updateReverseLine (MMatchInv.Table_ID, // Amt updated
|
if (!cr.updateReverseLine (MMatchInv.Table_ID, // Amt updated
|
||||||
m_matchInv.getReversal_ID(), 0, BigDecimal.ONE))
|
m_matchInv.getReversal_ID(), 0, BigDecimal.ONE, dr))
|
||||||
{
|
{
|
||||||
p_Error = "Failed to create reversal entry";
|
p_Error = "Failed to create reversal entry";
|
||||||
return null;
|
return null;
|
||||||
|
@ -290,7 +290,7 @@ public class Doc_MatchInv extends Doc
|
||||||
if (m_matchInv.isReversal())
|
if (m_matchInv.isReversal())
|
||||||
{
|
{
|
||||||
if (!cr.updateReverseLine (MMatchInv.Table_ID, // Amt updated
|
if (!cr.updateReverseLine (MMatchInv.Table_ID, // Amt updated
|
||||||
m_matchInv.getReversal_ID(), 0, BigDecimal.ONE))
|
m_matchInv.getReversal_ID(), 0, BigDecimal.ONE, dr))
|
||||||
{
|
{
|
||||||
p_Error = "Failed to create reversal entry";
|
p_Error = "Failed to create reversal entry";
|
||||||
return null;
|
return null;
|
||||||
|
@ -769,7 +769,7 @@ public class Doc_MatchInv extends Doc
|
||||||
if (m_matchInv.isReversal())
|
if (m_matchInv.isReversal())
|
||||||
{
|
{
|
||||||
if (!cr.updateReverseLine (MMatchInv.Table_ID, // Amt updated
|
if (!cr.updateReverseLine (MMatchInv.Table_ID, // Amt updated
|
||||||
m_matchInv.getReversal_ID(), 0, BigDecimal.ONE))
|
m_matchInv.getReversal_ID(), 0, BigDecimal.ONE, dr))
|
||||||
{
|
{
|
||||||
p_Error = "Failed to create reversal entry";
|
p_Error = "Failed to create reversal entry";
|
||||||
return null;
|
return null;
|
||||||
|
@ -803,7 +803,7 @@ public class Doc_MatchInv extends Doc
|
||||||
if (m_matchInv.isReversal())
|
if (m_matchInv.isReversal())
|
||||||
{
|
{
|
||||||
if (!cr.updateReverseLine (MMatchInv.Table_ID, // Amt updated
|
if (!cr.updateReverseLine (MMatchInv.Table_ID, // Amt updated
|
||||||
m_matchInv.getReversal_ID(), 0, BigDecimal.ONE))
|
m_matchInv.getReversal_ID(), 0, BigDecimal.ONE, dr))
|
||||||
{
|
{
|
||||||
p_Error = "Failed to create reversal entry";
|
p_Error = "Failed to create reversal entry";
|
||||||
return null;
|
return null;
|
||||||
|
@ -1078,7 +1078,7 @@ public class Doc_MatchInv extends Doc
|
||||||
if (m_matchInv.isReversal())
|
if (m_matchInv.isReversal())
|
||||||
{
|
{
|
||||||
if (!cr.updateReverseLine (MMatchInv.Table_ID, // Amt updated
|
if (!cr.updateReverseLine (MMatchInv.Table_ID, // Amt updated
|
||||||
m_matchInv.getReversal_ID(), 0, BigDecimal.ONE))
|
m_matchInv.getReversal_ID(), 0, BigDecimal.ONE, dr))
|
||||||
{
|
{
|
||||||
p_Error = "Failed to create reversal entry";
|
p_Error = "Failed to create reversal entry";
|
||||||
return null;
|
return null;
|
||||||
|
@ -1112,7 +1112,7 @@ public class Doc_MatchInv extends Doc
|
||||||
if (m_matchInv.isReversal())
|
if (m_matchInv.isReversal())
|
||||||
{
|
{
|
||||||
if (!cr.updateReverseLine (MMatchInv.Table_ID, // Amt updated
|
if (!cr.updateReverseLine (MMatchInv.Table_ID, // Amt updated
|
||||||
m_matchInv.getReversal_ID(), 0, BigDecimal.ONE))
|
m_matchInv.getReversal_ID(), 0, BigDecimal.ONE, dr))
|
||||||
{
|
{
|
||||||
p_Error = "Failed to create reversal entry";
|
p_Error = "Failed to create reversal entry";
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -435,7 +435,7 @@ public class Doc_MatchPO extends Doc
|
||||||
// PPV Offset
|
// PPV Offset
|
||||||
FactLine dr = fact.createLine(null,
|
FactLine dr = fact.createLine(null,
|
||||||
getAccount(Doc.ACCTTYPE_PPVOffset, as), as.getC_Currency_ID(), Env.ONE);
|
getAccount(Doc.ACCTTYPE_PPVOffset, as), as.getC_Currency_ID(), Env.ONE);
|
||||||
if (!dr.updateReverseLine(MMatchPO.Table_ID, m_matchPO.getM_MatchPO_ID(), 0, Env.ONE))
|
if (!dr.updateReverseLine(MMatchPO.Table_ID, m_matchPO.getM_MatchPO_ID(), 0, Env.ONE, cr))
|
||||||
{
|
{
|
||||||
p_Error = Msg.getMsg(Env.getCtx(), "FailedToCreateReversalEntryForACCTTYPE_PPVOffset");
|
p_Error = Msg.getMsg(Env.getCtx(), "FailedToCreateReversalEntryForACCTTYPE_PPVOffset");
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -214,7 +214,7 @@ public class Doc_Movement extends Doc
|
||||||
{
|
{
|
||||||
// Set AmtAcctCr from Original Movement
|
// Set AmtAcctCr from Original Movement
|
||||||
if (!cr.updateReverseLine (MMovement.Table_ID,
|
if (!cr.updateReverseLine (MMovement.Table_ID,
|
||||||
m_Reversal_ID, line.getReversalLine_ID(),Env.ONE))
|
m_Reversal_ID, line.getReversalLine_ID(),Env.ONE, dr))
|
||||||
{
|
{
|
||||||
p_Error = "Original Inventory Move not posted yet";
|
p_Error = "Original Inventory Move not posted yet";
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -63,7 +63,7 @@ public final class FactLine extends X_Fact_Acct
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = -533308106857819424L;
|
private static final long serialVersionUID = -601720541421664784L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
|
@ -1110,7 +1110,6 @@ public final class FactLine extends X_Fact_Acct
|
||||||
return new_Account_ID;
|
return new_Account_ID;
|
||||||
} // createRevenueRecognition
|
} // createRevenueRecognition
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
* Update Line with reversed Original Amount in Accounting Currency.
|
* Update Line with reversed Original Amount in Accounting Currency.
|
||||||
* Also copies original dimensions like Project, etc.
|
* Also copies original dimensions like Project, etc.
|
||||||
|
@ -1123,6 +1122,26 @@ public final class FactLine extends X_Fact_Acct
|
||||||
*/
|
*/
|
||||||
public boolean updateReverseLine (int AD_Table_ID, int Record_ID, int Line_ID,
|
public boolean updateReverseLine (int AD_Table_ID, int Record_ID, int Line_ID,
|
||||||
BigDecimal multiplier)
|
BigDecimal multiplier)
|
||||||
|
{
|
||||||
|
return updateReverseLine(AD_Table_ID, Record_ID, Line_ID, multiplier, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
* Update Line with reversed Original Amount in Accounting Currency.
|
||||||
|
* Also copies original dimensions like Project, etc.
|
||||||
|
* Called from Doc_MatchInv
|
||||||
|
* @param AD_Table_ID table
|
||||||
|
* @param Record_ID record
|
||||||
|
* @param Line_ID line
|
||||||
|
* @param multiplier targetQty/documentQty
|
||||||
|
* @param otherLine reversal line created before this. if not null, this reversal should reverse the opposite sign.
|
||||||
|
* @return true if success
|
||||||
|
*
|
||||||
|
* NOTE: otherLine is required in cases where the original DR/CR postings are done in the same account
|
||||||
|
* in this case looking just for the first posting is wrong and results in a non-balanced reversal posting
|
||||||
|
*/
|
||||||
|
public boolean updateReverseLine (int AD_Table_ID, int Record_ID, int Line_ID,
|
||||||
|
BigDecimal multiplier, FactLine otherLine)
|
||||||
{
|
{
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
|
|
||||||
|
@ -1143,6 +1162,14 @@ public final class FactLine extends X_Fact_Acct
|
||||||
if (MMovement.Table_ID == AD_Table_ID)
|
if (MMovement.Table_ID == AD_Table_ID)
|
||||||
sql.append(" AND M_Locator_ID=?");
|
sql.append(" AND M_Locator_ID=?");
|
||||||
// end MZ
|
// end MZ
|
||||||
|
if (otherLine != null)
|
||||||
|
{
|
||||||
|
if (otherLine.getAmtAcctDr().signum() == 0 && otherLine.getAmtAcctCr().signum() != 0)
|
||||||
|
sql.append(" AND AmtAcctDr = 0 AND AmtAcctCr != 0 ");
|
||||||
|
else if (otherLine.getAmtAcctDr().signum() != 0 && otherLine.getAmtAcctCr().signum() == 0)
|
||||||
|
sql.append(" AND AmtAcctCr = 0 AND AmtAcctDr != 0 ");
|
||||||
|
}
|
||||||
|
|
||||||
sql.append(" ORDER BY Fact_Acct_ID");
|
sql.append(" ORDER BY Fact_Acct_ID");
|
||||||
|
|
||||||
PreparedStatement pstmt = null;
|
PreparedStatement pstmt = null;
|
||||||
|
|
Loading…
Reference in New Issue