/** * Updated all inoutLines' PostageFreeStatus according to the respective bPartner's postage free * amount. * * @param ignorePostageFreeAmt if true, the lines qty is not set to {@link BigDecimal#ZERO}, even * if we are below the customer's postage free amount. However, the status is still set. */ @Override public void updatePostageFreeStatus(final boolean ignorePostageFreeAmt) { for (final I_M_InOut shipmentCandidate : getCandidates()) { final I_C_BPartner bPartner = InterfaceWrapperHelper.create(shipmentCandidate.getC_BPartner(), I_C_BPartner.class); final BigDecimal postageFree = (BigDecimal) bPartner.getPostageFreeAmt(); BigDecimal shipmentValue = BigDecimal.ZERO; // if ignorePostageFreeAmount is false and a postage free amount // is set, we need to check if the value of this shipment is // enough to make shipping profitable boolean sufficiantValue = postageFree == null; if (!sufficiantValue) { for (final I_M_InOutLine inOutLine : getLines(shipmentCandidate)) { // access orderLineCache instead of loading the line // from DB final MOrderLine orderLinePO = this.orderLineCache.get(inOutLine.getC_OrderLine_ID()); final BigDecimal lineValue = orderLinePO.getPriceActual().multiply(inOutLine.getQtyEntered()); shipmentValue = shipmentValue.add(lineValue); if (shipmentValue.compareTo(postageFree) >= 0) { sufficiantValue = true; break; } } } for (final I_M_InOutLine inOutLine : getLines(shipmentCandidate)) { final PostageFreeStatus status; if (sufficiantValue) { status = PostageFreeStatus.OK; } else { if (!ignorePostageFreeAmt) { inOutLine.setQtyEntered(BigDecimal.ZERO); inOutLine.setMovementQty(BigDecimal.ZERO); } status = PostageFreeStatus.BELOW_POSTAGEFREE_AMT; if (logger.isInfoEnabled()) { logger.info( "Shipment " + shipmentCandidate.getDocumentNo() + " has an insufficient value of " + shipmentValue.toPlainString() + " (minimum value is " + postageFree.toPlainString() + ")"); } } final MInOutLine inOutLinePO = getPO(inOutLine); line2PostageFreeStatus.put(inOutLinePO, status); } } }