Search in sources :

Example 31 with MPPProductBOM

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 "";
}
Also used : MPPProductBOM(org.eevolution.model.MPPProductBOM) MPPProductBOMLine(org.eevolution.model.MPPProductBOMLine) BigDecimal(java.math.BigDecimal)

Aggregations

MPPProductBOM (org.eevolution.model.MPPProductBOM)31 BigDecimal (java.math.BigDecimal)14 MProduct (org.compiere.model.MProduct)14 MPPProductBOMLine (org.eevolution.model.MPPProductBOMLine)14 Query (org.compiere.model.Query)11 ArrayList (java.util.ArrayList)8 AdempiereException (org.adempiere.exceptions.AdempiereException)6 MWorkflow (org.compiere.wf.MWorkflow)6 Arrays (java.util.Arrays)5 List (java.util.List)5 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)5 MAcctSchema (org.compiere.model.MAcctSchema)5 MCost (org.compiere.model.MCost)5 MCostElement (org.compiere.model.MCostElement)5 Env (org.compiere.util.Env)5 MPPOrder (org.eevolution.model.MPPOrder)5 MBPartner (org.compiere.model.MBPartner)4 I_PP_Order (org.eevolution.model.I_PP_Order)4 MPPProductPlanning (org.eevolution.model.MPPProductPlanning)4 Vector (java.util.Vector)3