Search in sources :

Example 16 with MPPProductBOM

use of org.eevolution.model.MPPProductBOM in project adempiere by adempiere.

the class AbstractMakeToOrder method test01.

public void test01() throws Exception {
    Qty = new BigDecimal(10);
    //Define Product
    product = MProduct.get(getCtx(), M_Product_ID);
    //Define Business Partner
    BPartner = new MBPartner(getCtx(), C_BPartner_ID, trxName);
    //Setting the BOM
    int PP_Product_BOM_ID = MPPProductBOM.getBOMSearchKey(product);
    if (PP_Product_BOM_ID > 0)
        bom = new MPPProductBOM(getCtx(), PP_Product_BOM_ID, trxName);
    else
        throw new AdempiereException("@NotFound@ @PP_ProductBOM_ID@");
    if (bom != null) {
        bom.setBOMType(MPPProductBOM.BOMTYPE_Make_To_Order);
        bom.setBOMUse(MPPProductBOM.BOMUSE_Manufacturing);
        bom.saveEx();
    }
    //Define Workflow as standardd
    workflow = new MWorkflow(getCtx(), AD_Workflow_ID, trxName);
    workflow.setValue(product.getValue());
    workflow.saveEx();
    //int workflow_id =  MWorkflow.getWorkflowSearchKey(product);
    if (AD_Workflow_ID > 0)
        workflow = MWorkflow.get(getCtx(), AD_Workflow_ID);
    else
        throw new AdempiereException("@NotFound@ @AD_Workflow_ID@");
    createOrder();
    MPPOrder expected = createPPOrder();
    I_PP_Order actual = MPPOrder.forC_OrderLine_ID(getCtx(), oline.get_ID(), oline.getM_Product_ID(), trxName);
    if (actual == null) {
        throw new AdempiereException("@NotFound@ @PP_Order_ID@ not was generate");
    }
    assertEquals("Confirming Manufacturing Order", expected, actual);
}
Also used : I_PP_Order(org.eevolution.model.I_PP_Order) AdempiereException(org.adempiere.exceptions.AdempiereException) MWorkflow(org.compiere.wf.MWorkflow) MBPartner(org.compiere.model.MBPartner) MPPProductBOM(org.eevolution.model.MPPProductBOM) BigDecimal(java.math.BigDecimal) MPPOrder(org.eevolution.model.MPPOrder)

Example 17 with MPPProductBOM

use of org.eevolution.model.MPPProductBOM in project adempiere by adempiere.

the class RollupBillOfMaterial method doIt.

//	prepare
/**
	 * 	Generate Calculate Cost
	 *	@return info
	 *	@throws Exception
	 */
