Search in sources :

Example 1 with MForecast

use of org.compiere.model.MForecast in project adempiere by adempiere.

the class MPPMRP method M_ForecastLine.

/**
	 * Create MRP record based in Forecast Line 
	 * @param MForecastLine Forecast Line
	 */
public static void M_ForecastLine(MForecastLine fl) {
    String trxName = fl.get_TrxName();
    Properties ctx = fl.getCtx();
    MForecast f = new MForecast(ctx, fl.getM_Forecast_ID(), trxName);
    MPPMRP mrp = getQuery(fl, null, null).firstOnly();
    if (mrp == null) {
        mrp = new MPPMRP(ctx, 0, trxName);
        mrp.setM_ForecastLine_ID(fl.getM_ForecastLine_ID());
    }
    mrp.setM_Forecast(f);
    mrp.setName("MRP");
    mrp.setAD_Org_ID(fl.getAD_Org_ID());
    mrp.setDatePromised(fl.getDatePromised());
    mrp.setDateStartSchedule(fl.getDatePromised());
    mrp.setDateFinishSchedule(fl.getDatePromised());
    mrp.setDateOrdered(fl.getDatePromised());
    mrp.setM_Warehouse_ID(fl.getM_Warehouse_ID());
    mrp.setM_Product_ID(fl.getM_Product_ID());
    mrp.setQty(fl.getQty());
    mrp.setDocStatus(DocAction.STATUS_InProgress);
    mrp.saveEx();
}
Also used : MForecast(org.compiere.model.MForecast) Properties(java.util.Properties)

Example 2 with MForecast

use of org.compiere.model.MForecast in project adempiere by adempiere.

the class LiberoValidator method modelChange.

