use of org.adempiere.exceptions.NoVendorForProductException 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());
}
use of org.adempiere.exceptions.NoVendorForProductException in project adempiere by adempiere.
the class MPPCostCollector method createPO.
/**
* Create Purchase Order (in case of Subcontracting)
* @param activity
*/
private String createPO(MPPOrderNode activity) {
String msg = "";
HashMap<Integer, MOrder> orders = new HashMap<Integer, MOrder>();
//
String whereClause = MPPOrderNodeProduct.COLUMNNAME_PP_Order_Node_ID + "=?" + " AND " + MPPOrderNodeProduct.COLUMNNAME_IsSubcontracting + "=?";
Collection<MPPOrderNodeProduct> subcontracts = new Query(getCtx(), MPPOrderNodeProduct.Table_Name, whereClause, get_TrxName()).setParameters(new Object[] { activity.get_ID(), true }).setOnlyActiveRecords(true).list();
for (MPPOrderNodeProduct subcontract : subcontracts) {
//
// If Product is not Purchased or is not Service, then it is not a subcontracting candidate [SKIP]
MProduct product = MProduct.get(getCtx(), subcontract.getM_Product_ID());
if (!product.isPurchased() || !MProduct.PRODUCTTYPE_Service.equals(product.getProductType()))
throw new AdempiereException("The Product: " + product.getName() + " Do not is Purchase or Service Type");
//
// Find Vendor and Product PO data
int C_BPartner_ID = activity.getC_BPartner_ID();
MProductPO product_po = null;
for (MProductPO ppo : MProductPO.getOfProduct(getCtx(), product.get_ID(), null)) {
if (C_BPartner_ID == ppo.getC_BPartner_ID()) {
C_BPartner_ID = ppo.getC_BPartner_ID();
product_po = ppo;
break;
}
if (ppo.isCurrentVendor() && ppo.getC_BPartner_ID() != 0) {
C_BPartner_ID = ppo.getC_BPartner_ID();
product_po = ppo;
break;
}
}
if (C_BPartner_ID <= 0 || product_po == null) {
throw new NoVendorForProductException(product.getName());
}
//
// Calculate Lead Time
Timestamp today = new Timestamp(System.currentTimeMillis());
Timestamp datePromised = TimeUtil.addDays(today, product_po.getDeliveryTime_Promised());
//
// Get/Create Purchase Order Header
MOrder order = orders.get(C_BPartner_ID);
if (order == null) {
order = new MOrder(getCtx(), 0, get_TrxName());
MBPartner vendor = MBPartner.get(getCtx(), C_BPartner_ID);
order.setAD_Org_ID(getAD_Org_ID());
order.setBPartner(vendor);
order.setIsSOTrx(false);
order.setC_DocTypeTarget_ID();
order.setDatePromised(datePromised);
order.setDescription(Msg.translate(getCtx(), MPPOrder.COLUMNNAME_PP_Order_ID) + ":" + getPP_Order().getDocumentNo());
order.setDocStatus(MOrder.DOCSTATUS_Drafted);
order.setDocAction(MOrder.DOCACTION_Complete);
order.setAD_User_ID(getAD_User_ID());
order.setM_Warehouse_ID(getM_Warehouse_ID());
//order.setSalesRep_ID(getAD_User_ID());
order.saveEx();
addDescription(Msg.translate(getCtx(), "C_Order_ID") + ": " + order.getDocumentNo());
orders.put(C_BPartner_ID, order);
msg = msg + Msg.translate(getCtx(), "C_Order_ID") + " : " + order.getDocumentNo() + " - " + Msg.translate(getCtx(), "C_BPartner_ID") + " : " + vendor.getName() + " , ";
}
//
// Create Order Line:
BigDecimal QtyOrdered = getMovementQty().multiply(subcontract.getQty());
// Check Order Min
if (product_po.getOrder_Min().signum() > 0) {
QtyOrdered = QtyOrdered.max(product_po.getOrder_Min());
}
// Check Order Pack
if (product_po.getOrder_Pack().signum() > 0 && QtyOrdered.signum() > 0) {
QtyOrdered = product_po.getOrder_Pack().multiply(QtyOrdered.divide(product_po.getOrder_Pack(), 0, BigDecimal.ROUND_UP));
}
MOrderLine oline = new MOrderLine(order);
oline.setM_Product_ID(product.getM_Product_ID());
oline.setDescription(activity.getDescription());
oline.setM_Warehouse_ID(getM_Warehouse_ID());
oline.setQty(QtyOrdered);
//line.setPrice(m_product_po.getPricePO());
//oline.setPriceList(m_product_po.getPriceList());
oline.setPP_Cost_Collector_ID(get_ID());
oline.setDatePromised(datePromised);
oline.saveEx();
//
// TODO: Mark this as processed?
setProcessed(true);
}
// each subcontracting line
return msg;
}
use of org.adempiere.exceptions.NoVendorForProductException in project adempiere by adempiere.
the class RequisitionPOCreate method newLine.
// closeOrder
/**
* New Order Line (different Product)
* @param rLine request line
* @throws Exception
*/
private void newLine(MRequisitionLine rLine) throws Exception {
if (m_orderLine != null) {
m_orderLine.saveEx();
}
m_orderLine = null;
MProduct product = MProduct.get(getCtx(), rLine.getM_Product_ID());
// 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 AdempiereUserError("No Vendor for Charge " + charge.getName());
}
} else {
// Find Strategic Vendor for Product
// TODO: refactor
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 NoVendorForProductException(product.getName());
}
}
if (!isGenerateForVendor(C_BPartner_ID)) {
log.info("Skip for partner " + C_BPartner_ID);
return;
}
// New Order - Different Vendor
if (m_order == null || m_order.getC_BPartner_ID() != C_BPartner_ID || m_order.getDatePromised().compareTo(rLine.getDateRequired()) != 0) {
newOrder(rLine, C_BPartner_ID);
}
// No Order Line
m_orderLine = new MOrderLine(m_order);
m_orderLine.setDatePromised(rLine.getDateRequired());
if (product != null) {
m_orderLine.setProduct(product);
m_orderLine.setM_AttributeSetInstance_ID(rLine.getM_AttributeSetInstance_ID());
} else {
m_orderLine.setC_Charge_ID(rLine.getC_Charge_ID());
m_orderLine.setPriceActual(rLine.getPriceActual());
}
m_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();
m_orderLine.saveEx();
}
Aggregations