use of org.compiere.model.MBOM in project adempiere by adempiere.
the class BOMValidate method validateProduct.
// validateBOM
/**
* Validate Product
* @param product product
* @param BOMType type
* @param BOMUse use
* @return true if valid
*/
private boolean validateProduct(MProduct product, String BOMType, String BOMUse) {
if (!product.isBOM())
return true;
//
String restriction = "BOMType='" + BOMType + "' AND BOMUse='" + BOMUse + "'";
MBOM[] boms = MBOM.getOfProduct(getCtx(), p_M_Product_ID, get_TrxName(), restriction);
if (boms.length != 1) {
log.warning(restriction + " - Length=" + boms.length);
return false;
}
if (m_products.contains(product)) {
log.warning(m_product.getName() + " recursively includes " + product.getName());
return false;
}
m_products.add(product);
log.fine(product.getName());
//
MBOM bom = boms[0];
MBOMProduct[] BOMproducts = MBOMProduct.getOfBOM(bom);
for (int i = 0; i < BOMproducts.length; i++) {
MBOMProduct BOMproduct = BOMproducts[i];
MProduct pp = new MProduct(getCtx(), BOMproduct.getM_BOMProduct_ID(), get_TrxName());
if (pp.isBOM())
return validateProduct(pp, bom.getBOMType(), bom.getBOMUse());
}
return true;
}
use of org.compiere.model.MBOM in project adempiere by adempiere.
the class MProductBOMTest method testBOMCreation.
public void testBOMCreation() {
bom = new MBOM(getCtx(), 0, getTrxName());
// BOM load test case of qualified bom parent for testing MBOM.getOfProduct
bom.setM_Product_ID(134);
bom.setBOMType("A");
bom.setName("PatioTable");
//
boolean saveResult = bom.save();
assertTrue("MBOM.save()", saveResult);
try {
commit();
} catch (Exception e) {
fail(e.getLocalizedMessage());
}
}
Aggregations