Bring in Manufacturing Light code from Adaxa / Paul Bowden

This commit is contained in:
Carlos Ruiz 2012-08-21 17:41:53 -05:00
parent 0785915c7b
commit 41338b001f
2 changed files with 202 additions and 155 deletions

View File

@ -22,6 +22,7 @@ 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.ArrayList;
import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
import org.compiere.model.MBPartner; import org.compiere.model.MBPartner;
@ -35,6 +36,7 @@ import org.compiere.model.MOrg;
import org.compiere.model.MProduct; import org.compiere.model.MProduct;
import org.compiere.model.MProduction; import org.compiere.model.MProduction;
import org.compiere.model.MProductionLine; import org.compiere.model.MProductionLine;
import org.compiere.model.MReplenish;
import org.compiere.model.MRequisition; import org.compiere.model.MRequisition;
import org.compiere.model.MRequisitionLine; import org.compiere.model.MRequisitionLine;
import org.compiere.model.MStorage; import org.compiere.model.MStorage;
@ -758,7 +760,7 @@ public class ReplenishReportProduction extends SvrProcess
} }
} // create Distribution Order } // create Distribution Order
/** /**
* Create Requisition * Create Production
*/ */
private void createProduction() private void createProduction()
{ {
@ -775,24 +777,47 @@ public class ReplenishReportProduction extends SvrProcess
X_T_Replenish replenish = replenishs[i]; X_T_Replenish replenish = replenishs[i];
if (wh == null || wh.getM_Warehouse_ID() != replenish.getM_Warehouse_ID()) if (wh == null || wh.getM_Warehouse_ID() != replenish.getM_Warehouse_ID())
wh = MWarehouse.get(getCtx(), replenish.getM_Warehouse_ID()); wh = MWarehouse.get(getCtx(), replenish.getM_Warehouse_ID());
BigDecimal batchQty = null;
for (MReplenish rep : MReplenish.getForProduct(getCtx(), replenish.getM_Product_ID(), get_TrxName()))
{
if ( rep.getM_Warehouse_ID() == replenish.getM_Warehouse_ID())
batchQty = rep.getQtyBatchSize();
}
BigDecimal qtyToProduce = replenish.getQtyToOrder();
while ( qtyToProduce.compareTo(Env.ZERO) > 0)
{
BigDecimal qty = qtyToProduce;
if ( batchQty != null && batchQty.compareTo(Env.ZERO) > 0 && qtyToProduce.compareTo(batchQty) > 0)
{
qty = batchQty;
qtyToProduce = qtyToProduce.subtract(batchQty);
}
else
{
qtyToProduce = Env.ZERO;
}
production = new MProduction (getCtx(), 0, get_TrxName()); production = new MProduction (getCtx(), 0, get_TrxName());
production.setDescription(Msg.getMsg(getCtx(), "Replenishment")); production.setDescription(Msg.getMsg(getCtx(), "Replenishment"));
// Set Org/WH // Set Org/WH
production.setAD_Org_ID(wh.getAD_Org_ID()); production.setAD_Org_ID(wh.getAD_Org_ID());
production.setM_Locator_ID(wh.getDefaultLocator().get_ID()); production.setM_Locator_ID(wh.getDefaultLocator().get_ID());
production.setM_Product_ID(replenish.getM_Product_ID()); production.setM_Product_ID(replenish.getM_Product_ID());
production.setProductionQty(replenish.getQtyToOrder()); production.setProductionQty(qty);
production.setMovementDate(Env.getContextAsDate(getCtx(), "#Date")); production.setMovementDate(Env.getContextAsDate(getCtx(), "#Date"));
production.saveEx(); production.saveEx();
production.createLines(false); production.createLines(false);
production.setIsCreated("Y"); production.setIsCreated("Y");
production.save(get_TrxName()); production.save(get_TrxName());
log.fine(production.toString()); log.fine(production.toString());
noProds++; noProds++;
info += " - " + production.getDocumentNo(); info += " - " + production.getDocumentNo();
}
} }
m_info = "#" + noProds + info; m_info = "#" + noProds + info;

