use of org.compiere.model.MProduct 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.compiere.model.MProduct in project adempiere by adempiere.
the class VProductConfigurationBOM method getProductFromMPPProductBOM.
// createMainPanel
/**
* Get last product of a BOM
* @return MProduct
*/
private MProduct getProductFromMPPProductBOM(int PP_Product_BOM_ID) {
MProduct m_product = null;
try {
StringBuffer sql1 = new StringBuffer("select m_product_id from pp_product_bom where pp_product_bom_id = ?");
PreparedStatement pstmt = DB.prepareStatement(sql1.toString(), null);
pstmt.setInt(1, PP_Product_BOM_ID);
ResultSet rs = pstmt.executeQuery();
//
if (rs.next()) {
int m_product_id = rs.getInt(1);
m_product = new MProduct(Env.getCtx(), m_product_id, null);
}
rs.close();
pstmt.close();
} catch (SQLException s) {
log.log(Level.SEVERE, "ERROR:", s);
}
return m_product;
}
use of org.compiere.model.MProduct in project adempiere by adempiere.
the class VProductConfigurationBOM method addBOMLine.
// addBOMLines
/**
* Add BOM Line to this.
* Calls addBOMLines if added product is a BOM
* @param line BOM Line
* @param qty quantity
*/
private void addBOMLine(MPPProductBOMLine line, BigDecimal qty) {
log.fine("In addBOMLine");
log.fine(line.toString());
//FIXME: add a bomtype accessor here
String bomType = line.getComponentType();
if (bomType == null)
bomType = MProductBOM.BOMTYPE_StandardPart;
BigDecimal lineQty = new BigDecimal(0);
MProduct product = getProductFromMPPProductBOMLine(line);
if (product == null)
return;
addDisplay(line.getM_Product_ID(), product.getM_Product_ID(), bomType, product.getName(), lineQty, line.getPP_Product_BOM_ID(), line.getFeature(), line.get_ID());
}
use of org.compiere.model.MProduct in project adempiere by adempiere.
the class PosKeyGenerate method doIt.
/**
* Generate keys for each product
*/
@Override
protected String doIt() throws Exception {
if (posKeyLayoutId == 0)
throw new FillMandatoryException("C_POSKeyLayout_ID");
int count = 0;
String where = "";
Object[] params = new Object[] {};
if (productCategoryId > 0) {
where = "M_Product_Category_ID = ? ";
params = new Object[] { productCategoryId };
}
Query query = new Query(getCtx(), MProduct.Table_Name, where, get_TrxName()).setParameters(params).setOnlyActiveRecords(true).setOrderBy("Value");
List<MProduct> products = query.list();
for (MProduct product : products) {
MPOSKey key = new MPOSKey(getCtx(), 0, get_TrxName());
key.setName(product.getName());
key.setM_Product_ID(product.getM_Product_ID());
key.setC_POSKeyLayout_ID(posKeyLayoutId);
key.setSeqNo(count * 10);
key.setQty(Env.ONE);
key.saveEx();
count++;
}
return "@Created@ " + count;
}
use of org.compiere.model.MProduct in project adempiere by adempiere.
the class ProductUOMConvert method doIt.
// prepare
/**
* Process
* @return message
* @throws Exception
*/
protected String doIt() throws Exception {
if (p_M_Product_ID == 0 || p_M_Product_To_ID == 0 || p_M_Locator_ID == 0 || p_Qty == null || Env.ZERO.compareTo(p_Qty) == 0)
throw new AdempiereUserError("Invalid Parameter");
//
MProduct product = MProduct.get(getCtx(), p_M_Product_ID);
MProduct productTo = MProduct.get(getCtx(), p_M_Product_To_ID);
log.info("Product=" + product + ", ProductTo=" + productTo + ", M_Locator_ID=" + p_M_Locator_ID + ", Qty=" + p_Qty);
MUOMConversion[] conversions = MUOMConversion.getProductConversions(getCtx(), product.getM_Product_ID());
MUOMConversion conversion = null;
for (int i = 0; i < conversions.length; i++) {
if (conversions[i].getC_UOM_To_ID() == productTo.getC_UOM_ID())
conversion = conversions[i];
}
if (conversion == null)
throw new AdempiereUserError("@NotFound@: @C_UOM_Conversion_ID@");
MUOM uomTo = MUOM.get(getCtx(), productTo.getC_UOM_ID());
BigDecimal qtyTo = p_Qty.divide(conversion.getDivideRate(), uomTo.getStdPrecision(), BigDecimal.ROUND_HALF_UP);
BigDecimal qtyTo6 = p_Qty.divide(conversion.getDivideRate(), 6, BigDecimal.ROUND_HALF_UP);
if (qtyTo.compareTo(qtyTo6) != 0)
throw new AdempiereUserError("@StdPrecision@: " + qtyTo + " <> " + qtyTo6 + " (" + p_Qty + "/" + conversion.getDivideRate() + ")");
log.info(conversion + " -> " + qtyTo);
// Set to Beta
return "Not completed yet";
}
Aggregations