Search in sources :

Example 1 with NoPlantForWarehouseException

use of org.eevolution.exceptions.NoPlantForWarehouseException in project adempiere by adempiere.

the class ReleaseInOutBound method createManufacturingOrder.

/**
	 * Create Manufacturing Order when the Is create supply is define as yes
	 * @param outBoundOrderLine Bound Line
	 * @param product Product
	 * @param qtySupply Quantity to Supply
	 */
public void createManufacturingOrder(MWMInOutBoundLine outBoundOrderLine, MProduct product, BigDecimal qtySupply) {
    MPPOrder order = MPPOrder.forC_OrderLine_ID(outBoundOrderLine.getCtx(), outBoundOrderLine.getC_OrderLine_ID(), product.get_ID(), outBoundOrderLine.get_TrxName());
    if (order == null) {
        MPPProductBOM bom = MPPProductBOM.getDefault(product, get_TrxName());
        if (bom != null) {
            MPPProductPlanning productPlanning = null;
            //Validate the BOM based in planning data 
            if (bom == null) {
                productPlanning = MPPProductPlanning.find(getCtx(), outBoundOrderLine.getAD_Org_ID(), 0, 0, product.getM_Product_ID(), null);
                if (productPlanning != null) {
                    bom = (MPPProductBOM) productPlanning.getPP_Product_BOM();
                }
            }
            if (bom != null) {
                final int plant_id = MPPProductPlanning.getPlantForWarehouse(outBoundOrderLine.getM_Warehouse_ID());
                if (plant_id <= 0) {
                    throw new NoPlantForWarehouseException(outBoundOrderLine.getM_Warehouse_ID());
                }
                MWorkflow workflow = MWorkflow.get(getCtx(), MWorkflow.getWorkflowSearchKey(product));
                //Validate the workflow based in planning data 						
                if (workflow == null && productPlanning != null) {
                    workflow = productPlanning.getAD_Workflow();
                }
                if (plant_id > 0 && workflow != null) {
                    String description = Msg.translate(getCtx(), MWMInOutBound.COLUMNNAME_WM_InOutBound_ID) + " : " + outBoundOrderLine.getParent().getDocumentNo();
                    //Create temporary Product Planning to Create Manufacturing Order 
                    productPlanning = new MPPProductPlanning(getCtx(), 0, get_TrxName());
                    productPlanning.setAD_Org_ID(outBoundOrderLine.getAD_Org_ID());
                    productPlanning.setM_Product_ID(product.getM_Product_ID());
                    productPlanning.setPlanner_ID(outBoundOrderLine.getParent().getSalesRep_ID());
                    productPlanning.setPP_Product_BOM_ID(bom.getPP_Product_BOM_ID());
                    productPlanning.setAD_Workflow_ID(workflow.getAD_Workflow_ID());
                    productPlanning.setM_Warehouse_ID(outBoundOrderLine.getM_Warehouse_ID());
                    productPlanning.setS_Resource_ID(plant_id);
                    order = MPPMRP.createMO(productPlanning, outBoundOrderLine.getC_OrderLine_ID(), outBoundOrderLine.getM_AttributeSetInstance_ID(), qtySupply, outBoundOrderLine.getPickDate(), outBoundOrderLine.getShipDate(), description);
                    MOrderLine orderLine = new MOrderLine(getCtx(), outBoundOrderLine.getC_OrderLine_ID(), get_TrxName());
                    description = "";
                    if (orderLine.getDescription() != null)
                        description = orderLine.getDescription();
                    description = description + " " + Msg.translate(orderLine.getCtx(), MPPOrder.COLUMNNAME_PP_Order_ID) + " : " + order.getDocumentNo();
                    orderLine.setDescription(description);
                    orderLine.saveEx();
                    String boundDescription = "";
                    if (outBoundOrderLine.getDescription() != null)
                        boundDescription = outBoundOrderLine.getDescription();
                    boundDescription = boundDescription + " " + Msg.translate(getCtx(), MPPOrder.COLUMNNAME_PP_Order_ID) + " : " + order.getDocumentNo();
                    outBoundOrderLine.setDescription(boundDescription);
                }
            }
        }
    }
    if (order != null) {
        outBoundOrderLine.setProcessed(true);
        outBoundOrderLine.saveEx();
    }
}
Also used : MPPProductPlanning(org.eevolution.model.MPPProductPlanning) MWorkflow(org.compiere.wf.MWorkflow) MOrderLine(org.compiere.model.MOrderLine) MPPProductBOM(org.eevolution.model.MPPProductBOM) NoPlantForWarehouseException(org.eevolution.exceptions.NoPlantForWarehouseException) MPPOrder(org.eevolution.model.MPPOrder)

