use of org.eevolution.model.MPPProductBOM in project adempiere by adempiere.
the class MProduction method createBOM.
/**
* Create Lines from finished product
* @param mustBeStocked
* @param finishedProduct
* @param requiredQty
* @return
*/
private String createBOM(boolean mustBeStocked, MProduct finishedProduct, BigDecimal requiredQty) {
int defaultLocator = 0;
MPPProductBOM bom = MPPProductBOM.getDefault(finishedProduct, get_TrxName());
for (MPPProductBOMLine bLine : bom.getLines()) {
lineno = lineno + 10;
BigDecimal BOMMovementQty = getQty(bLine, true).multiply(requiredQty);
int precision = bLine.getPrecision();
if (BOMMovementQty.scale() > precision) {
BOMMovementQty = BOMMovementQty.setScale(precision, RoundingMode.HALF_UP);
}
MProduct bomproduct = bLine.getProduct();
if (bomproduct.isBOM() && bomproduct.isPhantom()) {
createBOM(mustBeStocked, bomproduct, BOMMovementQty);
} else {
defaultLocator = bomproduct.getM_Locator_ID();
if (defaultLocator == 0)
defaultLocator = getM_Locator_ID();
if (!bomproduct.isStocked()) {
MProductionLine BOMLine = null;
BOMLine = new MProductionLine(this);
BOMLine.setLine(lineno);
BOMLine.setM_Product_ID(bomproduct.getM_Product_ID());
BOMLine.setM_Locator_ID(defaultLocator);
BOMLine.setQtyUsed(BOMMovementQty);
BOMLine.setPlannedQty(BOMMovementQty);
BOMLine.setMovementQty(BOMMovementQty.negate());
BOMLine.saveEx(get_TrxName());
lineno = lineno + 10;
} else if (BOMMovementQty.signum() == 0) {
MProductionLine BOMLine = null;
BOMLine = new MProductionLine(this);
BOMLine.setLine(lineno);
BOMLine.setM_Product_ID(bomproduct.getM_Product_ID());
BOMLine.setM_Locator_ID(defaultLocator);
BOMLine.setQtyUsed(BOMMovementQty);
BOMLine.setPlannedQty(BOMMovementQty);
BOMLine.saveEx(get_TrxName());
lineno = lineno + 10;
} else {
MProductionLine BOMLine = null;
BOMLine = new MProductionLine(this);
BOMLine.setLine(lineno);
BOMLine.setM_Product_ID(bomproduct.getM_Product_ID());
BOMLine.setM_Locator_ID(defaultLocator);
BOMLine.setPlannedQty(BOMMovementQty);
BOMLine.setQtyReserved(BOMMovementQty);
BOMLine.setMovementQty(BOMMovementQty.negate());
BOMLine.saveEx(get_TrxName());
lineno = lineno + 10;
}
// for available storages
}
}
return "";
}
Aggregations