//	initialize
public String modelChange(PO po, int type) throws Exception {
    log.info(po.get_TableName() + " Type: " + type);
    boolean isChange = (TYPE_AFTER_NEW == type || (TYPE_AFTER_CHANGE == type && MPPMRP.isChanged(po)));
    boolean isDelete = (TYPE_BEFORE_DELETE == type);
    boolean isReleased = false;
    boolean isVoided = false;
    //Update MRP Change Net 
    if (MPPMRP.isChanged(po) && (TYPE_AFTER_CHANGE == type || TYPE_AFTER_NEW == type)) {
        MPPMRP.setIsRequired(po, MPPProductPlanning.COLUMNNAME_IsRequiredMRP, true, po.get_TrxName());
    }
    DocAction doc = null;
    if (po instanceof DocAction) {
        doc = (DocAction) po;
    } else if (po instanceof MOrderLine) {
        doc = ((MOrderLine) po).getParent();
    }
    if (doc != null) {
        String docStatus = doc.getDocStatus();
        isReleased = DocAction.STATUS_InProgress.equals(docStatus) || DocAction.STATUS_Completed.equals(docStatus);
        isVoided = DocAction.STATUS_Voided.equals(docStatus);
    }
    // Can we change M_Product.C_UOM_ID ?
    if (po instanceof MProduct && TYPE_BEFORE_CHANGE == type && po.is_ValueChanged(MProduct.COLUMNNAME_C_UOM_ID) && MPPMRP.hasProductRecords((MProduct) po)) {
        throw new AdempiereException("@SaveUomError@");
    }
    //
    if (isDelete || isVoided || !po.isActive()) {
        if (MOrder.Table_Name.equals(po.get_TableName()) || MOrderLine.Table_Name.equals(po.get_TableName()) || MPPOrder.Table_Name.equals(po.get_TableName()) || MPPOrderBOMLine.Table_Name.equals(po.get_TableName()) || MDDOrder.Table_Name.equals(po.get_TableName()) || MDDOrderLine.Table_Name.equals(po.get_TableName()) || MRequisition.Table_Name.equals(po.get_TableName()) || MRequisitionLine.Table_Name.equals(po.get_TableName()) || MForecast.Table_Name.equals(po.get_TableName()) || MForecastLine.Table_Name.equals(po.get_TableName()))
            MPPMRP.deleteMRP(po);
    } else if (po instanceof MOrder) {
        MOrder order = (MOrder) po;
        // or when you change DatePromised or DocStatus and is Purchase Order
        if (isChange && !order.isSOTrx()) {
            MPPMRP.C_Order(order);
        } else // or you change DatePromised
        if (type == TYPE_AFTER_CHANGE && order.isSOTrx()) {
            if (isReleased || MPPMRP.isChanged(order)) {
                MPPMRP.C_Order(order);
            }
        }
    } else // 
    if (po instanceof MOrderLine && isChange) {
        MOrderLine ol = (MOrderLine) po;
        MOrder order = ol.getParent();
        // Create/Update a planning supply when isPurchase Order or you change relevant fields
        if (!order.isSOTrx()) {
            MPPMRP.C_OrderLine(ol);
        } else // you change relevant fields
        if (order.isSOTrx() && isReleased) {
            MPPMRP.C_OrderLine(ol);
        }
    } else //
    if (po instanceof MRequisition && isChange) {
        MRequisition r = (MRequisition) po;
        MPPMRP.M_Requisition(r);
    } else //
    if (po instanceof MRequisitionLine && isChange) {
        MRequisitionLine rl = (MRequisitionLine) po;
        MPPMRP.M_RequisitionLine(rl);
    } else //
    if (po instanceof MForecast && isChange) {
        MForecast fl = (MForecast) po;
        MPPMRP.M_Forecast(fl);
    } else //
    if (po instanceof MForecastLine && isChange) {
        MForecastLine fl = (MForecastLine) po;
        MPPMRP.M_ForecastLine(fl);
    } else if (po instanceof MDDOrder && isChange) {
        MDDOrder order = (MDDOrder) po;
        MPPMRP.DD_Order(order);
    } else //
    if (po instanceof MDDOrderLine && isChange) {
        MDDOrderLine ol = (MDDOrderLine) po;
        MPPMRP.DD_OrderLine(ol);
    } else //
    if (po instanceof MPPOrder && isChange) {
        MPPOrder order = (MPPOrder) po;
        MPPMRP.PP_Order(order);
    } else //
    if (po instanceof MPPOrderBOMLine && isChange) {
        MPPOrderBOMLine obl = (MPPOrderBOMLine) po;
        MPPMRP.PP_Order_BOMLine(obl);
    }
    //
    return null;
}
Also used : MProduct(org.compiere.model.MProduct) DocAction(org.compiere.process.DocAction) MForecast(org.compiere.model.MForecast) MOrder(org.compiere.model.MOrder) MForecastLine(org.compiere.model.MForecastLine) AdempiereException(org.adempiere.exceptions.AdempiereException) MOrderLine(org.compiere.model.MOrderLine) MRequisitionLine(org.compiere.model.MRequisitionLine) MRequisition(org.compiere.model.MRequisition)

Example 3 with MForecast

use of org.compiere.model.MForecast in project adempiere by adempiere.

the class ProcessingForecast method doIt.

//	prepare
/**
	 * 	Process
	 *	@return info
	 *	@throws Exception
	 */
protected String doIt() {
    MForecast forecast = new MForecast(getCtx(), p_M_Forecast_ID, get_TrxName());
    forecast.setProcessed(true);
    forecast.saveEx();
    for (MForecastLine fl : forecast.getLines(true)) {
        MPPMRP.M_ForecastLine(fl);
    }
    return "@M_Forecast_ID@ : " + forecast.getName() + " @Processed@";
}
Also used : MForecastLine(org.compiere.model.MForecastLine) MForecast(org.compiere.model.MForecast)

Example 4 with MForecast

use of org.compiere.model.MForecast in project adempiere by adempiere.

the class GenerateForecast method doIt.

// prepare
/**
	 * Process
	 * 
	 * @return message
	 * @throws Exception
	 */