protected String doIt() throws Exception {
    //Get account schema
    MAcctSchema acctSchema = MAcctSchema.get(getCtx(), getAccountingSchemaId());
    //Get cost type
    MCostType costType = MCostType.get(getCtx(), getCostTypeId());
    final List<MCostElement> costElements = getCostElementId() > 0 ? Arrays.asList(MCostElement.get(getCtx(), getCostElementId())) : MCostElement.getCostElement(getCtx(), get_TrxName());
    //Get max low level
    int maxLowLevel = MPPMRP.getMaxLowLevel(getCtx(), get_TrxName());
    // Cost Roll-up for all levels
    for (int lowLevel = maxLowLevel; lowLevel >= 0; lowLevel--) {
        //Iterate product based in parameters
        Arrays.stream(getProductIds(lowLevel)).filter(productId -> productId > 0).forEach(productId -> {
            MProduct product = MProduct.get(getCtx(), productId);
            I_PP_Product_Planning productPlanning = MPPProductPlanning.find(getCtx(), getOrganizationId(), getWarehouseId(), getResourcePlantId(), productId, get_TrxName());
            int bomId = 0;
            if (productPlanning != null)
                bomId = productPlanning.getPP_Product_BOM_ID();
            else
                createNotice(product, Msg.parseTranslation(getCtx(), "@NotFound@ @PP_Product_Planning_ID@"));
            if (bomId <= 0)
                bomId = MPPProductBOM.getBOMSearchKey(product);
            MPPProductBOM bom = MPPProductBOM.get(getCtx(), bomId);
            if (bom == null)
                createNotice(product, Msg.parseTranslation(getCtx(), "@NotFound@ @PP_Product_BOM_ID@"));
            Trx.run(new TrxRunnable() {

                MAcctSchema acctSchema;

                MCostType costType;

                MProduct product;

                MPPProductBOM bom;

                public TrxRunnable setParameters(MAcctSchema acctSchema, MCostType costType, MProduct product, MPPProductBOM bom) {
                    this.acctSchema = acctSchema;
                    this.costType = costType;
                    this.product = product;
                    this.bom = bom;
                    return this;
                }

                public void run(String trxName) {
                    costElements.stream().filter(costElement -> costElement != null).forEach(costElement -> {
                        rollup(acctSchema, costType, costElement, product, bom, trxName);
                    });
                }
            }.setParameters(acctSchema, costType, product, bom));
        });
    // Products List
    }
    // for Low Lever
    return "@OK@";
}
Also used : MUOMConversion(org.compiere.model.MUOMConversion) MPPProductPlanning(org.eevolution.model.MPPProductPlanning) Arrays(java.util.Arrays) I_PP_Product_Planning(org.eevolution.model.I_PP_Product_Planning) MWorkflow(org.compiere.wf.MWorkflow) Env(org.compiere.util.Env) MCostType(org.compiere.model.MCostType) AtomicReference(java.util.concurrent.atomic.AtomicReference) MAcctSchema(org.compiere.model.MAcctSchema) ArrayList(java.util.ArrayList) MPPProductBOM(org.eevolution.model.MPPProductBOM) MCost(org.compiere.model.MCost) BigDecimal(java.math.BigDecimal) List(java.util.List) Query(org.compiere.model.Query) DB(org.compiere.util.DB) Msg(org.compiere.util.Msg) MCostElement(org.compiere.model.MCostElement) TrxRunnable(org.compiere.util.TrxRunnable) MPPMRP(org.eevolution.model.MPPMRP) Trx(org.compiere.util.Trx) MProduct(org.compiere.model.MProduct) MCostElement(org.compiere.model.MCostElement) MAcctSchema(org.compiere.model.MAcctSchema) MProduct(org.compiere.model.MProduct) I_PP_Product_Planning(org.eevolution.model.I_PP_Product_Planning) TrxRunnable(org.compiere.util.TrxRunnable) MCostType(org.compiere.model.MCostType) MPPProductBOM(org.eevolution.model.MPPProductBOM)

Example 18 with MPPProductBOM

use of org.eevolution.model.MPPProductBOM 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
}
Also used : MProduct(org.compiere.model.MProduct) JTree(javax.swing.JTree) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) MPPProductBOMLine(org.eevolution.model.MPPProductBOMLine) MPPProductBOM(org.eevolution.model.MPPProductBOM)

Example 19 with MPPProductBOM

use of org.eevolution.model.MPPProductBOM in project adempiere by adempiere.

the class VProductConfigurationBOM method getBOMLines.

/**
	 * 	Get Array of BOM Lines
	 *	@return MProduct
	 */
private MPPProductBOMLine[] getBOMLines(MProduct m_product) {
    Collection<MPPProductBOMLine> col = new ArrayList<MPPProductBOMLine>();
    try {
        StringBuffer sql1 = new StringBuffer("select pp_product_bom_id from pp_product_bom where m_product_id = ?");
        PreparedStatement pstmt = DB.prepareStatement(sql1.toString(), null);
        pstmt.setInt(1, m_product.get_ID());
        ResultSet rs = pstmt.executeQuery();
        if (rs.next()) {
            int m_pp_product_bom_id = rs.getInt(1);
            MPPProductBOM m_MPPProductBOM = new MPPProductBOM(Env.getCtx(), m_pp_product_bom_id, null);
            MPPProductBOMLine[] bomLines = m_MPPProductBOM.getLines();
            //...or pass an explicit array
            Collections.addAll(col, bomLines);
        }
        rs.close();
        pstmt.close();
    } catch (SQLException s) {
        log.log(Level.SEVERE, "ERROR:", s);
    }
    return (MPPProductBOMLine[]) col.toArray(new MPPProductBOMLine[col.size()]);
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) MPPProductBOMLine(org.eevolution.model.MPPProductBOMLine) MPPProductBOM(org.eevolution.model.MPPProductBOM) ALayoutConstraint(org.compiere.apps.ALayoutConstraint)

Example 20 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