Bring in Manufacturing Light code from Adaxa / Paul Bowden
This commit is contained in:
parent
0785915c7b
commit
41338b001f
|
@ -22,6 +22,7 @@ import java.sql.PreparedStatement;
|
|||
import java.sql.ResultSet;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.compiere.model.MBPartner;
|
||||
|
@ -35,6 +36,7 @@ import org.compiere.model.MOrg;
|
|||
import org.compiere.model.MProduct;
|
||||
import org.compiere.model.MProduction;
|
||||
import org.compiere.model.MProductionLine;
|
||||
import org.compiere.model.MReplenish;
|
||||
import org.compiere.model.MRequisition;
|
||||
import org.compiere.model.MRequisitionLine;
|
||||
import org.compiere.model.MStorage;
|
||||
|
@ -758,7 +760,7 @@ public class ReplenishReportProduction extends SvrProcess
|
|||
}
|
||||
} // create Distribution Order
|
||||
/**
|
||||
* Create Requisition
|
||||
* Create Production
|
||||
*/
|
||||
private void createProduction()
|
||||
{
|
||||
|
@ -775,24 +777,47 @@ public class ReplenishReportProduction extends SvrProcess
|
|||
X_T_Replenish replenish = replenishs[i];
|
||||
if (wh == null || wh.getM_Warehouse_ID() != 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.setDescription(Msg.getMsg(getCtx(), "Replenishment"));
|
||||
// Set Org/WH
|
||||
production.setAD_Org_ID(wh.getAD_Org_ID());
|
||||
production.setM_Locator_ID(wh.getDefaultLocator().get_ID());
|
||||
production.setM_Product_ID(replenish.getM_Product_ID());
|
||||
production.setProductionQty(replenish.getQtyToOrder());
|
||||
production.setProductionQty(qty);
|
||||
production.setMovementDate(Env.getContextAsDate(getCtx(), "#Date"));
|
||||
production.saveEx();
|
||||
|
||||
production.createLines(false);
|
||||
|
||||
|
||||
production.setIsCreated("Y");
|
||||
production.save(get_TrxName());
|
||||
log.fine(production.toString());
|
||||
noProds++;
|
||||
info += " - " + production.getDocumentNo();
|
||||
}
|
||||
|
||||
}
|
||||
m_info = "#" + noProds + info;
|
||||
|
|
|
@ -27,6 +27,8 @@ public class MProduction extends X_M_Production {
|
|||
/** Log */
|
||||
private static CLogger m_log = CLogger.getCLogger (MProduction.class);
|
||||
private static final long serialVersionUID = 1L;
|
||||
private int lineno;
|
||||
private int count;
|
||||
|
||||
public MProduction(Properties ctx, int M_Production_ID, String trxName) {
|
||||
super(ctx, M_Production_ID, trxName);
|
||||
|
@ -90,17 +92,13 @@ public class MProduction extends X_M_Production {
|
|||
|
||||
public int createLines(boolean mustBeStocked) {
|
||||
|
||||
int defaultLocator = 0;
|
||||
lineno = 100;
|
||||
|
||||
count = 0;
|
||||
|
||||
int lineno = 100;
|
||||
int count = 0;
|
||||
// product to be produced
|
||||
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 );
|
||||
line.setLine( lineno );
|
||||
|
@ -112,9 +110,24 @@ public class MProduction extends X_M_Production {
|
|||
line.save();
|
||||
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
|
||||
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;
|
||||
ResultSet rs = null;
|
||||
|
@ -128,10 +141,18 @@ public class MProduction extends X_M_Production {
|
|||
lineno = lineno + 10;
|
||||
int BOMProduct_ID = rs.getInt(1);
|
||||
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());
|
||||
|
||||
|
||||
if ( bomproduct.isPhantom() )
|
||||
{
|
||||
createLines(mustBeStocked, bomproduct, BOMMovementQty);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
defaultLocator = bomproduct.getM_Locator_ID();
|
||||
if ( defaultLocator == 0 )
|
||||
defaultLocator = getM_Locator_ID();
|
||||
|
@ -274,6 +295,7 @@ public class MProduction extends X_M_Production {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} // for all bom products
|
||||
} catch (Exception e) {
|
||||
throw new AdempiereException("Failed to create production lines", e);
|
||||
|
|
Loading…
Reference in New Issue