Search in sources :

Example 1 with MProductPO

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

the class ReleaseInOutBound method createRequisition.

/**
	 * Create Requisition when the Is create supply is define as yes
	 * @param outBoundOrderLine
	 * @param product Product
	 * @param QtyPlanned Qty Planned
	 */
public void createRequisition(MWMInOutBoundLine outBoundOrderLine, MProduct product, BigDecimal QtyPlanned) {
    //s_log.info("Create Requisition");
    int partnerId = 0;
    int priceListId = 0;
    MProductPO productPOLast;
    MProductPO[] productPOs = MProductPO.getOfProduct(getCtx(), product.getM_Product_ID(), null);
    Arrays.stream(productPOs).forEach(productPO -> {
        if (productPO.isCurrentVendor() && productPO.getC_BPartner_ID() != 0) {
        }
    });
    if (partnerId == 0 && productPOs.length > 0) {
        partnerId = productPOs[0].getC_BPartner_ID();
    }
    if (partnerId == 0) {
        throw new NoVendorForProductException(product.getName());
    }
    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, partnerId);
    MRequisition requisition = new MRequisition(getCtx(), 0, get_TrxName());
    requisition.setAD_Org_ID(outBoundLocator.getAD_Org_ID());
    requisition.setAD_User_ID(getAD_User_ID());
    requisition.setDateRequired(outBoundOrderLine.getPickDate());
    // TODO: add translation
    requisition.setDescription("Generate from Outbound Order");
    requisition.setM_Warehouse_ID(outBoundLocator.getM_Warehouse_ID());
    requisition.setC_DocType_ID(MDocType.getDocType(MDocType.DOCBASETYPE_PurchaseRequisition));
    if (priceListId > 0)
        requisition.setM_PriceList_ID(priceListId);
    requisition.saveEx();
    MRequisitionLine reqline = new MRequisitionLine(requisition);
    reqline.setLine(10);
    reqline.setAD_Org_ID(outBoundLocator.getAD_Org_ID());
    reqline.setC_BPartner_ID(partnerId);
    reqline.setM_Product_ID(product.getM_Product_ID());
    reqline.setPrice();
    reqline.setPriceActual(Env.ZERO);
    reqline.setQty(QtyPlanned);
    reqline.saveEx();
    MOrderLine orderLine = new MOrderLine(getCtx(), outBoundOrderLine.getC_OrderLine_ID(), get_TrxName());
    orderLine.setDescription(orderLine.getDescription() + " " + Msg.translate(getCtx(), MRequisition.COLUMNNAME_M_Requisition_ID) + " : " + requisition.getDocumentNo());
    orderLine.saveEx();
    outBoundOrderLine.setDescription(outBoundOrderLine.getDescription() + " " + Msg.translate(outBoundOrderLine.getCtx(), MRequisition.COLUMNNAME_M_Requisition_ID) + " : " + requisition.getDocumentNo());
}
Also used : NoVendorForProductException(org.adempiere.exceptions.NoVendorForProductException) MProductPO(org.compiere.model.MProductPO) MOrderLine(org.compiere.model.MOrderLine) MRequisitionLine(org.compiere.model.MRequisitionLine) MRequisition(org.compiere.model.MRequisition)

Example 2 with MProductPO

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

the class ProjectGenPO method createPO.

//	doIt
/**
	 * 	Create PO from Planned Amt/Qty
	 * 	@param projectLine project line
	 */
