use of org.compiere.model.MProduct in project adempiere by adempiere.
the class CostBillOfMaterial method explodeProduct.
// doIt
/**
* * Generate an Explosion for this product
*
* @param accountSchema
* @param productId
* @param isComponent
*/
private void explodeProduct(MAcctSchema accountSchema, int productId, boolean isComponent) {
MProduct product = MProduct.get(getCtx(), productId);
List<MPPProductBOM> boms = getBOMs(product, isComponent);
if (!isComponent && boms.size() == 0) {
throw new AdempiereException("@Error@ Product is not a BOM");
}
boms.stream().filter(bom -> bom != null).forEach(bom -> {
if (!isComponent)
createLines(accountSchema, bom, null);
levelNo++;
Arrays.stream(bom.getLines()).filter(bomLine -> bomLine != null && bomLine.isActive()).forEach(bomLine -> {
createLines(accountSchema, bom, bomLine);
explodeProduct(accountSchema, bomLine.getM_Product_ID(), true);
});
levelNo--;
});
}
use of org.compiere.model.MProduct in project adempiere by adempiere.
the class CostBillOfMaterial method createLines.
/**
* createLines
*
* @param bom
* @param bomLine
*/
private void createLines(MAcctSchema accountSchema, MPPProductBOM bom, MPPProductBOMLine bomLine) {
MProduct product;
BigDecimal qty;
if (bomLine != null) {
product = MProduct.get(getCtx(), bomLine.getM_Product_ID());
qty = bomLine.getQty();
} else if (bom != null) {
product = MProduct.get(getCtx(), bom.getM_Product_ID());
qty = Env.ONE;
} else {
throw new AdempiereException("@NotFound@ @PP_Product_BOM_ID@");
}
//for (MCostElement costElement : getCostElements())
getCostElements().stream().filter(costElement -> costElement != null).forEach(costElement -> {
X_T_BOMLine reportBOMLine = new X_T_BOMLine(getCtx(), 0, get_TrxName());
reportBOMLine.setAD_Org_ID(getOrganizationId());
reportBOMLine.setM_Warehouse_ID(getWarehouseId());
reportBOMLine.setSel_Product_ID(getProductId());
reportBOMLine.setImplosion(isImplosion);
reportBOMLine.setC_AcctSchema_ID(getAccountingSchemaId());
reportBOMLine.setM_CostType_ID(getCostTypeId());
reportBOMLine.setCostingMethod(getCostingMethod());
reportBOMLine.setAD_PInstance_ID(getAD_PInstance_ID());
reportBOMLine.setM_CostElement_ID(costElement.get_ID());
reportBOMLine.setM_Product_ID(product.get_ID());
reportBOMLine.setM_Warehouse_ID(getWarehouseId());
reportBOMLine.setQtyBOM(qty);
reportBOMLine.setSeqNo(seqNo);
reportBOMLine.setLevelNo(levelNo);
reportBOMLine.setLevels(LEVELS.substring(0, levelNo) + levelNo);
BigDecimal currentCostPrice = Env.ZERO;
BigDecimal currentCostPriceLL = Env.ZERO;
BigDecimal futureCostPrice = Env.ZERO;
BigDecimal futureCostPriceLL = Env.ZERO;
final CostEngine engine = CostEngineFactory.getCostEngine(getAD_Client_ID());
List<MCost> costs = MCost.getByElement(product, accountSchema, getCostTypeId(), getOrganizationId(), getWarehouseId(), 0, costElement.getM_CostElement_ID());
boolean isCostFrozen = false;
for (MCost cost : costs) {
currentCostPrice = currentCostPrice.add(cost.getCurrentCostPrice());
currentCostPriceLL = currentCostPriceLL.add(cost.getCurrentCostPriceLL());
futureCostPrice = futureCostPrice.add(cost.getFutureCostPrice());
futureCostPriceLL = futureCostPriceLL.add(cost.getFutureCostPriceLL());
isCostFrozen = cost.isCostFrozen();
}
reportBOMLine.setCurrentCostPrice(currentCostPrice);
reportBOMLine.setCurrentCostPriceLL(currentCostPriceLL);
reportBOMLine.setFutureCostPrice(currentCostPrice);
reportBOMLine.setFutureCostPriceLL(currentCostPriceLL);
reportBOMLine.setIsCostFrozen(isCostFrozen);
if (bomLine != null) {
reportBOMLine.setPP_Product_BOM_ID(bomLine.getPP_Product_BOM_ID());
reportBOMLine.setPP_Product_BOMLine_ID(bomLine.getPP_Product_BOMLine_ID());
} else if (bom != null) {
reportBOMLine.setPP_Product_BOM_ID(bom.getPP_Product_BOM_ID());
}
reportBOMLine.saveEx();
seqNo++;
});
}
use of org.compiere.model.MProduct in project adempiere by adempiere.
the class MovementGenerate method generate.
// doIt
/**
* Generate Shipments
* @param pstmt Order Query
* @return info
*/
private String generate(PreparedStatement pstmt) {
MClient client = MClient.get(getCtx());
try {
ResultSet rs = pstmt.executeQuery();
while (// Order
rs.next()) {
MDDOrder order = new MDDOrder(getCtx(), rs, get_TrxName());
// New Header different Shipper, Shipment Location
if (!p_ConsolidateDocument || (m_movement != null && (m_movement.getC_BPartner_Location_ID() != order.getC_BPartner_Location_ID() || m_movement.getM_Shipper_ID() != order.getM_Shipper_ID()))) {
completeMovement();
}
log.fine("check: " + order + " - DeliveryRule=" + order.getDeliveryRule());
//
Timestamp minGuaranteeDate = m_movementDate;
boolean completeOrder = MDDOrder.DELIVERYRULE_CompleteOrder.equals(order.getDeliveryRule());
// OrderLine WHERE
String where = " " + p_M_Warehouse_ID + " IN (SELECT l.M_Warehouse_ID FROM M_Locator l WHERE l.M_Locator_ID=M_Locator_ID) ";
if (p_DatePromised != null)
where += " AND (TRUNC(DatePromised)<=" + DB.TO_DATE(p_DatePromised, true) + " OR DatePromised IS NULL)";
// Exclude Auto Delivery if not Force
if (!MDDOrder.DELIVERYRULE_Force.equals(order.getDeliveryRule()))
where += " AND (DD_OrderLine.M_Product_ID IS NULL" + " OR EXISTS (SELECT * FROM M_Product p " + "WHERE DD_OrderLine.M_Product_ID=p.M_Product_ID" + " AND IsExcludeAutoDelivery='N'))";
// Exclude Unconfirmed
if (!p_IsUnconfirmedInOut)
where += " AND NOT EXISTS (SELECT * FROM M_MovementLine iol" + " INNER JOIN M_Movement io ON (iol.M_Movement_ID=io.M_Movement_ID) " + "WHERE iol.DD_OrderLine_ID=DD_OrderLine.DD_OrderLine_ID AND io.DocStatus IN ('IP','WC'))";
// Deadlock Prevention - Order by M_Product_ID
MDDOrderLine[] lines = order.getLines(where, "M_Product_ID");
for (int i = 0; i < lines.length; i++) {
MDDOrderLine line = lines[i];
MLocator l = new MLocator(getCtx(), line.getM_Locator_ID(), get_TrxName());
if (l.getM_Warehouse_ID() != p_M_Warehouse_ID)
continue;
log.fine("check: " + line);
BigDecimal onHand = Env.ZERO;
//BigDecimal toDeliver = line.getQtyOrdered()
//.subtract(line.getQtyDelivered());
BigDecimal toDeliver = line.getConfirmedQty();
MProduct product = line.getProduct();
// Nothing to Deliver
if (product != null && toDeliver.signum() == 0)
continue;
// or it's a charge - Bug#: 1603966
if (line.getC_Charge_ID() != 0 && toDeliver.signum() == 0)
continue;
// Check / adjust for confirmations
BigDecimal unconfirmedShippedQty = Env.ZERO;
if (p_IsUnconfirmedInOut && product != null && toDeliver.signum() != 0) {
String where2 = "EXISTS (SELECT * FROM M_Movement io WHERE io.M_Movement_ID=M_MovementLine.M_Movement_ID AND io.DocStatus IN ('IP','WC'))";
MMovementLine[] iols = MMovementLine.getOfOrderLine(getCtx(), line.getDD_OrderLine_ID(), where2, null);
for (int j = 0; j < iols.length; j++) unconfirmedShippedQty = unconfirmedShippedQty.add(iols[j].getMovementQty());
String logInfo = "Unconfirmed Qty=" + unconfirmedShippedQty + " - ToDeliver=" + toDeliver + "->";
toDeliver = toDeliver.subtract(unconfirmedShippedQty);
logInfo += toDeliver;
if (toDeliver.signum() < 0) {
toDeliver = Env.ZERO;
logInfo += " (set to 0)";
}
// Adjust On Hand
onHand = onHand.subtract(unconfirmedShippedQty);
log.fine(logInfo);
}
// Comments & lines w/o product & services
if ((product == null || !product.isStocked()) && (// comments
line.getQtyOrdered().signum() == 0 || // lines w/o product
toDeliver.signum() != 0)) {
if (// printed later
!MDDOrder.DELIVERYRULE_CompleteOrder.equals(order.getDeliveryRule()))
createLine(order, line, toDeliver, null, false);
continue;
}
// Stored Product
MProductCategory pc = MProductCategory.get(order.getCtx(), product.getM_Product_Category_ID());
String MMPolicy = pc.getMMPolicy();
if (MMPolicy == null || MMPolicy.length() == 0)
MMPolicy = client.getMMPolicy();
//
MStorage[] storages = getStorages(l.getM_Warehouse_ID(), line.getM_Product_ID(), line.getM_AttributeSetInstance_ID(), product.getM_AttributeSet_ID(), line.getM_AttributeSetInstance_ID() == 0, minGuaranteeDate, MClient.MMPOLICY_FiFo.equals(MMPolicy));
for (int j = 0; j < storages.length; j++) {
MStorage storage = storages[j];
onHand = onHand.add(storage.getQtyOnHand());
}
boolean fullLine = onHand.compareTo(toDeliver) >= 0 || toDeliver.signum() < 0;
// Complete Order
if (completeOrder && !fullLine) {
log.fine("Failed CompleteOrder - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + "), ToDeliver=" + toDeliver + " - " + line);
completeOrder = false;
break;
} else // Complete Line
if (fullLine && MDDOrder.DELIVERYRULE_CompleteLine.equals(order.getDeliveryRule())) {
log.fine("CompleteLine - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + ", ToDeliver=" + toDeliver + " - " + line);
//
createLine(order, line, toDeliver, storages, false);
} else // Availability
if (MDDOrder.DELIVERYRULE_Availability.equals(order.getDeliveryRule()) && (onHand.signum() > 0 || toDeliver.signum() < 0)) {
BigDecimal deliver = toDeliver;
if (deliver.compareTo(onHand) > 0)
deliver = onHand;
log.fine("Available - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + "), ToDeliver=" + toDeliver + ", Delivering=" + deliver + " - " + line);
//
createLine(order, line, deliver, storages, false);
} else // Force
if (MDDOrder.DELIVERYRULE_Force.equals(order.getDeliveryRule())) {
BigDecimal deliver = toDeliver;
log.fine("Force - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + "), ToDeliver=" + toDeliver + ", Delivering=" + deliver + " - " + line);
//
createLine(order, line, deliver, storages, true);
} else // Manual
if (MDDOrder.DELIVERYRULE_Manual.equals(order.getDeliveryRule()))
log.fine("Manual - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + ") - " + line);
else
log.fine("Failed: " + order.getDeliveryRule() + " - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + "), ToDeliver=" + toDeliver + " - " + line);
}
// Complete Order successful
if (completeOrder && MDDOrder.DELIVERYRULE_CompleteOrder.equals(order.getDeliveryRule())) {
for (int i = 0; i < lines.length; i++) {
MDDOrderLine line = lines[i];
MLocator l = new MLocator(getCtx(), line.getM_Locator_ID(), get_TrxName());
if (l.getM_Warehouse_ID() != p_M_Warehouse_ID)
continue;
MProduct product = line.getProduct();
BigDecimal toDeliver = line.getQtyOrdered().subtract(line.getQtyDelivered());
//
MStorage[] storages = null;
if (product != null && product.isStocked()) {
MProductCategory pc = MProductCategory.get(order.getCtx(), product.getM_Product_Category_ID());
String MMPolicy = pc.getMMPolicy();
if (MMPolicy == null || MMPolicy.length() == 0)
MMPolicy = client.getMMPolicy();
//
storages = getStorages(l.getM_Warehouse_ID(), line.getM_Product_ID(), line.getM_AttributeSetInstance_ID(), product.getM_AttributeSet_ID(), line.getM_AttributeSetInstance_ID() == 0, minGuaranteeDate, MClient.MMPOLICY_FiFo.equals(MMPolicy));
}
//
createLine(order, line, toDeliver, storages, false);
}
}
m_line += 1000;
}
// while order
rs.close();
pstmt.close();
pstmt = null;
} catch (Exception e) {
log.log(Level.SEVERE, m_sql, e);
}
try {
if (pstmt != null)
pstmt.close();
pstmt = null;
} catch (Exception e) {
pstmt = null;
}
completeMovement();
return "@Created@ = " + m_created;
}
use of org.compiere.model.MProduct in project adempiere by adempiere.
the class RollupBillOfMaterial method doIt.
// prepare
/**
* Generate Calculate Cost
* @return info
* @throws Exception
*/
protected String doIt() throws Exception {
//Get account schema
MAcctSchema acctSchema = MAcctSchema.get(getCtx(), getAccountingSchemaId());
//Get cost type
MCostType costType = MCostType.get(getCtx(), getCostTypeId());
final List<MCostElement> costElements = getCostElementId() > 0 ? Arrays.asList(MCostElement.get(getCtx(), getCostElementId())) : MCostElement.getCostElement(getCtx(), get_TrxName());
//Get max low level
int maxLowLevel = MPPMRP.getMaxLowLevel(getCtx(), get_TrxName());
// Cost Roll-up for all levels
for (int lowLevel = maxLowLevel; lowLevel >= 0; lowLevel--) {
//Iterate product based in parameters
Arrays.stream(getProductIds(lowLevel)).filter(productId -> productId > 0).forEach(productId -> {
MProduct product = MProduct.get(getCtx(), productId);
I_PP_Product_Planning productPlanning = MPPProductPlanning.find(getCtx(), getOrganizationId(), getWarehouseId(), getResourcePlantId(), productId, get_TrxName());
int bomId = 0;
if (productPlanning != null)
bomId = productPlanning.getPP_Product_BOM_ID();
else
createNotice(product, Msg.parseTranslation(getCtx(), "@NotFound@ @PP_Product_Planning_ID@"));
if (bomId <= 0)
bomId = MPPProductBOM.getBOMSearchKey(product);
MPPProductBOM bom = MPPProductBOM.get(getCtx(), bomId);
if (bom == null)
createNotice(product, Msg.parseTranslation(getCtx(), "@NotFound@ @PP_Product_BOM_ID@"));
Trx.run(new TrxRunnable() {
MAcctSchema acctSchema;
MCostType costType;
MProduct product;
MPPProductBOM bom;
public TrxRunnable setParameters(MAcctSchema acctSchema, MCostType costType, MProduct product, MPPProductBOM bom) {
this.acctSchema = acctSchema;
this.costType = costType;
this.product = product;
this.bom = bom;
return this;
}
public void run(String trxName) {
costElements.stream().filter(costElement -> costElement != null).forEach(costElement -> {
rollup(acctSchema, costType, costElement, product, bom, trxName);
});
}
}.setParameters(acctSchema, costType, product, bom));
});
// Products List
}
// for Low Lever
return "@OK@";
}
use of org.compiere.model.MProduct in project adempiere by adempiere.
the class VOrderReceiptIssue method vetoableChange.
public void vetoableChange(PropertyChangeEvent e) throws PropertyVetoException {
String name = e.getPropertyName();
Object value = e.getNewValue();
log.fine("VOrderReceip.vetoableChange - " + name + "=" + value);
if (value == null)
return;
// PP_Order_ID
if (name.equals("PP_Order_ID")) {
orderField.setValue(value);
MPPOrder pp_order = getPP_Order();
if (pp_order != null) {
setS_Resource_ID(pp_order.getS_Resource_ID());
setM_Warehouse_ID(pp_order.getM_Warehouse_ID());
setDeliveredQty(pp_order.getQtyDelivered());
setOrderedQty(pp_order.getQtyOrdered());
// m_PP_order.getQtyOrdered().subtract(m_PP_order.getQtyDelivered());
setQtyBatchs(pp_order.getQtyBatchs());
setQtyBatchSize(pp_order.getQtyBatchSize());
setOpenQty(pp_order.getQtyOrdered().subtract(pp_order.getQtyDelivered()));
setToDeliverQty(getOpenQty());
setM_Product_ID(pp_order.getM_Product_ID());
MProduct m_product = MProduct.get(Env.getCtx(), pp_order.getM_Product_ID());
setC_UOM_ID(m_product.getC_UOM_ID());
setOrder_UOM_ID(pp_order.getC_UOM_ID());
// Default ASI defined from the Parent BOM Order
setM_AttributeSetInstance_ID(pp_order.getMPPOrderBOM().getM_AttributeSetInstance_ID());
// default to first entry -
pickcombo.setSelectedIndex(0);
// isBackflush
}
}
// PP_Order_ID
}
Aggregations