use of org.compiere.model.MProduct in project adempiere by adempiere.
the class MPPOrder method isQtyAvailable.
public static boolean isQtyAvailable(MPPOrder order, I_PP_Order_BOMLine line) {
MProduct product = MProduct.get(order.getCtx(), line.getM_Product_ID());
if (product == null || !product.isStocked())
return true;
BigDecimal qtyToDeliver = line.getQtyRequired();
BigDecimal qtyScrap = line.getQtyScrap();
BigDecimal qtyRequired = qtyToDeliver.add(qtyScrap);
BigDecimal qtyAvailable = MStorage.getQtyAvailable(order.getM_Warehouse_ID(), 0, line.getM_Product_ID(), line.getM_AttributeSetInstance_ID(), order.get_TrxName());
return qtyAvailable.compareTo(qtyRequired) >= 0;
}
use of org.compiere.model.MProduct in project adempiere by adempiere.
the class MPPOrder method updateMakeToKit.
/**
* Create Auto Receipt and Issue based on Quantity
* @param qtyShipment
*/
public void updateMakeToKit(BigDecimal qtyShipment) {
MPPOrderBOM orderBOM = (MPPOrderBOM) getMPPOrderBOM();
getLines(true);
// Auto receipt and issue for kit
if (MPPOrderBOM.BOMTYPE_Make_To_Kit.equals(orderBOM.getBOMType()) && MPPOrderBOM.BOMUSE_Manufacturing.equals(orderBOM.getBOMUse())) {
Timestamp today = new Timestamp(System.currentTimeMillis());
ArrayList[][] issue = new ArrayList[m_lines.length][1];
for (int i = 0; i < getLines().length; i++) {
MPPOrderBOMLine line = m_lines[i];
KeyNamePair id = null;
if (MPPOrderBOMLine.ISSUEMETHOD_Backflush.equals(line.getIssueMethod())) {
id = new KeyNamePair(line.get_ID(), "Y");
} else
id = new KeyNamePair(line.get_ID(), "N");
ArrayList<Object> data = new ArrayList<Object>();
BigDecimal qtyToDeliver = qtyShipment.multiply(line.getQtyMultiplier());
//0 - MPPOrderBOMLine ID
data.add(id);
//1 - Critical
data.add(line.isCritical());
MProduct product = (MProduct) line.getM_Product();
//2 - Value
data.add(product.getValue());
KeyNamePair productKey = new KeyNamePair(product.get_ID(), product.getName());
//3 - KeyNamePair Product
data.add(productKey);
//4 - QtyToDeliver
data.add(qtyToDeliver);
//5 - QtyScrapComponent
data.add(Env.ZERO);
issue[i][0] = data;
}
boolean forceIssue = false;
MOrderLine orderLine = (MOrderLine) getC_OrderLine();
if (MOrder.DELIVERYRULE_CompleteLine.equals(orderLine.getParent().getDeliveryRule()) || MOrder.DELIVERYRULE_CompleteOrder.equals(orderLine.getParent().getDeliveryRule())) {
boolean isCompleteQtyDeliver = MPPOrder.isQtyAvailable(this, issue, today);
if (!isCompleteQtyDeliver) {
throw new AdempiereException("@NoQtyAvailable@");
}
} else if (MOrder.DELIVERYRULE_Availability.equals(orderLine.getParent().getDeliveryRule()) || MOrder.DELIVERYRULE_AfterReceipt.equals(orderLine.getParent().getDeliveryRule()) || MOrder.DELIVERYRULE_Manual.equals(orderLine.getParent().getDeliveryRule())) {
throw new AdempiereException("@DeliveryRule@ " + orderLine.getParent().getDeliveryRule() + "@ActionNotSupported@");
} else if (MOrder.DELIVERYRULE_Force.equals(orderLine.getParent().getDeliveryRule())) {
forceIssue = true;
}
for (int i = 0; i < issue.length; i++) {
int attributeSetInstanceId = 0;
KeyNamePair key = (KeyNamePair) issue[i][0].get(0);
Boolean isCritical = (Boolean) issue[i][0].get(1);
String value = (String) issue[i][0].get(2);
KeyNamePair productkey = (KeyNamePair) issue[i][0].get(3);
int productId = productkey.getKey();
MProduct product = MProduct.get(getCtx(), productId);
BigDecimal qtyToDeliver = (BigDecimal) issue[i][0].get(4);
BigDecimal qtyScrapComponent = (BigDecimal) issue[i][0].get(5);
MPPOrderBOMLine orderBOMLine = null;
int orderBOMLineId = (Integer) key.getKey();
if (orderBOMLineId > 0) {
orderBOMLine = new MPPOrderBOMLine(getCtx(), orderBOMLineId, get_TrxName());
//Validate if AttributeSet generate instance
attributeSetInstanceId = orderBOMLine.getM_AttributeSetInstance_ID();
}
MStorage[] storages = MPPOrder.getStorages(getCtx(), productId, getM_Warehouse_ID(), attributeSetInstanceId, today, get_TrxName());
MPPOrder.createIssue(this, orderBOMLine, today, qtyToDeliver, qtyScrapComponent, Env.ZERO, storages, forceIssue);
}
MPPOrder.createReceipt(this, today, getQtyDelivered(), qtyShipment, getQtyScrap(), getQtyReject(), getM_Locator_ID(), getM_AttributeSetInstance_ID());
}
}
use of org.compiere.model.MProduct in project adempiere by adempiere.
the class CalloutBOM method parent.
/**
* Parent cycle check and BOM Line defaults.
* @param ctx Context
* @param WindowNo current Window No
* @param mTab Model Tab
* @param mField Model Field
* @param value The new value
*/
public String parent(Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value) {
if (isCalloutActive() || value == null)
return "";
final int M_Product_ID = (Integer) value;
if (M_Product_ID <= 0)
return "";
I_PP_Product_BOMLine bomLine = GridTabWrapper.create(mTab, I_PP_Product_BOMLine.class);
I_PP_Product_BOM bom = bomLine.getPP_Product_BOM();
if (//Adempiere-272 changes
bom == null) {
throw new AdempiereException("Please save header record first.");
}
if (bom.getM_Product_ID() == bomLine.getM_Product_ID()) {
throw new AdempiereException("@ValidComponent@ - Error Parent not be Component");
}
// Set BOM Line defaults
// May be the parent;
MProduct product = MProduct.get(ctx, M_Product_ID);
bomLine.setDescription(product.getDescription());
bomLine.setHelp(product.getHelp());
bomLine.setC_UOM_ID(product.getC_UOM_ID());
bomLine.setM_AttributeSetInstance_ID(product.getEnvAttributeSetInstance(ctx, WindowNo) == null ? 0 : product.getEnvAttributeSetInstance(ctx, WindowNo));
return "";
}
use of org.compiere.model.MProduct in project adempiere by adempiere.
the class MPPOrder method isQtyAvailable.
/**
* get if Component is Available
* @param MPPOrdrt Manufacturing order
* @param ArrayList Issues
* @param minGuaranteeDate Guarantee Date
* @return true when the qty available is enough
*/
public static boolean isQtyAvailable(MPPOrder order, ArrayList[][] issue, Timestamp minGuaranteeDate) {
boolean isCompleteQtyDeliver = false;
for (int i = 0; i < issue.length; i++) {
KeyNamePair key = (KeyNamePair) issue[i][0].get(0);
boolean isSelected = key.getName().equals("Y");
if (key == null || !isSelected) {
continue;
}
String value = (String) issue[i][0].get(2);
KeyNamePair productkey = (KeyNamePair) issue[i][0].get(3);
int M_Product_ID = productkey.getKey();
BigDecimal qtyToDeliver = (BigDecimal) issue[i][0].get(4);
BigDecimal qtyScrapComponent = (BigDecimal) issue[i][0].get(5);
MProduct product = MProduct.get(order.getCtx(), M_Product_ID);
if (product != null && product.isStocked()) {
int M_AttributeSetInstance_ID = 0;
if (value == null && isSelected) {
M_AttributeSetInstance_ID = (Integer) key.getKey();
} else if (value != null && isSelected) {
int PP_Order_BOMLine_ID = (Integer) key.getKey();
if (PP_Order_BOMLine_ID > 0) {
MPPOrderBOMLine orderBOMLine = new MPPOrderBOMLine(order.getCtx(), PP_Order_BOMLine_ID, order.get_TrxName());
//Validate if AttributeSet generate instance
M_AttributeSetInstance_ID = orderBOMLine.getM_AttributeSetInstance_ID();
}
}
MStorage[] storages = MPPOrder.getStorages(order.getCtx(), M_Product_ID, order.getM_Warehouse_ID(), M_AttributeSetInstance_ID, minGuaranteeDate, order.get_TrxName());
if (M_AttributeSetInstance_ID == 0) {
BigDecimal toIssue = qtyToDeliver.add(qtyScrapComponent);
for (MStorage storage : storages) {
// TODO Selection of ASI
if (storage.getQtyOnHand().signum() == 0)
continue;
BigDecimal issueActual = toIssue.min(storage.getQtyOnHand());
toIssue = toIssue.subtract(issueActual);
if (toIssue.signum() <= 0)
break;
}
} else {
BigDecimal qtydelivered = qtyToDeliver;
qtydelivered.setScale(4, BigDecimal.ROUND_HALF_UP);
qtydelivered = Env.ZERO;
}
BigDecimal onHand = Env.ZERO;
for (MStorage storage : storages) {
onHand = onHand.add(storage.getQtyOnHand());
}
isCompleteQtyDeliver = onHand.compareTo(qtyToDeliver.add(qtyScrapComponent)) >= 0;
if (!isCompleteQtyDeliver)
break;
}
}
return isCompleteQtyDeliver;
}
use of org.compiere.model.MProduct in project adempiere by adempiere.
the class MPPOrderBOMLine method explodePhantom.
/**
* Explode Phantom Items
* TODO: check if BOM and BOM Lines are valid
*/
private void explodePhantom() {
if (m_isExplodePhantom && m_qtyRequiredPhantom != null) {
MProduct parent = MProduct.get(getCtx(), getM_Product_ID());
int PP_Product_BOM_ID = MPPProductBOM.getBOMSearchKey(parent);
if (PP_Product_BOM_ID <= 0) {
return;
}
MPPProductBOM bom = MPPProductBOM.get(getCtx(), PP_Product_BOM_ID);
if (bom != null) {
for (MPPProductBOMLine PP_Product_BOMline : bom.getLines()) {
MPPOrderBOMLine PP_Order_BOMLine = new MPPOrderBOMLine(PP_Product_BOMline, getPP_Order_ID(), getPP_Order_BOM_ID(), getM_Warehouse_ID(), get_TrxName());
PP_Order_BOMLine.setAD_Org_ID(getAD_Org_ID());
PP_Order_BOMLine.setQtyOrdered(m_qtyRequiredPhantom);
PP_Order_BOMLine.saveEx();
}
}
m_isExplodePhantom = false;
}
}
Aggregations