use of org.compiere.model.MProduct in project adempiere by adempiere.
the class CRPDatasetFactory method getTreeNodeRepresentation.
private String getTreeNodeRepresentation(Timestamp dateTime, DefaultMutableTreeNode node, MResource r) {
String name = null;
if (node.getUserObject() instanceof MResource) {
MResource res = (MResource) node.getUserObject();
name = res.getName();
} else if (node.getUserObject() instanceof Timestamp) {
Timestamp d = (Timestamp) node.getUserObject();
SimpleDateFormat df = Env.getLanguage(Env.getCtx()).getDateFormat();
name = df.format(d);
if (!isAvailable(r, d)) {
name = "{" + name + "}";
}
} else if (node.getUserObject() instanceof MPPOrder) {
MPPOrder o = (MPPOrder) node.getUserObject();
MProduct p = MProduct.get(Env.getCtx(), o.getM_Product_ID());
name = o.getDocumentNo() + " (" + p.getName() + ")";
} else if (node.getUserObject() instanceof MPPOrderNode) {
MPPOrderNode on = (MPPOrderNode) node.getUserObject();
MPPOrderWorkflow owf = on.getMPPOrderWorkflow();
MResourceType rt = MResourceType.get(Env.getCtx(), r.getS_ResourceType_ID());
// no function
//Env.getLanguage(Env.getCtx()).getTimeFormat();
SimpleDateFormat df = new SimpleDateFormat("HH:mm");
Timestamp[] interval = getDayBorders(dateTime, on, rt);
name = df.format(interval[0]) + " - " + df.format(interval[1]) + " " + on.getName() + " (" + owf.getName() + ")";
}
return name;
}
use of org.compiere.model.MProduct in project adempiere by adempiere.
the class BOMTreeFactory method getNode.
protected DefaultMutableTreeNode getNode(BOMWrapper bom, BigDecimal qty, HashMap map) {
MProduct product = new MProduct(Env.getCtx(), bom.getM_Product_ID(), MProduct.Table_Name);
DefaultMutableTreeNode parent = new DefaultMutableTreeNode(bom);
;
map.put(parent, getTreeNodeRepresentation(parent));
DefaultMutableTreeNode node = null;
DefaultMutableTreeNode leaf = null;
int[] ids = getStorageReasoner().getPOIDs(BOMLineWrapper.tableName(type()), BOMWrapper.idColumn(type()) + " = " + bom.getID(), null);
BOMLineWrapper bomline = null;
MProduct p = null;
for (int i = 0; i < ids.length; i++) {
bomline = new BOMLineWrapper(Env.getCtx(), ids[i], null, type());
bomline.setQtyBOM(qty != null ? qty.multiply(bomline.getQtyBOM()) : bomline.getQtyBOM());
p = new MProduct(Env.getCtx(), bomline.getM_Product_ID(), null);
node = addLeafs(p, qty, map);
leaf = new DefaultMutableTreeNode(bomline);
map.put(leaf, getTreeNodeRepresentation(leaf));
parent.add((node == null) ? leaf : node);
}
return parent;
}
use of org.compiere.model.MProduct in project adempiere by adempiere.
the class MovementGenerate method createLine.
// generate
/**************************************************************************
* Create Line
* @param Distribution order order
* @param orderLine line
* @param qty qty
* @param storages storage info
* @param force force delivery
*/
private void createLine(MDDOrder order, MDDOrderLine orderLine, BigDecimal qty, MStorage[] storages, boolean force) {
// Complete last Shipment - can have multiple shipments
if (m_lastC_BPartner_Location_ID != order.getC_BPartner_Location_ID())
completeMovement();
m_lastC_BPartner_Location_ID = order.getC_BPartner_Location_ID();
// Create New Shipment
if (m_movement == null) {
MLocator locator = MLocator.get(getCtx(), orderLine.getM_Locator_ID());
m_movement = createMovement(order, m_movementDate);
m_movement.setAD_Org_ID(locator.getAD_Org_ID());
//m_movement.setM_Warehouse_ID(orderLine.getM_Warehouse_ID()); // sets Org too
m_movement.setIsInTransit(true);
m_movement.setDD_Order_ID(order.getDD_Order_ID());
if (order.getC_BPartner_ID() != order.getC_BPartner_ID())
m_movement.setC_BPartner_ID(order.getC_BPartner_ID());
if (order.getC_BPartner_Location_ID() != order.getC_BPartner_Location_ID())
m_movement.setC_BPartner_Location_ID(order.getC_BPartner_Location_ID());
//Look the document type based on organization
int docTypeDO_ID = getDocType(MDocType.DOCBASETYPE_MaterialMovement, m_movement.getAD_Org_ID());
if (docTypeDO_ID > 0)
m_movement.setC_DocType_ID(docTypeDO_ID);
if (!m_movement.save())
throw new IllegalStateException("Could not create Movement");
}
// Non Inventory Lines
if (storages == null) {
MMovementLine line = new MMovementLine(m_movement);
line.setOrderLine(orderLine, Env.ZERO, false);
// Correct UOM
line.setMovementQty(qty);
if (orderLine.getQtyEntered().compareTo(orderLine.getQtyOrdered()) != 0)
line.setMovementQty(qty.multiply(orderLine.getQtyEntered()).divide(orderLine.getQtyOrdered(), 12, BigDecimal.ROUND_HALF_UP));
line.setLine(m_line + orderLine.getLine());
if (!line.save())
throw new IllegalStateException("Could not create Shipment Line");
log.fine(line.toString());
return;
}
// Product
MProduct product = orderLine.getProduct();
boolean linePerASI = false;
if (product.getM_AttributeSet_ID() != 0) {
MAttributeSet mas = MAttributeSet.get(getCtx(), product.getM_AttributeSet_ID());
linePerASI = mas.isInstanceAttribute();
}
// Inventory Lines
ArrayList<MMovementLine> list = new ArrayList<MMovementLine>();
BigDecimal toDeliver = qty;
for (int i = 0; i < storages.length; i++) {
MStorage storage = storages[i];
BigDecimal deliver = toDeliver;
// Not enough On Hand
if (deliver.compareTo(storage.getQtyOnHand()) > 0 && // positive storage
storage.getQtyOnHand().signum() >= 0) {
if (// Adjust to OnHand Qty
!force || // if force not on last location
(force && i + 1 != storages.length))
deliver = storage.getQtyOnHand();
}
if (// zero deliver
deliver.signum() == 0)
continue;
int M_Locator_ID = storage.getM_Locator_ID();
//
MMovementLine line = null;
if (// find line with Locator
!linePerASI) {
for (int ll = 0; ll < list.size(); ll++) {
MMovementLine test = (MMovementLine) list.get(ll);
if (test.getM_Locator_ID() == M_Locator_ID) {
line = test;
break;
}
}
}
if (// new line
line == null) {
line = new MMovementLine(m_movement);
line.setOrderLine(orderLine, deliver, false);
line.setMovementQty(deliver);
list.add(line);
} else
// existing line
line.setMovementQty(line.getMovementQty().add(deliver));
if (orderLine.getQtyEntered().compareTo(orderLine.getQtyOrdered()) != 0)
line.setMovementQty(line.getMovementQty().multiply(orderLine.getQtyEntered()).divide(orderLine.getQtyOrdered(), 12, BigDecimal.ROUND_HALF_UP));
line.setLine(m_line + orderLine.getLine());
if (linePerASI)
line.setM_AttributeSetInstance_ID(storage.getM_AttributeSetInstance_ID());
if (!line.save())
throw new IllegalStateException("Could not create Shipment Line");
log.fine("ToDeliver=" + qty + "/" + deliver + " - " + line);
toDeliver = toDeliver.subtract(deliver);
// Temp adjustment
storage.setQtyOnHand(storage.getQtyOnHand().subtract(deliver));
//
if (toDeliver.signum() == 0)
break;
}
if (toDeliver.signum() != 0)
throw new IllegalStateException("Not All Delivered - Remainder=" + toDeliver);
}
use of org.compiere.model.MProduct in project adempiere by adempiere.
the class RollupBillOfMaterial method getFutureCostPriceLowLevel.
/**
* Get the sum Current Cost Price Level Low for this Cost Element
* @param acctSchema
* @param bom MPPProductBOM
* @param costElement MCostElement
* @param trxName
* @return Cost Price Lower Level
*/
private BigDecimal getFutureCostPriceLowLevel(MAcctSchema acctSchema, MPPProductBOM bom, MCostElement costElement, String trxName) {
log.info("Element: " + costElement);
AtomicReference<BigDecimal> costPriceLowLevel = new AtomicReference<>(Env.ZERO);
if (bom == null)
return costPriceLowLevel.get();
//Iterate bom lines
Arrays.stream(bom.getLines()).filter(bomLine -> bomLine != null && !bomLine.isCoProduct()).forEach(bomLine -> {
MProduct component = MProduct.get(getCtx(), bomLine.getM_Product_ID());
MCost cost = MCost.getOrCreate(component, 0, acctSchema, getOrganizationId(), getWarehouseId(), getCostTypeId(), costElement.getM_CostElement_ID());
Boolean includingScrapQty = true;
BigDecimal qty = bomLine.getQty(includingScrapQty);
if (bomLine.isByProduct())
cost.setFutureCostPriceLL(Env.ZERO);
BigDecimal costPrice = cost.getFutureCostPrice().add(cost.getFutureCostPriceLL());
if (costPrice.equals(BigDecimal.ZERO))
costPrice = cost.getCurrentCostPrice().add(cost.getCurrentCostPriceLL());
if (bomLine.getM_Product().getC_UOM_ID() != bomLine.getC_UOM_ID()) {
BigDecimal rate = MUOMConversion.getProductRateFrom(getCtx(), component.getM_Product_ID(), bomLine.getC_UOM_ID());
if (rate == null)
costPrice = costPrice.multiply(BigDecimal.ONE);
else
costPrice = costPrice.multiply(rate);
}
if (bomLine.isPacking()) {
int workflowId = 0;
MProduct product = MProduct.get(getCtx(), bom.getM_Product_ID());
MPPProductPlanning productPlanning = null;
if (workflowId <= 0)
workflowId = MWorkflow.getWorkflowSearchKey(product);
if (workflowId <= 0) {
productPlanning = MPPProductPlanning.find(getCtx(), getOrganizationId(), getWarehouseId(), getResourcePlantId(), product.get_ID(), get_TrxName());
if (productPlanning != null)
workflowId = productPlanning.getAD_Workflow_ID();
else
createNotice(product, "@NotFound@ @PP_Product_Planning_ID@");
}
if (workflowId <= 0)
createNotice(product, "@NotFound@ @AD_Workflow_ID@");
BigDecimal qtyBatchSize = DB.getSQLValueBD(trxName, "SELECT QtyBatchSize FROM AD_Workflow WHERE AD_Workflow_ID=?", workflowId);
if (qtyBatchSize != null && qtyBatchSize.signum() != 0)
qty = qty.divide(qtyBatchSize, acctSchema.getCostingPrecision(), BigDecimal.ROUND_HALF_UP);
}
BigDecimal componentCost = costPrice.multiply(qty);
costPriceLowLevel.updateAndGet(costAmt -> costAmt.add(componentCost));
log.info("CostElement: " + costElement.getName() + ", Component: " + component.getValue() + ", CostPrice: " + costPrice + ", Qty: " + qty + ", Cost: " + componentCost + " => Total Cost Element: " + costPriceLowLevel.get());
});
// BOM line
return costPriceLowLevel.get();
}
use of org.compiere.model.MProduct in project adempiere by adempiere.
the class PP_Product_BOM_Check method raiseError.
// doIt
private void raiseError(String string, String hint) throws Exception {
DB.rollback(false, get_TrxName());
// parent
MProduct xp = new MProduct(getCtx(), p_Record_ID, null);
// set BOM not verified
xp.setIsVerified(false);
xp.saveEx();
String msg = string;
ValueNamePair pp = CLogger.retrieveError();
if (pp != null)
msg = pp.getName() + " - ";
msg += hint;
throw new AdempiereUserError(msg);
}
Aggregations