protected String doIt() throws Exception {
    // Validate Data
    MForecast forecast = new MForecast(getCtx(), p_M_Forecast_ID, get_TrxName());
    MPPForecastRun fr = new MPPForecastRun(getCtx(), p_PP_ForecastRun_ID, get_TrxName());
    if (fr.getAD_Org_ID() != forecast.getAD_Org_ID())
        throw new AdempiereException("@AD_Org_ID@  @NotMatched@ @M_Forecast_ID@");
    if (fr.getPP_Calendar_ID() != forecast.getPP_Calendar_ID())
        throw new AdempiereException("@PP_Calendar_ID@  @NotMatched@ @M_Forecast_ID@");
    if (fr.getPP_PeriodDefinition_ID() != forecast.getPP_PeriodDefinition_ID())
        throw new AdempiereException("@PP_PeriodDefinition_ID@ @NotMatched@ @M_Forecast_ID@");
    StringBuilder result = new StringBuilder();
    int deletedRecord = 0;
    int updatedRecord = 0;
    int createdRecord = 0;
    if (p_SalesRep_ID <= 0)
        p_SalesRep_ID = Env.getAD_User_ID(getCtx());
    if ("R".equals(p_ForecastActionType)) {
        deletedRecord = deleteData();
        createdRecord = insertForecast();
    } else if ("M".equals(p_ForecastActionType)) {
        updatedRecord = updateForecast();
        createdRecord = insertForecast();
    }
    String desc = fr.getDocumentNo() + " " + fr.getDescription();
    forecast.setDescription(forecast.getDescription() != null ? forecast.getDescription() + " " + desc : desc);
    forecast.saveEx();
    fr.setProcessed(true);
    fr.saveEx();
    result.append("@M_Forecast_ID@ # @Deleted@ = ").append(deletedRecord).append(" @Updated@ = ").append(updatedRecord).append(" @Created@ = ").append(createdRecord);
    return result.toString();
}
Also used : MPPForecastRun(org.eevolution.model.MPPForecastRun) AdempiereException(org.adempiere.exceptions.AdempiereException) MForecast(org.compiere.model.MForecast)

Example 5 with MForecast

use of org.compiere.model.MForecast in project adempiere by adempiere.

the class ImportForecast method importForecast.

/**
	 * Import Forecast using X_I_Forecast table
	 * 
	 * @param X_I_Forecast
	 *            X_I_Forecast
	 * @return MForecastLine Forecast Line
	 */
private MForecastLine importForecast(X_I_Forecast ifl) {
    MForecastLine fl = new MForecastLine(getCtx(), ifl.getM_ForecastLine_ID(), get_TrxName());
    MForecast f = (MForecast) ifl.getM_Forecast();
    if (fl == null || fl.get_ID() <= 0) {
        fl = new MForecastLine(Env.getCtx(), 0, get_TrxName());
        fl.setAD_Org_ID(ifl.getAD_Org_ID());
        fl.setM_Forecast_ID(ifl.getM_Forecast_ID());
        fl.setM_Product_ID(ifl.getM_Product_ID());
        fl.setM_Warehouse_ID(ifl.getM_Warehouse_ID());
    }
    fl.setQty(ifl.getQty());
    fl.setIsActive(true);
    fl.setSalesRep_ID(ifl.getSalesRep_ID());
    fl.setDatePromised(ifl.getDatePromised());
    MPPPeriod period = MPPPeriod.findByCalendar(getCtx(), ifl.getDatePromised(), f.getPP_Calendar_ID(), get_TrxName());
    if (period == null) {
        ifl.setI_ErrorMsg(Msg.parseTranslation(ifl.getCtx(), "@PP_Period_ID@ @NotFound@ @To@ @DatePromised@" + ifl.getDatePromised()));
        isImported = false;
        return null;
    }
    fl.setPP_Period_ID(period.get_ID());
    fl.saveEx();
    isImported = true;
    return fl;
}
Also used : MPPPeriod(org.eevolution.model.MPPPeriod) MForecastLine(org.compiere.model.MForecastLine) MForecast(org.compiere.model.MForecast)

Aggregations

MForecast (org.compiere.model.MForecast)5 MForecastLine (org.compiere.model.MForecastLine)3 AdempiereException (org.adempiere.exceptions.AdempiereException)2 Properties (java.util.Properties)1 MOrder (org.compiere.model.MOrder)1 MOrderLine (org.compiere.model.MOrderLine)1 MProduct (org.compiere.model.MProduct)1 MRequisition (org.compiere.model.MRequisition)1 MRequisitionLine (org.compiere.model.MRequisitionLine)1 DocAction (org.compiere.process.DocAction)1 MPPForecastRun (org.eevolution.model.MPPForecastRun)1 MPPPeriod (org.eevolution.model.MPPPeriod)1