public IEditablePricingContext createPricingContext( I_C_InvoiceLine invoiceLine, final int priceListId, final BigDecimal priceQty) { final org.compiere.model.I_C_Invoice invoice = invoiceLine.getC_Invoice(); final boolean isSOTrx = invoice.isSOTrx(); final int productId = invoiceLine.getM_Product_ID(); int bPartnerId = invoice.getC_BPartner_ID(); final Timestamp date = invoice.getDateInvoiced(); final IEditablePricingContext pricingCtx = Services.get(IPricingBL.class) .createInitialContext( productId, bPartnerId, invoiceLine.getPrice_UOM_ID(), priceQty, isSOTrx); pricingCtx.setPriceDate(date); // 03152: setting the 'ol' to allow the subscription system to compute the right price pricingCtx.setReferencedObject(invoiceLine); pricingCtx.setM_PriceList_ID(priceListId); // PLV is only accurate if PL selected in header // metas: relay on M_PriceList_ID only, don't use M_PriceList_Version_ID // pricingCtx.setM_PriceList_Version_ID(orderLine.getM_PriceList_Version_ID()); return pricingCtx; }
@Override public void updatePrices(final I_C_InvoiceLine invoiceLine) { // Product was not set yet. There is no point to calculate the prices if (invoiceLine.getM_Product_ID() <= 0) { return; } // // Calculate Pricing Result final IEditablePricingContext pricingCtx = createPricingContext(invoiceLine); final boolean usePriceUOM = InterfaceWrapperHelper.isNew(invoiceLine); pricingCtx.setConvertPriceToContextUOM(!usePriceUOM); pricingCtx.setManualPrice(invoiceLine.isManualPrice()); if (pricingCtx.isManualPrice()) { // Task 08908: do not calculate the prices in case the price is manually set return; } final IPricingResult pricingResult = Services.get(IPricingBL.class).calculatePrice(pricingCtx); if (!pricingResult.isCalculated()) { throw new ProductNotOnPriceListException(pricingCtx, invoiceLine.getLine()); } // // PriceList final BigDecimal priceList = pricingResult.getPriceList(); invoiceLine.setPriceList(priceList); invoiceLine.setPriceLimit(pricingResult.getPriceLimit()); invoiceLine.setPrice_UOM_ID(pricingResult.getPrice_UOM_ID()); invoiceLine.setPriceEntered(pricingResult.getPriceStd()); invoiceLine.setPriceActual(pricingResult.getPriceStd()); // // Discount invoiceLine.setDiscount(pricingResult.getDiscount()); // // Calculate PriceActual from PriceEntered and Discount calculatePriceActual(invoiceLine, pricingResult.getPrecision()); invoiceLine.setPrice_UOM_ID(pricingResult.getPrice_UOM_ID()); // }