use of org.eevolution.model.MPPProductBOM in project adempiere by adempiere.
the class AbstractMakeToOrder method test01.
public void test01() throws Exception {
Qty = new BigDecimal(10);
//Define Product
product = MProduct.get(getCtx(), M_Product_ID);
//Define Business Partner
BPartner = new MBPartner(getCtx(), C_BPartner_ID, trxName);
//Setting the BOM
int PP_Product_BOM_ID = MPPProductBOM.getBOMSearchKey(product);
if (PP_Product_BOM_ID > 0)
bom = new MPPProductBOM(getCtx(), PP_Product_BOM_ID, trxName);
else
throw new AdempiereException("@NotFound@ @PP_ProductBOM_ID@");
if (bom != null) {
bom.setBOMType(MPPProductBOM.BOMTYPE_Make_To_Order);
bom.setBOMUse(MPPProductBOM.BOMUSE_Manufacturing);
bom.saveEx();
}
//Define Workflow as standardd
workflow = new MWorkflow(getCtx(), AD_Workflow_ID, trxName);
workflow.setValue(product.getValue());
workflow.saveEx();
//int workflow_id = MWorkflow.getWorkflowSearchKey(product);
if (AD_Workflow_ID > 0)
workflow = MWorkflow.get(getCtx(), AD_Workflow_ID);
else
throw new AdempiereException("@NotFound@ @AD_Workflow_ID@");
createOrder();
MPPOrder expected = createPPOrder();
I_PP_Order actual = MPPOrder.forC_OrderLine_ID(getCtx(), oline.get_ID(), oline.getM_Product_ID(), trxName);
if (actual == null) {
throw new AdempiereException("@NotFound@ @PP_Order_ID@ not was generate");
}
assertEquals("Confirming Manufacturing Order", expected, actual);
}
use of org.eevolution.model.MPPProductBOM in project adempiere by adempiere.
the class RollupBillOfMaterial method doIt.
// prepare
/**
* Generate Calculate Cost
* @return info
* @throws Exception
*/
protected String doIt() throws Exception {
//Get account schema
MAcctSchema acctSchema = MAcctSchema.get(getCtx(), getAccountingSchemaId());
//Get cost type
MCostType costType = MCostType.get(getCtx(), getCostTypeId());
final List<MCostElement> costElements = getCostElementId() > 0 ? Arrays.asList(MCostElement.get(getCtx(), getCostElementId())) : MCostElement.getCostElement(getCtx(), get_TrxName());
//Get max low level
int maxLowLevel = MPPMRP.getMaxLowLevel(getCtx(), get_TrxName());
// Cost Roll-up for all levels
for (int lowLevel = maxLowLevel; lowLevel >= 0; lowLevel--) {
//Iterate product based in parameters
Arrays.stream(getProductIds(lowLevel)).filter(productId -> productId > 0).forEach(productId -> {
MProduct product = MProduct.get(getCtx(), productId);
I_PP_Product_Planning productPlanning = MPPProductPlanning.find(getCtx(), getOrganizationId(), getWarehouseId(), getResourcePlantId(), productId, get_TrxName());
int bomId = 0;
if (productPlanning != null)
bomId = productPlanning.getPP_Product_BOM_ID();
else
createNotice(product, Msg.parseTranslation(getCtx(), "@NotFound@ @PP_Product_Planning_ID@"));
if (bomId <= 0)
bomId = MPPProductBOM.getBOMSearchKey(product);
MPPProductBOM bom = MPPProductBOM.get(getCtx(), bomId);
if (bom == null)
createNotice(product, Msg.parseTranslation(getCtx(), "@NotFound@ @PP_Product_BOM_ID@"));
Trx.run(new TrxRunnable() {
MAcctSchema acctSchema;
MCostType costType;
MProduct product;
MPPProductBOM bom;
public TrxRunnable setParameters(MAcctSchema acctSchema, MCostType costType, MProduct product, MPPProductBOM bom) {
this.acctSchema = acctSchema;
this.costType = costType;
this.product = product;
this.bom = bom;
return this;
}
public void run(String trxName) {
costElements.stream().filter(costElement -> costElement != null).forEach(costElement -> {
rollup(acctSchema, costType, costElement, product, bom, trxName);
});
}
}.setParameters(acctSchema, costType, product, bom));
});
// Products List
}
// for Low Lever
return "@OK@";
}
use of org.eevolution.model.MPPProductBOM in project adempiere by adempiere.
the class VTreeBOM method action_loadBOM.
// actionPerformed
/**
* Action: Fill Tree with all nodes
*/
private void action_loadBOM() {
int M_Product_ID = getM_Product_ID();
if (M_Product_ID == 0)
return;
MProduct product = MProduct.get(getCtx(), M_Product_ID);
DefaultMutableTreeNode parent = new DefaultMutableTreeNode(productSummary(product, false));
dataBOM.clear();
m_level = 0;
if (isImplosion()) {
for (MPPProductBOMLine bomline : MPPProductBOMLine.getByProduct(product)) {
parent.add(parent(bomline));
}
m_tree = new JTree(parent);
} else {
for (MPPProductBOM bom : MPPProductBOM.getProductBOMs(product)) {
parent.add(parent(bom));
}
m_tree = new JTree(parent);
}
m_tree.addTreeSelectionListener(this);
treePane.getViewport().add(m_tree, null);
loadTableBOM();
dataPane.getViewport().add(tableBOM, null);
// 4Layers - Set divider location
splitPane.setDividerLocation(DIVIDER_LOCATION);
// 4Layers - end
}
use of org.eevolution.model.MPPProductBOM in project adempiere by adempiere.
the class VProductConfigurationBOM method getBOMLines.
/**
* Get Array of BOM Lines
* @return MProduct
*/
private MPPProductBOMLine[] getBOMLines(MProduct m_product) {
Collection<MPPProductBOMLine> col = new ArrayList<MPPProductBOMLine>();
try {
StringBuffer sql1 = new StringBuffer("select pp_product_bom_id from pp_product_bom where m_product_id = ?");
PreparedStatement pstmt = DB.prepareStatement(sql1.toString(), null);
pstmt.setInt(1, m_product.get_ID());
ResultSet rs = pstmt.executeQuery();
if (rs.next()) {
int m_pp_product_bom_id = rs.getInt(1);
MPPProductBOM m_MPPProductBOM = new MPPProductBOM(Env.getCtx(), m_pp_product_bom_id, null);
MPPProductBOMLine[] bomLines = m_MPPProductBOM.getLines();
//...or pass an explicit array
Collections.addAll(col, bomLines);
}
rs.close();
pstmt.close();
} catch (SQLException s) {
log.log(Level.SEVERE, "ERROR:", s);
}
return (MPPProductBOMLine[]) col.toArray(new MPPProductBOMLine[col.size()]);
}
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