Search in sources :

Example 1 with MPPProductPlanning

use of org.eevolution.model.MPPProductPlanning 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 MPPProductPlanning

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

the class CreateProductPlanning method createPlanning.

private void createPlanning(int productId) {
    MPPProductPlanning productPlanning = MPPProductPlanning.get(getCtx(), clientId, orgId, warehouseId, resourceId, productId, get_TrxName());
    boolean isNew = productPlanning == null;
    // Create Product Data Planning
    if (productPlanning == null) {
        productPlanning = new MPPProductPlanning(getCtx(), 0, get_TrxName());
        productPlanning.setAD_Org_ID(orgId);
        productPlanning.setM_Warehouse_ID(warehouseId);
        productPlanning.setS_Resource_ID(resourceId);
        productPlanning.setM_Product_ID(productId);
    }
    productPlanning.setDD_NetworkDistribution_ID(networkDistributionId);
    productPlanning.setAD_Workflow_ID(workflowId);
    productPlanning.setIsCreatePlan(createPlan);
    productPlanning.setIsMPS(isMPS);
    productPlanning.setIsRequiredMRP(true);
    productPlanning.setIsRequiredDRP(true);
    productPlanning.setDeliveryTime_Promised(deliveryTimePromised);
    productPlanning.setOrder_Period(orderPeriod);
    productPlanning.setPlanner_ID(plannerId);
    productPlanning.setOrder_Policy(orderPolicy);
    productPlanning.setSafetyStock(safetyStock);
    productPlanning.setOrder_Qty(orderQty);
    productPlanning.setOrder_Min(orderMin);
    productPlanning.setOrder_Max(orderMax);
    productPlanning.setOrder_Pack(orderPack);
    productPlanning.setTimeFence(timeFence);
    productPlanning.setTransferTime(transferTime);
    productPlanning.setIsPhantom(false);
    productPlanning.setWorkingTime(workingTime);
    productPlanning.setYield(yield);
    productPlanning.saveEx();
    if (isNew)
        countCreated++;
    else
        countUpdated++;
}
Also used : MPPProductPlanning(org.eevolution.model.MPPProductPlanning)

Example 3 with MPPProductPlanning

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

the class ImportProductPlanning method importRecords.

// doIt
/**
	 * import record using X_I_ProductPlanning table
	 */
private void importRecords() {
    for (X_I_ProductPlanning ipp : getRecords(false, p_IsImportOnlyNoErrors)) {
        isImported = false;
        MPPProductPlanning pp = importProductPlanning(ipp);
        if (pp == null)
            isImported = false;
        if (isImported) {
            ipp.setPP_Product_Planning_ID(pp.getPP_Product_Planning_ID());
            ipp.setI_IsImported(true);
            ipp.setProcessed(true);
            ipp.setI_ErrorMsg("");
            ipp.saveEx();
            imported++;
        } else {
            ipp.setI_IsImported(false);
            ipp.setProcessed(true);
            ipp.saveEx();
            notimported++;
        }
    }
}
Also used : MPPProductPlanning(org.eevolution.model.MPPProductPlanning) X_I_ProductPlanning(org.eevolution.model.X_I_ProductPlanning)

Example 4 with MPPProductPlanning

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

the class ImportProductPlanning method importProductPlanning.

/**
	 * import record using X_I_ProductPlanning table
	 * 
	 * @param ipp
	 *            X_I_ProductPlanning
	 */
private MPPProductPlanning importProductPlanning(X_I_ProductPlanning ipp) {
    try {
        MPPProductPlanning pp = null;
        if (ipp.getPP_Product_Planning_ID() > 0)
            pp = new MPPProductPlanning(getCtx(), ipp.getPP_Product_Planning_ID(), get_TrxName());
        else {
            pp = MPPProductPlanning.get(getCtx(), ipp.getAD_Client_ID(), ipp.getAD_Org_ID(), ipp.getM_Warehouse_ID(), ipp.getS_Resource_ID(), ipp.getM_Product_ID(), get_TrxName());
        }
        if (pp == null || pp.get_ID() <= 0) {
            pp = new MPPProductPlanning(Env.getCtx(), 0, get_TrxName());
            pp.setAD_Org_ID(ipp.getAD_Org_ID());
            pp.setM_Product_ID(ipp.getM_Product_ID());
            pp.setS_Resource_ID(ipp.getS_Resource_ID());
            pp.setM_Warehouse_ID(ipp.getM_Warehouse_ID());
            pp.setIsRequiredDRP(false);
            pp.setIsRequiredMRP(false);
        }
        fillValue(pp, ipp);
        if (ipp.getC_BPartner_ID() > 0 && ipp.getVendorProductNo() != null) {
            importPurchaseProductPlanning(ipp);
        }
        pp.saveEx();
        isImported = true;
        return pp;
    } catch (Exception e) {
        ipp.setI_ErrorMsg(e.getMessage());
        isImported = false;
        return null;
    }
}
Also used : MPPProductPlanning(org.eevolution.model.MPPProductPlanning)

Example 5 with MPPProductPlanning

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

