Search in sources :

Example 1 with X_T_BOM_Indented

use of org.compiere.model.X_T_BOM_Indented in project adempiere by adempiere.

the class IndentedBOM method explodeProduct.

// doIt
/**
	 * Generate an Explosion for this product
	 * @param product
	 * @param isComponent component / header
	 */
private llCost explodeProduct(int M_Product_ID, BigDecimal qty, BigDecimal accumQty) {
    MProduct product = MProduct.get(getCtx(), M_Product_ID);
    X_T_BOM_Indented tboml = new X_T_BOM_Indented(getCtx(), 0, get_TrxName());
    tboml.setAD_Org_ID(p_AD_Org_ID);
    tboml.setC_AcctSchema_ID(p_C_AcctSchema_ID);
    tboml.setAD_PInstance_ID(getAD_PInstance_ID());
    tboml.setM_CostElement_ID(p_M_CostElement_ID);
    tboml.setSel_Product_ID(product.get_ID());
    tboml.setM_Product_ID(p_M_Product_ID);
    tboml.setQtyBOM(qty);
    tboml.setQty(accumQty);
    //
    tboml.setSeqNo(m_SeqNo);
    tboml.setLevelNo(m_LevelNo);
    tboml.setLevels((m_LevelNo > 0 ? ":" : "") + StringUtils.repeat("    ", m_LevelNo) + " " + product.getValue());
    //
    // Set Costs:
    MCost cost = MCost.get(product, 0, m_as, p_AD_Org_ID, 0, p_M_CostElement_ID, get_TrxName());
    tboml.setCurrentCostPrice(cost.getCurrentCostPrice());
    tboml.setCost(cost.getCurrentCostPrice().multiply(accumQty));
    tboml.setFutureCostPrice(cost.getFutureCostPrice());
    tboml.setCostFuture(cost.getFutureCostPrice().multiply(accumQty));
    m_SeqNo++;
    BigDecimal llCost = Env.ZERO;
    BigDecimal llFutureCost = Env.ZERO;
    List<MPPProductBOMLine> list = getBOMs(product);
    for (MPPProductBOMLine bom : list) {
        m_LevelNo++;
        llCost ll = explodeProduct(bom.getM_Product_ID(), bom.getQtyBOM(), accumQty.multiply(bom.getQtyBOM()));
        llCost = llCost.add(ll.currentCost.multiply(accumQty.multiply(bom.getQtyBOM())));
        llFutureCost = llFutureCost.add(ll.futureCost.multiply(accumQty.multiply(bom.getQtyBOM())));
        m_LevelNo--;
    }
    llCost retVal = new llCost();
    if (list.size() == 0) {
        tboml.setCurrentCostPriceLL(cost.getCurrentCostPrice());
        tboml.setFutureCostPriceLL(cost.getFutureCostPrice());
        //
        retVal.currentCost = cost.getCurrentCostPrice();
        retVal.futureCost = cost.getFutureCostPrice();
    } else {
        tboml.setCurrentCostPriceLL(llCost);
        tboml.setFutureCostPriceLL(llFutureCost);
        //
        retVal.currentCost = llCost;
        retVal.futureCost = llFutureCost;
    }
    tboml.saveEx();
    return retVal;
}
Also used : X_T_BOM_Indented(org.compiere.model.X_T_BOM_Indented) MProduct(org.compiere.model.MProduct) MCost(org.compiere.model.MCost) MPPProductBOMLine(org.eevolution.model.MPPProductBOMLine) BigDecimal(java.math.BigDecimal)

Aggregations

BigDecimal (java.math.BigDecimal)1 MCost (org.compiere.model.MCost)1 MProduct (org.compiere.model.MProduct)1 X_T_BOM_Indented (org.compiere.model.X_T_BOM_Indented)1 MPPProductBOMLine (org.eevolution.model.MPPProductBOMLine)1