Bring in Manufacturing Light code from Adaxa / Paul Bowden

Refs #44. Improve exception handling on production create lines. Prevent production lines for same locator/asi being split
changeset 6170	1b6c87d57f92
This commit is contained in:
Dirk Niemeyer 2012-08-06 09:27:17 +02:00
parent d00cfa2ad5
commit 0785915c7b
2 changed files with 37 additions and 23 deletions

View File

@ -8,6 +8,7 @@ import java.util.ArrayList;
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.model.MAttributeSetInstance; import org.compiere.model.MAttributeSetInstance;
import org.compiere.model.MOrderLine; import org.compiere.model.MOrderLine;
import org.compiere.model.MProduct; import org.compiere.model.MProduct;
@ -52,11 +53,12 @@ public class MProduction extends X_M_Production {
+ "WHERE pl.M_Production_ID = ?"; + "WHERE pl.M_Production_ID = ?";
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement(sql, get_TrxName()); pstmt = DB.prepareStatement(sql, get_TrxName());
pstmt.setInt(1, get_ID()); pstmt.setInt(1, get_ID());
ResultSet rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
while (rs.next()) while (rs.next())
list.add( new MProductionLine( getCtx(), rs.getInt(1), get_TrxName() ) ); list.add( new MProductionLine( getCtx(), rs.getInt(1), get_TrxName() ) );
rs.close(); rs.close();
@ -65,17 +67,12 @@ public class MProduction extends X_M_Production {
} }
catch (SQLException ex) catch (SQLException ex)
{ {
m_log.log(Level.SEVERE, sql, ex); throw new AdempiereException("Unable to load production lines", ex);
} }
try finally
{ {
if (pstmt != null) DB.close(rs, pstmt);
pstmt.close();
} }
catch (SQLException ex1)
{
}
pstmt = null;
MProductionLine[] retValue = new MProductionLine[list.size()]; MProductionLine[] retValue = new MProductionLine[list.size()];
list.toArray(retValue); list.toArray(retValue);
@ -120,11 +117,12 @@ public class MProduction extends X_M_Production {
+ " WHERE M_Product_ID=" + getM_Product_ID() + " ORDER BY Line"; + " WHERE M_Product_ID=" + getM_Product_ID() + " ORDER BY Line";
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try { try {
pstmt = DB.prepareStatement(sql, get_TrxName()); pstmt = DB.prepareStatement(sql, get_TrxName());
ResultSet rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
while (rs.next()) { while (rs.next()) {
lineno = lineno + 10; lineno = lineno + 10;
@ -244,16 +242,31 @@ public class MProduction extends X_M_Production {
if (BOMMovementQty.signum() != 0 ) { if (BOMMovementQty.signum() != 0 ) {
if (!mustBeStocked) if (!mustBeStocked)
{ {
BOMLine = new MProductionLine( this );
BOMLine.setLine( lineno ); // roll up costing attributes if in the same locator
BOMLine.setM_Product_ID( BOMProduct_ID ); if ( previousAttribSet == 0
BOMLine.setM_Locator_ID( defaultLocator ); && prevLoc == defaultLocator) {
BOMLine.setQtyUsed( BOMMovementQty); BOMLine.setQtyUsed(BOMLine.getQtyUsed()
BOMLine.setPlannedQty( BOMMovementQty); .add(BOMMovementQty));
BOMLine.save(get_TrxName()); BOMLine.setPlannedQty(BOMLine.getQtyUsed());
BOMLine.save(get_TrxName());
lineno = lineno + 10;
count++; }
// otherwise create new line
else {
BOMLine = new MProductionLine( this );
BOMLine.setLine( lineno );
BOMLine.setM_Product_ID( BOMProduct_ID );
BOMLine.setM_Locator_ID( defaultLocator );
BOMLine.setQtyUsed( BOMMovementQty);
BOMLine.setPlannedQty( BOMMovementQty);
BOMLine.save(get_TrxName());
lineno = lineno + 10;
count++;
}
} }
else else
{ {
@ -263,7 +276,10 @@ public class MProduction extends X_M_Production {
} }
} // for all bom products } // for all bom products
} catch (Exception e) { } catch (Exception e) {
log.log(Level.SEVERE, "createLines", e); throw new AdempiereException("Failed to create production lines", e);
}
finally {
DB.close(rs, pstmt);
} }
return count; return count;

View File

@ -325,6 +325,4 @@ public class MProductionLine extends X_M_ProductionLine {
return true; return true;
} }
} }