the class RollupWorkflow method doIt.

//	prepare
protected String doIt() throws Exception {
    //Get account schema
    MAcctSchema accountSchema = MAcctSchema.get(getCtx(), getAccountingSchemaId());
    //Get cost type
    MCostType costType = MCostType.get(getCtx(), getCostTypeId());
    //Get cost element to process
    final List<MCostElement> costElements = getCostElementId() > 0 ? Arrays.asList(MCostElement.get(getCtx(), getCostElementId())) : MCostElement.getCostElement(getCtx(), get_TrxName());
    routingService = RoutingServiceFactory.get().getRoutingService(getAD_Client_ID());
    //Iterate product ids based on parameters
    Arrays.stream(getProductIds()).filter(productId -> productId > 0).forEach(productId -> {
        MProduct product = MProduct.get(getCtx(), productId);
        log.info("Product: " + product);
        int workflowId = 0;
        MPPProductPlanning productPlanning = null;
        if (workflowId <= 0)
            workflowId = MWorkflow.getWorkflowSearchKey(product);
        if (workflowId <= 0) {
            productPlanning = MPPProductPlanning.find(getCtx(), getOrganizationId(), getWarehouseId(), getResourcePlantId(), product.get_ID(), get_TrxName());
            if (productPlanning != null)
                workflowId = productPlanning.getAD_Workflow_ID();
            else
                createNotice(product, "@NotFound@ @PP_Product_Planning_ID@");
        }
        if (workflowId <= 0)
            createNotice(product, "@NotFound@ @AD_Workflow_ID@");
        else {
            Trx.run(new TrxRunnable() {

                MAcctSchema accountSchema;

                MCostType costType;

                MProduct product;

                MPPProductPlanning productPlanning;

                int workflowId;

                public TrxRunnable setParameters(MAcctSchema accountSchema, MCostType costType, MProduct product, MPPProductPlanning productPlanning, int workflowId) {
                    this.accountSchema = accountSchema;
                    this.costType = costType;
                    this.product = product;
                    this.productPlanning = productPlanning;
                    this.workflowId = workflowId;
                    return this;
                }

                public void run(String trxName) {
                    MWorkflow workflow = new MWorkflow(getCtx(), workflowId, trxName);
                    costElements.stream().filter(costElement -> costElement != null && CostEngine.isActivityControlElement(costElement)).forEach(costElement -> {
                        rollup(accountSchema, costType, costElement, product, workflow, trxName);
                    });
                    if (productPlanning != null) {
                        productPlanning.load(trxName);
                        productPlanning.setYield(workflow.getYield());
                        productPlanning.saveEx();
                    }
                }
            }.setParameters(accountSchema, costType, product, productPlanning, workflowId));
        }
    });
    return "@OK@";
}
Also used : MPPProductPlanning(org.eevolution.model.MPPProductPlanning) Arrays(java.util.Arrays) 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) RoutingService(org.eevolution.model.RoutingService) MCost(org.compiere.model.MCost) BigDecimal(java.math.BigDecimal) Query(org.compiere.model.Query) Msg(org.compiere.util.Msg) Trx(org.compiere.util.Trx) CostEngine(org.adempiere.engine.CostEngine) RoundingMode(java.math.RoundingMode) CostEngineFactory(org.adempiere.engine.CostEngineFactory) CostDimension(org.adempiere.engine.CostDimension) MWorkflow(org.compiere.wf.MWorkflow) StandardCostingMethod(org.adempiere.engine.StandardCostingMethod) RoutingServiceFactory(org.eevolution.model.RoutingServiceFactory) List(java.util.List) MWFNode(org.compiere.wf.MWFNode) MCostElement(org.compiere.model.MCostElement) TrxRunnable(org.compiere.util.TrxRunnable) MProduct(org.compiere.model.MProduct) MCostElement(org.compiere.model.MCostElement) MAcctSchema(org.compiere.model.MAcctSchema) MProduct(org.compiere.model.MProduct) MPPProductPlanning(org.eevolution.model.MPPProductPlanning) MWorkflow(org.compiere.wf.MWorkflow) TrxRunnable(org.compiere.util.TrxRunnable) MCostType(org.compiere.model.MCostType)

Aggregations

MPPProductPlanning (org.eevolution.model.MPPProductPlanning)10 MWorkflow (org.compiere.wf.MWorkflow)3 BigDecimal (java.math.BigDecimal)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 List (java.util.List)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 MAcctSchema (org.compiere.model.MAcctSchema)2 MCost (org.compiere.model.MCost)2 MCostElement (org.compiere.model.MCostElement)2 MCostType (org.compiere.model.MCostType)2 MProduct (org.compiere.model.MProduct)2 Query (org.compiere.model.Query)2 Env (org.compiere.util.Env)2 Msg (org.compiere.util.Msg)2 Trx (org.compiere.util.Trx)2 TrxRunnable (org.compiere.util.TrxRunnable)2 MPPProductBOM (org.eevolution.model.MPPProductBOM)2 RoundingMode (java.math.RoundingMode)1 Properties (java.util.Properties)1