Search in sources :

Example 1 with MDistributionListLine

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

the class DistributionCreate method doIt.

//	prepare
/**
	 *  Perform process.
	 *  @return Message (text with variables)
	 *  @throws Exception if not successful
	 */
protected String doIt() throws Exception {
    log.info("M_DistributionList_ID=" + p_M_DistributionList_ID + ", M_Product_ID=" + p_M_Product_ID + ", Qty=" + p_Qty + ", Test=" + p_IsTest);
    if (p_IsCreateSingleOrder)
        log.info("SingleOrder=" + p_IsCreateSingleOrder + ", BPartner_ID=" + p_Bill_BPartner_ID + ", Location_ID=" + p_Bill_Location_ID);
    //
    if (p_M_DistributionList_ID == 0)
        throw new IllegalArgumentException("No Distribution List ID");
    m_dl = new MDistributionList(getCtx(), p_M_DistributionList_ID, get_TrxName());
    if (m_dl.get_ID() == 0)
        throw new Exception("Distribution List not found -  M_DistributionList_ID=" + p_M_DistributionList_ID);
    //
    if (p_M_Product_ID == 0)
        throw new IllegalArgumentException("No Product");
    m_product = MProduct.get(getCtx(), p_M_Product_ID);
    if (m_product.get_ID() == 0)
        throw new Exception("Product not found -  M_Product_ID=" + p_M_Product_ID);
    if (p_Qty == null || p_Qty.signum() != 1)
        throw new IllegalArgumentException("No Quantity");
    //
    if (p_IsCreateSingleOrder && p_Bill_BPartner_ID == 0)
        throw new IllegalArgumentException("Invoice Business Partner required for single Order");
    //	Create Single Order
    if (!p_IsTest && p_IsCreateSingleOrder) {
        MBPartner bp = new MBPartner(getCtx(), p_Bill_BPartner_ID, get_TrxName());
        if (bp.get_ID() == 0)
            throw new IllegalArgumentException("Single Business Partner not found - C_BPartner_ID=" + p_Bill_BPartner_ID);
        //
        m_singleOrder = new MOrder(getCtx(), 0, get_TrxName());
        m_singleOrder.setIsSOTrx(true);
        m_singleOrder.setC_DocTypeTarget_ID(MOrder.DocSubTypeSO_Standard);
        m_singleOrder.setBPartner(bp);
        if (p_Bill_Location_ID != 0)
            m_singleOrder.setC_BPartner_Location_ID(p_Bill_Location_ID);
        if (!m_singleOrder.save())
            throw new IllegalStateException("Single Order not created");
    }
    MDistributionListLine[] lines = m_dl.getLines();
    int counter = 0;
    for (int i = 0; i < lines.length; i++) {
        if (createOrder(lines[i]))
            counter++;
    }
    //	Update Qty
    if (m_singleOrder != null) {
        m_singleOrder.setDescription("# " + counter + " - " + m_totalQty);
        m_singleOrder.saveEx();
    }
    return "@Created@ #" + counter + " - @Qty@=" + m_totalQty;
}
Also used : MOrder(org.compiere.model.MOrder) MDistributionListLine(org.compiere.model.MDistributionListLine) MDistributionList(org.compiere.model.MDistributionList) MBPartner(org.compiere.model.MBPartner)

Aggregations

MBPartner (org.compiere.model.MBPartner)1 MDistributionList (org.compiere.model.MDistributionList)1 MDistributionListLine (org.compiere.model.MDistributionListLine)1 MOrder (org.compiere.model.MOrder)1