Example 2 with NoPlantForWarehouseException

use of org.eevolution.exceptions.NoPlantForWarehouseException in project adempiere by adempiere.

the class MPPMRP method createMOMakeTo.

public static MPPOrder createMOMakeTo(MOrderLine orderLine, BigDecimal qty) {
    MPPOrder order = MPPOrder.forC_OrderLine_ID(orderLine.getCtx(), orderLine.getC_OrderLine_ID(), orderLine.getM_Product_ID(), orderLine.get_TrxName());
    if (order == null) {
        //Search Plant for this Warehouse
        int plantId = 0;
        plantId = MPPProductPlanning.getPlantForWarehouse(orderLine.getM_Warehouse_ID());
        if (plantId <= 0)
            throw new NoPlantForWarehouseException(orderLine.getM_Warehouse_ID());
        final MProduct product = MProduct.get(orderLine.getCtx(), orderLine.getM_Product_ID());
        final String whereClause = MPPProductBOM.COLUMNNAME_BOMType + " IN (?,?)" + " AND " + MPPProductBOM.COLUMNNAME_BOMUse + "=?" + " AND " + MPPProductBOM.COLUMNNAME_Value + "=?";
        //Search standard BOM
        MPPProductBOM bom = new Query(orderLine.getCtx(), MPPProductBOM.Table_Name, whereClause, orderLine.get_TrxName()).setClient_ID().setParameters(MPPProductBOM.BOMTYPE_Make_To_Order, MPPProductBOM.BOMTYPE_Make_To_Kit, MPPProductBOM.BOMUSE_Manufacturing, product.getValue()).firstOnly();
        //Search workflow standard
        MWorkflow workflow = null;
        int workflowId = MWorkflow.getWorkflowSearchKey(product);
        if (workflowId > 0)
            workflow = MWorkflow.get(orderLine.getCtx(), workflowId);
        MPPProductPlanning productPlanning = null;
        //Search planning data if no exist BOM or Workflow Standard
        if (bom == null || workflow == null) {
            productPlanning = MPPProductPlanning.find(orderLine.getCtx(), orderLine.getAD_Org_ID(), orderLine.getM_Warehouse_ID(), plantId, orderLine.getM_Product_ID(), orderLine.get_TrxName());
            if (productPlanning == null)
                throw new AdempiereException("@NotFound@ @PP_Product_Planning_ID@");
        }
        //Validate BOM
        if (bom == null && productPlanning != null) {
            bom = new MPPProductBOM(orderLine.getCtx(), productPlanning.getPP_Product_BOM_ID(), orderLine.get_TrxName());
            if (bom != null && !MPPProductBOM.BOMTYPE_Make_To_Order.equals(bom.getBOMType()) && !MPPProductBOM.BOMTYPE_Make_To_Kit.equals(bom.getBOMType())) {
                throw new AdempiereException("@NotFound@ @PP_ProductBOM_ID@");
            }
        }
        if (workflow == null && productPlanning != null) {
            //Validate the workflow based in planning data 						
            workflow = new MWorkflow(orderLine.getCtx(), productPlanning.getAD_Workflow_ID(), orderLine.get_TrxName());
            if (workflow == null) {
                throw new AdempiereException("@NotFound@ @AD_Workflow_ID@");
            }
        }
        if (plantId > 0 && workflow != null) {
            String description = Msg.translate(orderLine.getCtx(), MRefList.getListName(orderLine.getCtx(), MPPOrderBOM.BOMTYPE_AD_Reference_ID, bom.getBOMType())) + " " + Msg.translate(orderLine.getCtx(), MOrder.COLUMNNAME_C_Order_ID) + " : " + orderLine.getParent().getDocumentNo();
            // Create temporary data planning to create Manufacturing Order
            productPlanning = new MPPProductPlanning(orderLine.getCtx(), 0, orderLine.get_TrxName());
            productPlanning.setAD_Org_ID(orderLine.getAD_Org_ID());
            productPlanning.setM_Product_ID(product.getM_Product_ID());
            productPlanning.setPlanner_ID(orderLine.getParent().getSalesRep_ID());
            productPlanning.setPP_Product_BOM_ID(bom.getPP_Product_BOM_ID());
            productPlanning.setAD_Workflow_ID(workflow.getAD_Workflow_ID());
            productPlanning.setM_Warehouse_ID(orderLine.getM_Warehouse_ID());
            productPlanning.setS_Resource_ID(plantId);
            order = MPPMRP.createMO(productPlanning, orderLine.getC_OrderLine_ID(), orderLine.getM_AttributeSetInstance_ID(), qty, orderLine.getDateOrdered(), orderLine.getDatePromised(), description);
            description = "";
            if (orderLine.getDescription() != null)
                description = orderLine.getDescription();
            description = description + " " + Msg.translate(orderLine.getCtx(), MRefList.getListName(orderLine.getCtx(), MPPOrderBOM.BOMTYPE_AD_Reference_ID, bom.getBOMType())) + " " + Msg.translate(orderLine.getCtx(), MPPOrder.COLUMNNAME_PP_Order_ID) + " : " + order.getDocumentNo();
            orderLine.setDescription(description);
            orderLine.saveEx();
        }
    } else {
        if (!order.isProcessed()) {
            //if you chance product in order line the Manufacturing order is void
            if (order.getM_Product_ID() != orderLine.getM_Product_ID()) {
                order.setDescription("");
                order.setQtyEntered(Env.ZERO);
                order.setC_OrderLine_ID(0);
                order.voidIt();
                order.setDocStatus(MPPOrder.DOCSTATUS_Voided);
                order.setDocAction(MPPOrder.ACTION_None);
                order.save();
                orderLine.setDescription("");
                orderLine.saveEx();
            }
            if (order.getQtyEntered().compareTo(orderLine.getQtyEntered()) != 0) {
                order.setQty(orderLine.getQtyEntered());
                order.saveEx();
            }
            if (order.getDatePromised().compareTo(orderLine.getDatePromised()) != 0) {
                order.setDatePromised(orderLine.getDatePromised());
                order.saveEx();
            }
        }
    }
    return order;
}
Also used : MProduct(org.compiere.model.MProduct) Query(org.compiere.model.Query) AdempiereException(org.adempiere.exceptions.AdempiereException) MWorkflow(org.compiere.wf.MWorkflow) NoPlantForWarehouseException(org.eevolution.exceptions.NoPlantForWarehouseException)

Aggregations

MWorkflow (org.compiere.wf.MWorkflow)2 NoPlantForWarehouseException (org.eevolution.exceptions.NoPlantForWarehouseException)2 AdempiereException (org.adempiere.exceptions.AdempiereException)1 MOrderLine (org.compiere.model.MOrderLine)1 MProduct (org.compiere.model.MProduct)1 Query (org.compiere.model.Query)1 MPPOrder (org.eevolution.model.MPPOrder)1 MPPProductBOM (org.eevolution.model.MPPProductBOM)1 MPPProductPlanning (org.eevolution.model.MPPProductPlanning)1