private void createPO(MProject project, MProjectLine projectLine) {
    if (projectLine.getM_Product_ID() == 0) {
        addLog(projectLine.getLine(), null, null, "Line has no Product");
        return;
    }
    if (projectLine.getC_OrderPO_ID() != 0) {
        addLog(projectLine.getLine(), null, null, "Line was ordered previously");
        return;
    }
    //	PO Record
    MProductPO[] pos = MProductPO.getOfProduct(getCtx(), projectLine.getM_Product_ID(), get_TrxName());
    if (pos == null || pos.length == 0) {
        addLog(projectLine.getLine(), null, null, "Product has no PO record");
        return;
    }
    //	Create to Order
    MOrder order = null;
    //	try to find PO to C_BPartner
    for (int i = 0; i < m_pos.size(); i++) {
        MOrder test = (MOrder) m_pos.get(i);
        if (test.getC_BPartner_ID() == pos[0].getC_BPartner_ID()) {
            order = test;
            break;
        }
    }
    if (//	create new Order
    order == null) {
        //	Vendor
        MBPartner bp = new MBPartner(getCtx(), pos[0].getC_BPartner_ID(), get_TrxName());
        //	New Order
        order = new MOrder(project, false, null);
        int AD_Org_ID = projectLine.getAD_Org_ID();
        if (AD_Org_ID == 0) {
            log.warning("createPOfromProjectLine - AD_Org_ID=0");
            AD_Org_ID = Env.getAD_Org_ID(getCtx());
            if (AD_Org_ID != 0)
                projectLine.setAD_Org_ID(AD_Org_ID);
        }
        order.setClientOrg(projectLine.getAD_Client_ID(), AD_Org_ID);
        order.setBPartner(bp);
        order.save();
        //	optionally save for consolidation
        if (m_ConsolidateDocument)
            m_pos.add(order);
    }
    //	Create Line
    MOrderLine orderLine = new MOrderLine(order);
    orderLine.setM_Product_ID(projectLine.getM_Product_ID(), true);
    orderLine.setQty(projectLine.getPlannedQty());
    orderLine.setDescription(projectLine.getDescription());
    //	(Vendor) PriceList Price
    orderLine.setPrice();
    if (orderLine.getPriceActual().signum() == 0) {
        //	Try to find purchase price
        BigDecimal poPrice = pos[0].getPricePO();
        int C_Currency_ID = pos[0].getC_Currency_ID();
        //
        if (poPrice == null || poPrice.signum() == 0)
            poPrice = pos[0].getPriceLastPO();
        if (poPrice == null || poPrice.signum() == 0)
            poPrice = pos[0].getPriceList();
        //	We have a price
        if (poPrice != null && poPrice.signum() != 0) {
            if (order.getC_Currency_ID() != C_Currency_ID)
                poPrice = MConversionRate.convert(getCtx(), poPrice, C_Currency_ID, order.getC_Currency_ID(), order.getDateAcct(), order.getC_ConversionType_ID(), order.getAD_Client_ID(), order.getAD_Org_ID());
            orderLine.setPrice(poPrice);
        }
    }
    orderLine.setTax();
    orderLine.saveEx();
    //	update ProjectLine
    projectLine.setC_OrderPO_ID(order.getC_Order_ID());
    projectLine.saveEx();
    addLog(projectLine.getLine(), null, projectLine.getPlannedQty(), order.getDocumentNo());
}
Also used : MOrder(org.compiere.model.MOrder) MProductPO(org.compiere.model.MProductPO) MBPartner(org.compiere.model.MBPartner) MOrderLine(org.compiere.model.MOrderLine) BigDecimal(java.math.BigDecimal)

Example 3 with MProductPO

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

the class MRP method getProductPlanning.

