use of org.compiere.model.MProductCategory in project adempiere by adempiere.
the class MovementGenerate method generate.
/**
* Generate Shipments
* @param distributionOrders Orders
* @return info
*/
private String generate(List<MDDOrder> distributionOrders) {
distributionOrders.stream().filter(order -> order != null).forEach(order -> {
getCurrentMovement().filter(movement -> movement != null || !isConsolidatetooneDocument()).filter(movement -> movement.getC_BPartner_Location_ID() != order.getC_BPartner_Location_ID() || movement.getM_Shipper_ID() != order.getM_Shipper_ID()).ifPresent(movement -> completeMovement());
log.fine("check: " + order + " - DeliveryRule=" + order.getDeliveryRule());
Timestamp minGuaranteeDate = getMovementDate();
StringBuilder where = new StringBuilder(" 1=1 ");
if (getWarehouseId() > 0)
where.append(" AND ").append(getWarehouseId()).append(" IN (SELECT l.M_Warehouse_ID FROM M_Locator l WHERE l.M_Locator_ID=M_Locator_ID) ");
if (getDatePromised() != null)
where.append(" AND (TRUNC(DatePromised)<=").append(DB.TO_DATE(getDatePromised(), true)).append(" OR DatePromised IS NULL)");
if (!MDDOrder.DELIVERYRULE_Force.equals(order.getDeliveryRule()))
where.append(" AND (DD_OrderLine.M_Product_ID IS NULL").append(" OR EXISTS (SELECT * FROM M_Product p ").append("WHERE DD_OrderLine.M_Product_ID=p.M_Product_ID").append(" AND IsExcludeAutoDelivery='N'))");
if (!isOrderswithunconfirmedShipments())
where.append(" AND NOT EXISTS (SELECT * FROM M_MovementLine iol").append(" INNER JOIN M_Movement io ON (iol.M_Movement_ID=io.M_Movement_ID) ").append("WHERE iol.DD_OrderLine_ID=DD_OrderLine.DD_OrderLine_ID AND io.DocStatus IN ('IP','WC'))");
List<MDDOrderLine> orderLines = order.getLines(where.toString(), "M_Product_ID");
orderLines.stream().filter(orderLine -> orderLine.getM_Product_ID() > 0 || orderLine.getC_Charge_ID() > 0).filter(orderLine -> orderLine.getConfirmedQty().signum() != 0).forEach(orderLine -> {
MLocator locator = new MLocator(getCtx(), orderLine.getM_Locator_ID(), get_TrxName());
if (getWarehouseId() > 0 && locator.getM_Warehouse_ID() != getWarehouseId())
return;
log.fine("check: " + orderLine);
BigDecimal onHand = Env.ZERO;
BigDecimal toDeliver = orderLine.getConfirmedQty();
MProduct product = orderLine.getProduct();
BigDecimal unconfirmedShippedQty = Env.ZERO;
if (isOrderswithunconfirmedShipments() && product != null && toDeliver.signum() != 0) {
String whereLine = "EXISTS (SELECT * FROM M_Movement io WHERE io.M_Movement_ID=M_MovementLine.M_Movement_ID AND io.DocStatus IN ('IP','WC'))";
MMovementLine[] movementLines = MMovementLine.getOfOrderLine(getCtx(), orderLine.getDD_OrderLine_ID(), whereLine, null);
unconfirmedShippedQty = Arrays.asList(movementLines).stream().map(MMovementLine::getMovementQty).reduce(BigDecimal.ZERO, BigDecimal::add);
String logInfo = "Unconfirmed Qty=" + unconfirmedShippedQty + " - ToDeliver=" + orderLine.getConfirmedQty() + "->";
toDeliver = orderLine.getConfirmedQty().subtract(unconfirmedShippedQty);
logInfo += toDeliver;
if (toDeliver.signum() < 0) {
toDeliver = Env.ZERO;
logInfo += " (set to 0)";
}
onHand = onHand.subtract(unconfirmedShippedQty);
log.fine(logInfo);
}
if ((product == null || !product.isStocked()) && (orderLine.getQtyOrdered().signum() == 0 || toDeliver.signum() != 0)) {
if (!MDDOrder.DELIVERYRULE_CompleteOrder.equals(order.getDeliveryRule()))
createLine(order, orderLine, toDeliver, null, false);
return;
}
String policyMaterialIssue = getPolicyIssue(product);
MStorage[] storages = getStorages(locator.getM_Warehouse_ID(), orderLine.getM_Product_ID(), orderLine.getM_AttributeSetInstance_ID(), product.getM_AttributeSet_ID(), orderLine.getM_AttributeSetInstance_ID() == 0, minGuaranteeDate, MClient.MMPOLICY_FiFo.equals(policyMaterialIssue));
onHand = Arrays.asList(storages).stream().map(MStorage::getQtyOnHand).reduce(BigDecimal.ZERO, BigDecimal::add);
boolean fullLine = onHand.compareTo(toDeliver) >= 0 || toDeliver.signum() < 0;
boolean completeOrder = MDDOrder.DELIVERYRULE_CompleteOrder.equals(order.getDeliveryRule());
if (completeOrder && !fullLine) {
log.fine("Failed CompleteOrder - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + "), ToDeliver=" + toDeliver + " - " + orderLine);
return;
} else if (fullLine && MDDOrder.DELIVERYRULE_CompleteLine.equals(order.getDeliveryRule())) {
log.fine("CompleteLine - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + ", ToDeliver=" + toDeliver + " - " + orderLine);
createLine(order, orderLine, toDeliver, storages, false);
} else if (MDDOrder.DELIVERYRULE_Availability.equals(order.getDeliveryRule()) && (onHand.signum() > 0 || orderLine.getConfirmedQty().signum() < 0)) {
BigDecimal deliver = orderLine.getConfirmedQty();
log.fine("Available - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + "), ToDeliver=" + toDeliver + ", Delivering=" + deliver + " - " + orderLine);
if (deliver.compareTo(onHand) > 0)
deliver = onHand;
createLine(order, orderLine, deliver, storages, false);
} else if (MDDOrder.DELIVERYRULE_Force.equals(order.getDeliveryRule())) {
BigDecimal deliver = toDeliver;
log.fine("Force - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + "), ToDeliver=" + toDeliver + ", Delivering=" + deliver + " - " + orderLine);
createLine(order, orderLine, deliver, storages, true);
} else if (MDDOrder.DELIVERYRULE_Manual.equals(order.getDeliveryRule()))
log.fine("Manual - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + ") - " + orderLine);
else
log.fine("Failed: " + order.getDeliveryRule() + " - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + "), ToDeliver=" + toDeliver + " - " + orderLine);
});
boolean completeOrder = MDDOrder.DELIVERYRULE_CompleteOrder.equals(order.getDeliveryRule());
if (completeOrder && MDDOrder.DELIVERYRULE_CompleteOrder.equals(order.getDeliveryRule())) {
for (MDDOrderLine orderLine : orderLines) {
MLocator l = new MLocator(getCtx(), orderLine.getM_Locator_ID(), get_TrxName());
if (getWarehouseId() > 0 && l.getM_Warehouse_ID() != getWarehouseId())
continue;
MProduct product = orderLine.getProduct();
BigDecimal toDeliver = orderLine.getQtyOrdered().subtract(orderLine.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 = getClient().getMMPolicy();
storages = getStorages(l.getM_Warehouse_ID(), orderLine.getM_Product_ID(), orderLine.getM_AttributeSetInstance_ID(), product.getM_AttributeSet_ID(), orderLine.getM_AttributeSetInstance_ID() == 0, minGuaranteeDate, MClient.MMPOLICY_FiFo.equals(MMPolicy));
}
createLine(order, orderLine, toDeliver, storages, false);
}
}
lineNo += 1000;
completeMovement();
});
return "@Created@ = " + createdCount;
}
use of org.compiere.model.MProductCategory in project adempiere by adempiere.
the class MovementGenerate method getPolicyIssue.
// generate
private String getPolicyIssue(MProduct product) {
// Stored Product
MProductCategory pc = MProductCategory.get(product.getCtx(), product.getM_Product_Category_ID());
String policyIssue = pc.getMMPolicy();
if (policyIssue == null || policyIssue.length() == 0)
policyIssue = getClient().getMMPolicy();
return policyIssue;
}
Aggregations