Search in sources :

Example 1 with MBOM

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;
}
Also used : MProduct(org.compiere.model.MProduct) MBOMProduct(org.compiere.model.MBOMProduct) MBOMProduct(org.compiere.model.MBOMProduct) MBOM(org.compiere.model.MBOM)

Example 2 with MBOM

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());
    }
}
Also used : MBOM(org.compiere.model.MBOM)

Aggregations

MBOM (org.compiere.model.MBOM)2 MBOMProduct (org.compiere.model.MBOMProduct)1 MProduct (org.compiere.model.MProduct)1