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:
parent
d00cfa2ad5
commit
0785915c7b
|
@ -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,6 +242,19 @@ public class MProduction extends X_M_Production {
|
||||||
if (BOMMovementQty.signum() != 0 ) {
|
if (BOMMovementQty.signum() != 0 ) {
|
||||||
if (!mustBeStocked)
|
if (!mustBeStocked)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// roll up costing attributes if in the same locator
|
||||||
|
if ( previousAttribSet == 0
|
||||||
|
&& prevLoc == defaultLocator) {
|
||||||
|
BOMLine.setQtyUsed(BOMLine.getQtyUsed()
|
||||||
|
.add(BOMMovementQty));
|
||||||
|
BOMLine.setPlannedQty(BOMLine.getQtyUsed());
|
||||||
|
BOMLine.save(get_TrxName());
|
||||||
|
|
||||||
|
}
|
||||||
|
// otherwise create new line
|
||||||
|
else {
|
||||||
|
|
||||||
BOMLine = new MProductionLine( this );
|
BOMLine = new MProductionLine( this );
|
||||||
BOMLine.setLine( lineno );
|
BOMLine.setLine( lineno );
|
||||||
BOMLine.setM_Product_ID( BOMProduct_ID );
|
BOMLine.setM_Product_ID( BOMProduct_ID );
|
||||||
|
@ -255,6 +266,8 @@ public class MProduction extends X_M_Production {
|
||||||
lineno = lineno + 10;
|
lineno = lineno + 10;
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new AdempiereUserError("Not enough stock of " + BOMProduct_ID);
|
throw new AdempiereUserError("Not enough stock of " + BOMProduct_ID);
|
||||||
|
@ -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;
|
||||||
|
|
|
@ -325,6 +325,4 @@ public class MProductionLine extends X_M_ProductionLine {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue