/// <summary> /// New Order Line (different Product) /// </summary> /// <param name="rLine">request line</param> private void NewLine(MRequisitionLine rLine) { if (_orderLine != null) { if (!_orderLine.Save()) { throw new Exception("Cannot update Order Line"); } } _orderLine = null; MProduct product = null; // Get Business Partner int C_BPartner_ID = rLine.GetC_BPartner_ID(); if (C_BPartner_ID != 0) { ; } else if (rLine.GetC_Charge_ID() != 0) { MCharge charge = MCharge.Get(GetCtx(), rLine.GetC_Charge_ID()); C_BPartner_ID = charge.GetC_BPartner_ID(); if (C_BPartner_ID == 0) { throw new Exception("No Vendor for Charge " + charge.GetName()); } } else { // Find Vendor from Produt product = MProduct.Get(GetCtx(), rLine.GetM_Product_ID()); MProductPO[] ppos = MProductPO.GetOfProduct(GetCtx(), product.GetM_Product_ID(), null); 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(); break; } } if (C_BPartner_ID == 0 && ppos.Length > 0) { C_BPartner_ID = ppos[0].GetC_BPartner_ID(); } if (C_BPartner_ID == 0) { throw new Exception("No Vendor for " + product.GetName()); } } // New Order - Different Vendor if (_order == null || _order.GetC_BPartner_ID() != C_BPartner_ID) { NewOrder(rLine, C_BPartner_ID); } // No Order Line _orderLine = new MOrderLine(_order); if (product != null) { _orderLine.SetProduct(product); _orderLine.SetM_AttributeSetInstance_ID(rLine.GetM_AttributeSetInstance_ID()); } else { _orderLine.SetC_Charge_ID(rLine.GetC_Charge_ID()); _orderLine.SetPriceActual(rLine.GetPriceActual()); } _orderLine.SetAD_Org_ID(rLine.GetAD_Org_ID()); // Prepare Save _m_M_Product_ID = rLine.GetM_Product_ID(); _m_M_AttributeSetInstance_ID = rLine.GetM_AttributeSetInstance_ID(); if (!_orderLine.Save()) { throw new Exception("Cannot save Order Line"); } }