View File

@ -27,6 +27,8 @@ public class MProduction extends X_M_Production {
/** Log */ /** Log */
private static CLogger m_log = CLogger.getCLogger (MProduction.class); private static CLogger m_log = CLogger.getCLogger (MProduction.class);
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private int lineno;
private int count;
public MProduction(Properties ctx, int M_Production_ID, String trxName) { public MProduction(Properties ctx, int M_Production_ID, String trxName) {
super(ctx, M_Production_ID, trxName); super(ctx, M_Production_ID, trxName);
@ -90,17 +92,13 @@ public class MProduction extends X_M_Production {
public int createLines(boolean mustBeStocked) { public int createLines(boolean mustBeStocked) {
int defaultLocator = 0; lineno = 100;
count = 0;
int lineno = 100;
int count = 0;
// product to be produced // product to be produced
MProduct finishedProduct = new MProduct(getCtx(), getM_Product_ID(), get_TrxName()); MProduct finishedProduct = new MProduct(getCtx(), getM_Product_ID(), get_TrxName());
MLocator finishedLocator = MLocator.get(getCtx(), getM_Locator_ID());
int M_Warehouse_ID = finishedLocator.getM_Warehouse_ID();
int asi = 0;
MProductionLine line = new MProductionLine( this ); MProductionLine line = new MProductionLine( this );
line.setLine( lineno ); line.setLine( lineno );
@ -112,9 +110,24 @@ public class MProduction extends X_M_Production {
line.save(); line.save();
count++; count++;
createLines(mustBeStocked, finishedProduct, getProductionQty());
return count;
}
private int createLines(boolean mustBeStocked, MProduct finishedProduct, BigDecimal requiredQty) {
int defaultLocator = 0;
MLocator finishedLocator = MLocator.get(getCtx(), getM_Locator_ID());
int M_Warehouse_ID = finishedLocator.getM_Warehouse_ID();
int asi = 0;
// products used in production // products used in production
String sql = "SELECT M_ProductBom_ID, BOMQty" + " FROM M_Product_BOM" String sql = "SELECT M_ProductBom_ID, BOMQty" + " FROM M_Product_BOM"
+ " WHERE M_Product_ID=" + getM_Product_ID() + " ORDER BY Line"; + " WHERE M_Product_ID=" + finishedProduct.getM_Product_ID() + " ORDER BY Line";
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null; ResultSet rs = null;
@ -128,10 +141,18 @@ public class MProduction extends X_M_Production {
lineno = lineno + 10; lineno = lineno + 10;
int BOMProduct_ID = rs.getInt(1); int BOMProduct_ID = rs.getInt(1);
BigDecimal BOMQty = rs.getBigDecimal(2); BigDecimal BOMQty = rs.getBigDecimal(2);
BigDecimal BOMMovementQty = BOMQty.multiply(getProductionQty()); BigDecimal BOMMovementQty = BOMQty.multiply(requiredQty);
MProduct bomproduct = new MProduct(Env.getCtx(), BOMProduct_ID, get_TrxName()); MProduct bomproduct = new MProduct(Env.getCtx(), BOMProduct_ID, get_TrxName());
if ( bomproduct.isPhantom() )
{
createLines(mustBeStocked, bomproduct, BOMMovementQty);
}
else
{
defaultLocator = bomproduct.getM_Locator_ID(); defaultLocator = bomproduct.getM_Locator_ID();
if ( defaultLocator == 0 ) if ( defaultLocator == 0 )
defaultLocator = getM_Locator_ID(); defaultLocator = getM_Locator_ID();
@ -274,6 +295,7 @@ public class MProduction extends X_M_Production {
} }
} }
} }
}
} // for all bom products } // for all bom products
} catch (Exception e) { } catch (Exception e) {
throw new AdempiereException("Failed to create production lines", e); throw new AdempiereException("Failed to create production lines", e);