Search in sources :

Example 6 with MRequisitionLine

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

the class MRPApproval method createRequisition.

private MRequisition createRequisition(MPPMRP mrp) {
    if (MPPMRP.ORDERTYPE_ManufacturingOrder.equals(mrp.getOrderType())) {
        int docTypeId = MPPMRP.getDocType(getCtx(), MDocType.DOCBASETYPE_PurchaseRequisition, mrp.getAD_Org_ID(), Env.getAD_User_ID(getCtx()), get_TrxName());
        // Get PriceList from BPartner/Group - teo_sarca, FR [ 2829476 ]
        int priceListId = -1;
        final String sql = "SELECT COALESCE(bp." + MBPartner.COLUMNNAME_PO_PriceList_ID + ",bpg." + X_C_BP_Group.COLUMNNAME_PO_PriceList_ID + ")" + " FROM C_BPartner bp" + " INNER JOIN C_BP_Group bpg ON (bpg.C_BP_Group_ID=bp.C_BP_Group_ID)" + " WHERE bp.C_BPartner_ID=?";
        priceListId = DB.getSQLValueEx(get_TrxName(), sql, getBusinessPartnerId());
        MRequisition requisition = new MRequisition(getCtx(), 0, get_TrxName());
        requisition.setAD_Org_ID(mrp.getAD_Org_ID());
        requisition.setAD_User_ID(mrp.getPlanner_ID());
        requisition.setDateDoc(mrp.getDateStartSchedule());
        requisition.setDateRequired(mrp.getDatePromised());
        // req.setDescription(""); // TODO: add translation
        requisition.setM_Warehouse_ID(mrp.getM_Warehouse_ID());
        requisition.setC_DocType_ID(docTypeId);
        if (priceListId > 0)
            requisition.setM_PriceList_ID(priceListId);
        requisition.saveEx();
        MRequisitionLine requisitionLine = new MRequisitionLine(requisition);
        requisitionLine.setLine(10);
        requisitionLine.setAD_Org_ID(mrp.getAD_Org_ID());
        requisitionLine.setC_BPartner_ID(mrp.getC_BPartner_ID());
        requisitionLine.setM_Product_ID(mrp.getM_Product_ID());
        requisitionLine.setPrice();
        if (getReferenceNo() != null)
            requisitionLine.setDescription(getReferenceNo());
        requisitionLine.setPriceActual(Env.ZERO);
        requisitionLine.setQty(mrp.getQty());
        requisitionLine.saveEx();
        requisition.processIt(DocAction.ACTION_Prepare);
        requisition.saveEx();
        return requisition;
    }
    return null;
}
Also used : MRequisitionLine(org.compiere.model.MRequisitionLine) MRequisition(org.compiere.model.MRequisition)

Example 7 with MRequisitionLine

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

the class MRPApproval method executeRequisitionApproval.

private void executeRequisitionApproval(MPPMRP mrp) {
    MRequisition requisition = (MRequisition) mrp.getM_Requisition();
    Timestamp dateRequired = getSelectionAsTimestamp(mrp.getPP_MRP_ID(), "R_" + MRequisition.COLUMNNAME_DateRequired);
    if (dateRequired != null)
        requisition.setDateRequired(dateRequired);
    if (mrp.is_Changed())
        ;
    {
        validateChanges(mrp, MPPMRP.COLUMNNAME_Priority, requisition, MRequisition.COLUMNNAME_PriorityRule);
        requisition.saveEx();
        MRequisitionLine requisitionLine = (MRequisitionLine) mrp.getM_RequisitionLine();
        validateChanges(mrp, MPPMRP.COLUMNNAME_C_BPartner_ID, requisitionLine, MRequisitionLine.COLUMNNAME_C_BPartner_ID);
        validateChanges(mrp, MPPMRP.COLUMNNAME_Qty, requisitionLine, MRequisitionLine.COLUMNNAME_Qty);
        requisitionLine.saveEx();
    }
    requisition.processIt(DocAction.ACTION_Prepare);
    requisition.saveEx();
}
Also used : Timestamp(java.sql.Timestamp) MRequisitionLine(org.compiere.model.MRequisitionLine) MRequisition(org.compiere.model.MRequisition)

Example 8 with MRequisitionLine

