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;
}
}
use of org.compiere.model.MProduct in project adempiere by adempiere.
the class MPPOrderBOMLine method reserveStock.
/**
* Reserve Inventory for this BOM Line
*/
protected void reserveStock() {
final int header_M_Warehouse_ID = getParent().getM_Warehouse_ID();
// Check/set WH/Org
if (// enforce WH
header_M_Warehouse_ID != 0) {
if (header_M_Warehouse_ID != getM_Warehouse_ID())
setM_Warehouse_ID(header_M_Warehouse_ID);
if (getAD_Org_ID() != getAD_Org_ID())
setAD_Org_ID(getAD_Org_ID());
}
//
final BigDecimal target = getQtyRequired();
final BigDecimal difference = target.subtract(getQtyReserved()).subtract(getQtyDelivered());
log.fine("Line=" + getLine() + " - Target=" + target + ",Difference=" + difference + " - Requiered=" + getQtyRequired() + ",Reserved=" + getQtyReserved() + ",Delivered=" + getQtyDelivered());
if (difference.signum() == 0) {
return;
}
// Check Product - Stocked and Item
MProduct product = getM_Product();
if (!product.isStocked()) {
return;
}
BigDecimal reserved = difference;
int M_Locator_ID = getM_Locator_ID(reserved);
// Update Storage
if (!MStorage.add(getCtx(), getM_Warehouse_ID(), M_Locator_ID, getM_Product_ID(), getM_AttributeSetInstance_ID(), getM_AttributeSetInstance_ID(), Env.ZERO, reserved, Env.ZERO, get_TrxName())) {
throw new AdempiereException();
}
// update line
setQtyReserved(getQtyReserved().add(difference));
}
use of org.compiere.model.MProduct in project adempiere by adempiere.
the class InfoProductPanel method onEvent.
// isUnconfirmed
public void onEvent(Event e) {
if (!p_loadedOK)
return;
Component component = e.getTarget();
if (component != null) {
// Handle product info specific fields here
if (component.equals(confirmPanel.getButton(ConfirmPanel.A_PATTRIBUTE))) {
// Find the ASI used by the product on the lead row
MProduct mp = MProduct.get(Env.getCtx(), m_M_Product_ID);
// Set title and parameters for the PattributeInstance window
String title = "";
int wh_id = 0;
if (isValidVObject(fWarehouse_ID)) {
title = mp.getName() + " - " + fWarehouse_ID.getDisplay();
wh_id = ((Integer) (fWarehouse_ID.getValue())).intValue();
}
// Get the business partner from the context - it may be different than the Vendor
int bp_id = 0;
String s_bp_id = Env.getContext(Env.getCtx(), p_WindowNo, p_TabNo, "C_BPartner_ID", false);
if (s_bp_id != null && s_bp_id.length() != 0 && (new Integer(s_bp_id).intValue() > 0))
bp_id = new Integer(s_bp_id).intValue();
// Display the window
InfoPAttributeInstancePanel pai = new InfoPAttributeInstancePanel(this, title, wh_id, 0, p_table.getLeadRowKey(), bp_id);
if (!pai.wasCancelled()) {
// Get the results and update the fASI criteria field
m_M_AttributeSetInstance_ID = pai.getM_AttributeSetInstance_ID();
m_M_Locator_ID = pai.getM_Locator_ID();
if (m_M_AttributeSetInstance_ID > 0)
fASI_ID.setValue(m_M_AttributeSetInstance_ID);
else
// No instance
fASI_ID.setValue(0);
}
// looking around.
if (// If the results are saved, we can save now - an ASI is product specific
p_saveResults && m_M_AttributeSetInstance_ID != -1 && !pai.wasCancelled()) {
dispose(p_saveResults);
return;
}
return;
} else if (component instanceof Combobox) {
if (e.getName().equals("onChange")) {
// perform field-specific changes
if (component.equals(fWarehouse_ID.getComponent())) {
if (!isValidVObject(fWarehouse_ID)) {
// Disable the stock button
checkOnlyStock.setSelected(false);
checkOnlyStock.setEnabled(false);
} else
checkOnlyStock.setEnabled(true);
}
}
} else if (component instanceof Checkbox) {
Checkbox cb = (Checkbox) component;
// ShowDetail check box
if (cb.getName() != null && cb.getName().equals("ShowDetail")) {
// Refresh only the ATP tab
refreshAtpTab();
return;
}
} else if (// a tab in the ATP panel is selected
component instanceof Tab) {
if (detailTabBox.getSelectedIndex() == 5) {
checkShowDetail.setEnabled(true);
} else {
checkShowDetail.setEnabled(false);
}
refresh();
return;
}
}
//
super.onEvent(e);
}
Aggregations