MInOutConfirm:
BF [ 2800460 ] System generate Material Receipt with no lines https://sourceforge.net/tracker/?func=detail&atid=879332&aid=2800460&group_id=176962 BF [ 2791635 ] Use saveEx whenever is possible https://sourceforge.net/tracker/?func=detail&atid=879335&aid=2791635&group_id=176962 BF [ 1874419 ] JDBC Statement not close in a finally block https://sourceforge.net/tracker/?func=detail&atid=879332&aid=1874419&group_id=176962
This commit is contained in:
parent
4c87aebb13
commit
dc38e4d827
|
@ -18,17 +18,16 @@ package org.compiere.model;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.ArrayList;
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import org.adempiere.exceptions.AdempiereException;
|
||||||
import org.compiere.process.DocAction;
|
import org.compiere.process.DocAction;
|
||||||
import org.compiere.process.DocumentEngine;
|
import org.compiere.process.DocumentEngine;
|
||||||
import org.compiere.util.CLogger;
|
import org.compiere.util.CLogger;
|
||||||
import org.compiere.util.DB;
|
|
||||||
import org.compiere.util.Env;
|
import org.compiere.util.Env;
|
||||||
import org.compiere.util.Msg;
|
import org.compiere.util.Msg;
|
||||||
|
|
||||||
|
@ -37,6 +36,10 @@ import org.compiere.util.Msg;
|
||||||
*
|
*
|
||||||
* @author Jorg Janke
|
* @author Jorg Janke
|
||||||
* @version $Id: MInOutConfirm.java,v 1.3 2006/07/30 00:51:03 jjanke Exp $
|
* @version $Id: MInOutConfirm.java,v 1.3 2006/07/30 00:51:03 jjanke Exp $
|
||||||
|
*
|
||||||
|
* @author Teo Sarca, www.arhipac.ro
|
||||||
|
* <li>BF [ 2800460 ] System generate Material Receipt with no lines
|
||||||
|
* https://sourceforge.net/tracker/?func=detail&atid=879332&aid=2800460&group_id=176962
|
||||||
*/
|
*/
|
||||||
public class MInOutConfirm extends X_M_InOutConfirm implements DocAction
|
public class MInOutConfirm extends X_M_InOutConfirm implements DocAction
|
||||||
{
|
{
|
||||||
|
@ -69,14 +72,14 @@ public class MInOutConfirm extends X_M_InOutConfirm implements DocAction
|
||||||
}
|
}
|
||||||
|
|
||||||
MInOutConfirm confirm = new MInOutConfirm (ship, confirmType);
|
MInOutConfirm confirm = new MInOutConfirm (ship, confirmType);
|
||||||
confirm.save(ship.get_TrxName());
|
confirm.saveEx();
|
||||||
MInOutLine[] shipLines = ship.getLines(false);
|
MInOutLine[] shipLines = ship.getLines(false);
|
||||||
for (int i = 0; i < shipLines.length; i++)
|
for (int i = 0; i < shipLines.length; i++)
|
||||||
{
|
{
|
||||||
MInOutLine sLine = shipLines[i];
|
MInOutLine sLine = shipLines[i];
|
||||||
MInOutLineConfirm cLine = new MInOutLineConfirm (confirm);
|
MInOutLineConfirm cLine = new MInOutLineConfirm (confirm);
|
||||||
cLine.setInOutLine(sLine);
|
cLine.setInOutLine(sLine);
|
||||||
cLine.save(ship.get_TrxName());
|
cLine.saveEx();
|
||||||
}
|
}
|
||||||
s_log.info("New: " + confirm);
|
s_log.info("New: " + confirm);
|
||||||
return confirm;
|
return confirm;
|
||||||
|
@ -148,35 +151,10 @@ public class MInOutConfirm extends X_M_InOutConfirm implements DocAction
|
||||||
set_TrxName(m_lines, get_TrxName());
|
set_TrxName(m_lines, get_TrxName());
|
||||||
return m_lines;
|
return m_lines;
|
||||||
}
|
}
|
||||||
String sql = "SELECT * FROM M_InOutLineConfirm "
|
final String whereClause = MInOutLineConfirm.COLUMNNAME_M_InOutConfirm_ID+"=?";
|
||||||
+ "WHERE M_InOutConfirm_ID=?";
|
List<MInOutLineConfirm> list = new Query(getCtx(), MInOutLineConfirm.Table_Name, whereClause, get_TrxName())
|
||||||
ArrayList<MInOutLineConfirm> list = new ArrayList<MInOutLineConfirm>();
|
.setParameters(new Object[]{getM_InOutConfirm_ID()})
|
||||||
PreparedStatement pstmt = null;
|
.list();
|
||||||
try
|
|
||||||
{
|
|
||||||
pstmt = DB.prepareStatement (sql, get_TrxName());
|
|
||||||
pstmt.setInt (1, getM_InOutConfirm_ID());
|
|
||||||
ResultSet rs = pstmt.executeQuery ();
|
|
||||||
while (rs.next ())
|
|
||||||
list.add(new MInOutLineConfirm(getCtx(), rs, get_TrxName()));
|
|
||||||
rs.close ();
|
|
||||||
pstmt.close ();
|
|
||||||
pstmt = null;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
log.log(Level.SEVERE, sql, e);
|
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (pstmt != null)
|
|
||||||
pstmt.close ();
|
|
||||||
pstmt = null;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
pstmt = null;
|
|
||||||
}
|
|
||||||
m_lines = new MInOutLineConfirm[list.size ()];
|
m_lines = new MInOutLineConfirm[list.size ()];
|
||||||
list.toArray (m_lines);
|
list.toArray (m_lines);
|
||||||
return m_lines;
|
return m_lines;
|
||||||
|
@ -442,14 +420,14 @@ public class MInOutConfirm extends X_M_InOutConfirm implements DocAction
|
||||||
if (confirmLine.isFullyConfirmed())
|
if (confirmLine.isFullyConfirmed())
|
||||||
{
|
{
|
||||||
confirmLine.setProcessed(true);
|
confirmLine.setProcessed(true);
|
||||||
confirmLine.save(get_TrxName());
|
confirmLine.saveEx();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (createDifferenceDoc (inout, confirmLine))
|
if (createDifferenceDoc (inout, confirmLine))
|
||||||
{
|
{
|
||||||
confirmLine.setProcessed(true);
|
confirmLine.setProcessed(true);
|
||||||
confirmLine.save(get_TrxName());
|
confirmLine.saveEx();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -491,15 +469,7 @@ public class MInOutConfirm extends X_M_InOutConfirm implements DocAction
|
||||||
*/
|
*/
|
||||||
private void splitInOut (MInOut original, int C_DocType_ID, MInOutLineConfirm[] confirmLines)
|
private void splitInOut (MInOut original, int C_DocType_ID, MInOutLineConfirm[] confirmLines)
|
||||||
{
|
{
|
||||||
MInOut split = new MInOut (original, C_DocType_ID, original.getMovementDate());
|
MInOut split = null;
|
||||||
split.addDescription("Splitted from " + original.getDocumentNo());
|
|
||||||
split.setIsInDispute(true);
|
|
||||||
if (!split.save(get_TrxName()))
|
|
||||||
throw new IllegalStateException("Cannot save Split");
|
|
||||||
original.addDescription("Split: " + split.getDocumentNo());
|
|
||||||
if (!original.save(get_TrxName()))
|
|
||||||
throw new IllegalStateException("Cannot update original Shipment");
|
|
||||||
|
|
||||||
// Go through confirmations
|
// Go through confirmations
|
||||||
for (int i = 0; i < confirmLines.length; i++)
|
for (int i = 0; i < confirmLines.length; i++)
|
||||||
{
|
{
|
||||||
|
@ -511,6 +481,17 @@ public class MInOutConfirm extends X_M_InOutConfirm implements DocAction
|
||||||
MInOutLine oldLine = confirmLine.getLine();
|
MInOutLine oldLine = confirmLine.getLine();
|
||||||
log.fine("Qty=" + differenceQty + ", Old=" + oldLine);
|
log.fine("Qty=" + differenceQty + ", Old=" + oldLine);
|
||||||
//
|
//
|
||||||
|
// Create Header
|
||||||
|
if (split == null)
|
||||||
|
{
|
||||||
|
split = new MInOut (original, C_DocType_ID, original.getMovementDate());
|
||||||
|
split.addDescription("Splitted from " + original.getDocumentNo());
|
||||||
|
split.setIsInDispute(true);
|
||||||
|
split.saveEx();
|
||||||
|
original.addDescription("Split: " + split.getDocumentNo());
|
||||||
|
original.saveEx();
|
||||||
|
}
|
||||||
|
//
|
||||||
MInOutLine splitLine = new MInOutLine (split);
|
MInOutLine splitLine = new MInOutLine (split);
|
||||||
splitLine.setC_OrderLine_ID(oldLine.getC_OrderLine_ID());
|
splitLine.setC_OrderLine_ID(oldLine.getC_OrderLine_ID());
|
||||||
splitLine.setC_UOM_ID(oldLine.getC_UOM_ID());
|
splitLine.setC_UOM_ID(oldLine.getC_UOM_ID());
|
||||||
|
@ -525,27 +506,31 @@ public class MInOutConfirm extends X_M_InOutConfirm implements DocAction
|
||||||
splitLine.addDescription("Split: from " + oldLine.getMovementQty());
|
splitLine.addDescription("Split: from " + oldLine.getMovementQty());
|
||||||
// Qtys
|
// Qtys
|
||||||
splitLine.setQty(differenceQty); // Entered/Movement
|
splitLine.setQty(differenceQty); // Entered/Movement
|
||||||
if (!splitLine.save(get_TrxName()))
|
splitLine.saveEx();
|
||||||
throw new IllegalStateException("Cannot save Split Line");
|
|
||||||
// Old
|
// Old
|
||||||
oldLine.addDescription("Splitted: from " + oldLine.getMovementQty());
|
oldLine.addDescription("Splitted: from " + oldLine.getMovementQty());
|
||||||
oldLine.setQty(oldLine.getMovementQty().subtract(differenceQty));
|
oldLine.setQty(oldLine.getMovementQty().subtract(differenceQty));
|
||||||
if (!oldLine.save(get_TrxName()))
|
oldLine.saveEx();
|
||||||
throw new IllegalStateException("Cannot save Splited Line");
|
|
||||||
// Update Confirmation Line
|
// Update Confirmation Line
|
||||||
confirmLine.setTargetQty(confirmLine.getTargetQty().subtract(differenceQty));
|
confirmLine.setTargetQty(confirmLine.getTargetQty().subtract(differenceQty));
|
||||||
confirmLine.setDifferenceQty(Env.ZERO);
|
confirmLine.setDifferenceQty(Env.ZERO);
|
||||||
if (!confirmLine.save(get_TrxName()))
|
confirmLine.saveEx();
|
||||||
throw new IllegalStateException("Cannot save Split Confirmation");
|
|
||||||
} // for all confirmations
|
} // for all confirmations
|
||||||
|
|
||||||
|
// Nothing to split
|
||||||
|
if (split == null)
|
||||||
|
{
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
m_processMsg = "Split @M_InOut_ID@=" + split.getDocumentNo()
|
m_processMsg = "Split @M_InOut_ID@=" + split.getDocumentNo()
|
||||||
+ " - @M_InOutConfirm_ID@=";
|
+ " - @M_InOutConfirm_ID@=";
|
||||||
|
|
||||||
// Create Dispute Confirmation
|
// Create Dispute Confirmation
|
||||||
split.processIt(DocAction.ACTION_Prepare);
|
if (!split.processIt(DocAction.ACTION_Prepare))
|
||||||
|
throw new AdempiereException(split.getProcessMsg());
|
||||||
// split.createConfirmation();
|
// split.createConfirmation();
|
||||||
split.save(get_TrxName());
|
split.saveEx();
|
||||||
MInOutConfirm[] splitConfirms = split.getConfirmations(true);
|
MInOutConfirm[] splitConfirms = split.getConfirmations(true);
|
||||||
if (splitConfirms.length > 0)
|
if (splitConfirms.length > 0)
|
||||||
{
|
{
|
||||||
|
@ -561,7 +546,7 @@ public class MInOutConfirm extends X_M_InOutConfirm implements DocAction
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
splitConfirms[index].setIsInDispute(true);
|
splitConfirms[index].setIsInDispute(true);
|
||||||
splitConfirms[index].save(get_TrxName());
|
splitConfirms[index].saveEx();
|
||||||
m_processMsg += splitConfirms[index].getDocumentNo();
|
m_processMsg += splitConfirms[index].getDocumentNo();
|
||||||
// Set Lines to unconfirmed
|
// Set Lines to unconfirmed
|
||||||
MInOutLineConfirm[] splitConfirmLines = splitConfirms[index].getLines(false);
|
MInOutLineConfirm[] splitConfirmLines = splitConfirms[index].getLines(false);
|
||||||
|
@ -570,7 +555,7 @@ public class MInOutConfirm extends X_M_InOutConfirm implements DocAction
|
||||||
MInOutLineConfirm splitConfirmLine = splitConfirmLines[i];
|
MInOutLineConfirm splitConfirmLine = splitConfirmLines[i];
|
||||||
splitConfirmLine.setScrappedQty(Env.ZERO);
|
splitConfirmLine.setScrappedQty(Env.ZERO);
|
||||||
splitConfirmLine.setConfirmedQty(Env.ZERO);
|
splitConfirmLine.setConfirmedQty(Env.ZERO);
|
||||||
splitConfirmLine.save(get_TrxName());
|
splitConfirmLine.saveEx();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -601,11 +586,7 @@ public class MInOutConfirm extends X_M_InOutConfirm implements DocAction
|
||||||
m_creditMemo = new MInvoice (inout, null);
|
m_creditMemo = new MInvoice (inout, null);
|
||||||
m_creditMemo.setDescription(Msg.translate(getCtx(), "M_InOutConfirm_ID") + " " + getDocumentNo());
|
m_creditMemo.setDescription(Msg.translate(getCtx(), "M_InOutConfirm_ID") + " " + getDocumentNo());
|
||||||
m_creditMemo.setC_DocTypeTarget_ID(MDocType.DOCBASETYPE_APCreditMemo);
|
m_creditMemo.setC_DocTypeTarget_ID(MDocType.DOCBASETYPE_APCreditMemo);
|
||||||
if (!m_creditMemo.save(get_TrxName()))
|
m_creditMemo.saveEx();
|
||||||
{
|
|
||||||
m_processMsg += "Credit Memo not created";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
setC_Invoice_ID(m_creditMemo.getC_Invoice_ID());
|
setC_Invoice_ID(m_creditMemo.getC_Invoice_ID());
|
||||||
}
|
}
|
||||||
MInvoiceLine line = new MInvoiceLine (m_creditMemo);
|
MInvoiceLine line = new MInvoiceLine (m_creditMemo);
|
||||||
|
@ -616,11 +597,7 @@ public class MInOutConfirm extends X_M_InOutConfirm implements DocAction
|
||||||
}
|
}
|
||||||
// Note: confirmation is always in the qty according to the product UOM
|
// Note: confirmation is always in the qty according to the product UOM
|
||||||
line.setQty(confirm.getDifferenceQty()); // Entered/Invoiced
|
line.setQty(confirm.getDifferenceQty()); // Entered/Invoiced
|
||||||
if (!line.save(get_TrxName()))
|
line.saveEx();
|
||||||
{
|
|
||||||
m_processMsg += "Credit Memo Line not created";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
confirm.setC_InvoiceLine_ID(line.getC_InvoiceLine_ID());
|
confirm.setC_InvoiceLine_ID(line.getC_InvoiceLine_ID());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -631,13 +608,9 @@ public class MInOutConfirm extends X_M_InOutConfirm implements DocAction
|
||||||
if (m_inventory == null)
|
if (m_inventory == null)
|
||||||
{
|
{
|
||||||
MWarehouse wh = MWarehouse.get(getCtx(), inout.getM_Warehouse_ID());
|
MWarehouse wh = MWarehouse.get(getCtx(), inout.getM_Warehouse_ID());
|
||||||
m_inventory = new MInventory (wh);
|
m_inventory = new MInventory (wh, get_TrxName());
|
||||||
m_inventory.setDescription(Msg.translate(getCtx(), "M_InOutConfirm_ID") + " " + getDocumentNo());
|
m_inventory.setDescription(Msg.translate(getCtx(), "M_InOutConfirm_ID") + " " + getDocumentNo());
|
||||||
if (!m_inventory.save(get_TrxName()))
|
m_inventory.saveEx();
|
||||||
{
|
|
||||||
m_processMsg += "Inventory not created";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
setM_Inventory_ID(m_inventory.getM_Inventory_ID());
|
setM_Inventory_ID(m_inventory.getM_Inventory_ID());
|
||||||
}
|
}
|
||||||
MInOutLine ioLine = confirm.getLine();
|
MInOutLine ioLine = confirm.getLine();
|
||||||
|
|
|
@ -109,15 +109,26 @@ public class MInventory extends X_M_Inventory implements DocAction
|
||||||
} // MInventory
|
} // MInventory
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Warehouse Constructor
|
* Warehouse Constructor
|
||||||
* @param wh warehouse
|
* @param wh warehouse
|
||||||
|
* @deprecated since 3.5.3a . Please use {@link #MInventory(MWarehouse, String)}.
|
||||||
*/
|
*/
|
||||||
public MInventory (MWarehouse wh)
|
public MInventory (MWarehouse wh)
|
||||||
{
|
{
|
||||||
this (wh.getCtx(), 0, wh.get_TrxName());
|
this(wh, wh.get_TrxName());
|
||||||
|
} // MInventory
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Warehouse Constructor
|
||||||
|
* @param wh
|
||||||
|
* @param trxName
|
||||||
|
*/
|
||||||
|
public MInventory (MWarehouse wh, String trxName)
|
||||||
|
{
|
||||||
|
this (wh.getCtx(), 0, trxName);
|
||||||
setClientOrg(wh);
|
setClientOrg(wh);
|
||||||
setM_Warehouse_ID(wh.getM_Warehouse_ID());
|
setM_Warehouse_ID(wh.getM_Warehouse_ID());
|
||||||
} // MInventory
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Lines */
|
/** Lines */
|
||||||
|
|
Loading…
Reference in New Issue