Search in sources :

Example 11 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 12 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 13 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 14 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 15 with MPPProductBOM

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

the class DistributionRunOrders method groovy1.

public String groovy1(String A_TrxName, Properties A_Ctx, int P_M_Warehouse_ID, int P_M_PriceList_Version_ID, int P_M_DistributionList_ID) {
    MDistributionRunLine main = new MDistributionRunLine(A_Ctx, 0, A_TrxName);
    MProduct product = MProduct.get(A_Ctx, main.getM_Product_ID());
    BigDecimal Qty = main.getTotalQty();
    int seq = main.getLine();
    int num = 1;
    if (product.isBOM() && Qty.signum() > 0) {
        seq += 1;
        MPPProductBOM bom = MPPProductBOM.getDefault(product, A_TrxName);
        //Explotando los componentes
        for (MPPProductBOMLine line : bom.getLines()) {
            num += 1;
            int M_Product_ID = line.getM_Product_ID();
            BigDecimal QtyRequired = line.getQtyBOM().multiply(Qty);
            BigDecimal QtyAvailable = MStorage.getQtyAvailable(P_M_Warehouse_ID, M_Product_ID, 0, 0, A_TrxName);
            BigDecimal QtyOnHand = MPPMRP.getQtyOnHand(A_Ctx, P_M_Warehouse_ID, M_Product_ID, A_TrxName);
            BigDecimal QtyToDeliver = QtyRequired;
            if (QtyRequired.compareTo(QtyAvailable) > 0)
                QtyToDeliver = QtyAvailable;
            MDistributionRunLine drl = new MDistributionRunLine(A_Ctx, 0, A_TrxName);
            drl.setM_DistributionRun_ID(main.getM_DistributionRun_ID());
            drl.setLine(seq);
            drl.setM_Product_ID(M_Product_ID);
            drl.setM_DistributionList_ID(main.getM_DistributionList_ID());
            drl.setDescription(Msg.translate(A_Ctx, "QtyRequired") + " = " + QtyRequired.intValue() + " | " + Msg.translate(A_Ctx, "QtyAvailable") + " = " + QtyAvailable + " | " + Msg.translate(A_Ctx, "QtyOnHand") + " = " + QtyOnHand);
            drl.setTotalQty(QtyToDeliver);
            drl.saveEx();
        }
    }
    main.setIsActive(false);
    return "Componentes del Juego:" + num;
}
Also used : MProduct(org.compiere.model.MProduct) MDistributionRunLine(org.compiere.model.MDistributionRunLine) 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