use of org.compiere.model.MRequisitionLine 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 9 with MRequisitionLine

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

the class Doc_Requisition method loadLines.

// loadDocumentDetails
/**
	 *	Load Requisition Lines
	 *	@param req requisition
	 *	@return DocLine Array
	 */
private DocLine[] loadLines(MRequisition req) {
    ArrayList<DocLine> list = new ArrayList<DocLine>();
    MRequisitionLine[] lines = req.getLines();
    for (int i = 0; i < lines.length; i++) {
        MRequisitionLine line = lines[i];
        DocLine docLine = new DocLine(line, this);
        BigDecimal Qty = line.getQty();
        docLine.setQty(Qty, false);
        BigDecimal PriceActual = line.getPriceActual();
        BigDecimal LineNetAmt = line.getLineNetAmt();
        // DR
        docLine.setAmount(LineNetAmt);
        list.add(docLine);
    }
    // Return Array
    DocLine[] dls = new DocLine[list.size()];
    list.toArray(dls);
    return dls;
}
Also used : ArrayList(java.util.ArrayList) MRequisitionLine(org.compiere.model.MRequisitionLine) BigDecimal(java.math.BigDecimal)

Example 10 with MRequisitionLine

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

the class ReplenishReport method createRequisition.

//	createPO
/**
	 * 	Create Requisition
	 */
private void createRequisition() {
    int noReqs = 0;
    String info = "";
    //
    MRequisition requisition = null;
    MWarehouse wh = null;
    X_T_Replenish[] replenishs = getReplenish("M_WarehouseSource_ID IS NULL");
    for (int i = 0; i < replenishs.length; i++) {
        X_T_Replenish replenish = replenishs[i];
        if (wh == null || wh.getM_Warehouse_ID() != replenish.getM_Warehouse_ID())
            wh = MWarehouse.get(getCtx(), replenish.getM_Warehouse_ID());
        //
        if (requisition == null || requisition.getM_Warehouse_ID() != replenish.getM_Warehouse_ID()) {
            requisition = new MRequisition(getCtx(), 0, get_TrxName());
            requisition.setAD_User_ID(getAD_User_ID());
            requisition.setC_DocType_ID(p_C_DocType_ID);
            requisition.setDescription(Msg.getMsg(getCtx(), "Replenishment"));
            //	Set Org/WH
            requisition.setAD_Org_ID(wh.getAD_Org_ID());
            requisition.setM_Warehouse_ID(wh.getM_Warehouse_ID());
            if (!requisition.save())
                return;
            log.fine(requisition.toString());
            noReqs++;
            info += " - " + requisition.getDocumentNo();
        }
        //
        MRequisitionLine line = new MRequisitionLine(requisition);
        line.setM_Product_ID(replenish.getM_Product_ID());
        line.setC_BPartner_ID(replenish.getC_BPartner_ID());
        line.setQty(replenish.getQtyToOrder());
        line.setPrice();
        line.saveEx();
    }
    m_info = "#" + noReqs + info;
    log.info(m_info);
}
Also used : X_T_Replenish(org.compiere.model.X_T_Replenish) MRequisitionLine(org.compiere.model.MRequisitionLine) MRequisition(org.compiere.model.MRequisition) MWarehouse(org.compiere.model.MWarehouse)

Aggregations

MRequisitionLine (org.compiere.model.MRequisitionLine)10 MRequisition (org.compiere.model.MRequisition)8 ArrayList (java.util.ArrayList)3 MOrderLine (org.compiere.model.MOrderLine)3 BigDecimal (java.math.BigDecimal)2 MOrder (org.compiere.model.MOrder)2 MWarehouse (org.compiere.model.MWarehouse)2 Query (org.compiere.model.Query)2 X_T_Replenish (org.compiere.model.X_T_Replenish)2 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Timestamp (java.sql.Timestamp)1 HashMap (java.util.HashMap)1 AdempiereException (org.adempiere.exceptions.AdempiereException)1 NoVendorForProductException (org.adempiere.exceptions.NoVendorForProductException)1 MForecast (org.compiere.model.MForecast)1 MForecastLine (org.compiere.model.MForecastLine)1 MProduct (org.compiere.model.MProduct)1 MProductPO (org.compiere.model.MProductPO)1