protected MPPProductPlanning getProductPlanning(int AD_Client_ID, int AD_Org_ID, int S_Resource_ID, int M_Warehouse_ID, MProduct product, String trxName) throws SQLException {
    // Find data product planning demand 
    MPPProductPlanning pp = MPPProductPlanning.find(getCtx(), AD_Org_ID, M_Warehouse_ID, S_Resource_ID, product.getM_Product_ID(), trxName);
    if (pp == null) {
        return null;
    }
    MPPProductPlanning pp2 = new MPPProductPlanning(getCtx(), 0, null);
    MPPProductPlanning.copyValues(pp, pp2);
    pp2.setAD_Org_ID(pp.getAD_Org_ID());
    pp2.setIsRequiredDRP(isSynchronize());
    //
    if (pp2.getPP_Product_BOM_ID() <= 0 && product.isBOM()) {
        pp2.setPP_Product_BOM_ID(MPPProductBOM.getBOMSearchKey(product));
    }
    if (pp2.getAD_Workflow_ID() <= 0 && product.isBOM()) {
        pp2.setAD_Workflow_ID(MWorkflow.getWorkflowSearchKey(product));
    }
    if (pp2.getPlanner_ID() <= 0) {
        pp2.setPlanner_ID(getPlanner_ID() == null || getPlanner_ID() == 0 ? Env.getAD_User_ID(getCtx()) : getPlanner_ID());
    }
    if (pp2.getM_Warehouse_ID() <= 0) {
        pp2.setM_Warehouse_ID(M_Warehouse_ID);
    }
    if (pp2.getS_Resource_ID() <= 0) {
        pp2.setS_Resource_ID(S_Resource_ID);
    }
    if (pp2.getOrder_Policy() == null) {
        pp2.setOrder_Policy(X_PP_Product_Planning.ORDER_POLICY_Lot_For_Lot);
    }
    //Find Vendor
    if (!isSynchronize()) {
        if (product.isPurchased()) {
            int C_BPartner_ID = 0;
            MProductPO[] ppos = MProductPO.getOfProduct(getCtx(), product.getM_Product_ID(), trxName);
            for (int i = 0; i < ppos.length; i++) {
                if (ppos[i].isCurrentVendor() && ppos[i].getC_BPartner_ID() != 0) {
                    C_BPartner_ID = ppos[i].getC_BPartner_ID();
                    pp2.setDeliveryTime_Promised(BigDecimal.valueOf(ppos[i].getDeliveryTime_Promised()));
                    pp2.setOrder_Min(ppos[i].getOrder_Min());
                    pp2.setOrder_Max(Env.ZERO);
                    pp2.setOrder_Pack(ppos[i].getOrder_Pack());
                    pp2.setC_BPartner_ID(C_BPartner_ID);
                    break;
                }
            }
            if (C_BPartner_ID <= 0) {
                createMRPNote("MRP-130", AD_Org_ID, 0, product, (String) null, null, null, trxName);
                pp2.setIsCreatePlan(false);
            }
        }
        if (product.isBOM()) {
            if (pp2.getAD_Workflow_ID() <= 0)
                log.info("Error: Do not exist workflow (" + product.getValue() + ")");
        }
    }
    //
    return pp2;
}
Also used : MPPProductPlanning(org.eevolution.model.MPPProductPlanning) MProductPO(org.compiere.model.MProductPO)

Example 4 with MProductPO

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

the class ImportProductPlanning method importPurchaseProductPlanning.

/**
	 * Import record using X_I_ProductPlanning table
	 * 
	 * @param ipp
	 *            X_I_ProductPlanning
	 */
private void importPurchaseProductPlanning(X_I_ProductPlanning ipp) {
    MProduct product = MProduct.get(getCtx(), ipp.getM_Product_ID());
    if (product.isPurchased()) {
        final StringBuffer whereClause = new StringBuffer();
        whereClause.append(MProductPO.COLUMNNAME_M_Product_ID).append("=? AND ");
        whereClause.append(MProductPO.COLUMNNAME_C_BPartner_ID).append("=?");
        MProductPO productPO = new Query(getCtx(), MProductPO.Table_Name, whereClause.toString(), get_TrxName()).setClient_ID().setParameters(ipp.getM_Product_ID(), ipp.getC_BPartner_ID()).first();
        if (productPO == null) {
            productPO = new MProductPO(getCtx(), 0, get_TrxName());
            productPO.setM_Product_ID(ipp.getM_Product_ID());
            productPO.setC_BPartner_ID(ipp.getC_BPartner_ID());
        }
        productPO.setAD_Org_ID(ipp.getAD_Org_ID());
        productPO.setOrder_Min(ipp.getOrder_Min());
        productPO.setOrder_Pack(ipp.getOrder_Pack());
        productPO.setDeliveryTime_Promised(ipp.getDeliveryTime_Promised().intValue());
        productPO.setVendorProductNo(ipp.getVendorProductNo());
        productPO.saveEx();
    }
}
Also used : MProduct(org.compiere.model.MProduct) Query(org.compiere.model.Query) MProductPO(org.compiere.model.MProductPO)

Aggregations

MProductPO (org.compiere.model.MProductPO)4 MOrderLine (org.compiere.model.MOrderLine)2 BigDecimal (java.math.BigDecimal)1 NoVendorForProductException (org.adempiere.exceptions.NoVendorForProductException)1 MBPartner (org.compiere.model.MBPartner)1 MOrder (org.compiere.model.MOrder)1 MProduct (org.compiere.model.MProduct)1 MRequisition (org.compiere.model.MRequisition)1 MRequisitionLine (org.compiere.model.MRequisitionLine)1 Query (org.compiere.model.Query)1 MPPProductPlanning (org.eevolution.model.MPPProductPlanning)1