Skip to content

Commit

Permalink
Se agrega soporte a matener el porcentaje de descuento de la orden al
Browse files Browse the repository at this point in the history
copiar valores convertidos desde la orden hasta la factura
  • Loading branch information
carlosaparadam committed Aug 9, 2024
1 parent e593ab7 commit 1fe81ae
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public String modelChange(PO entity, int type) throws Exception {
if(!invoice.isReversal()
&& documentType.get_ValueAsBoolean(LVEUtil.COLUMNNAME_IsInvoicedWithOrgCurrency)
&& invoiceCurrencyId > 0) {
OrganizationRulesUtil.recalculateInvoiceLineRate(invoice, invoiceLine);
OrganizationRulesUtil.recalculateInvoiceLineRate(invoice, invoiceLine, true);
}
}
} else if(entity.get_TableName().equals(I_C_Invoice.Table_Name)) {
Expand All @@ -109,7 +109,7 @@ public String modelChange(PO entity, int type) throws Exception {
invoice.setC_Currency_ID(newCurrency.getC_Currency_ID());
// Recalculate Lines
Arrays.asList(invoice.getLines(true)).forEach(invoiceLine -> {
OrganizationRulesUtil.recalculateInvoiceLineRate(invoice, invoiceLine);
OrganizationRulesUtil.recalculateInvoiceLineRate(invoice, invoiceLine, true);
invoiceLine.saveEx();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.erpya.lve.util;

import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.util.Optional;

Expand All @@ -28,6 +29,7 @@
import org.compiere.model.MInvoiceLine;
import org.compiere.model.MOrder;
import org.compiere.model.MOrderLine;
import org.compiere.model.MUOMConversion;
import org.compiere.util.Env;

/**
Expand All @@ -37,12 +39,22 @@
public class OrganizationRulesUtil {

/**
* Recaulculate Invoice Line from Order
* Recalculate Invoice Line from Order
* @param invoice
* @param invoiceLine
* @return
*/
public static final void recalculateInvoiceLineRate(MInvoice invoice, MInvoiceLine invoiceLine) {
recalculateInvoiceLineRate(invoice, invoiceLine, false);
}

/**
* Recalculate Invoice Line from Order
* @param invoice
* @param invoiceLine
* @param maintainPriceDiscount
*/
public static final void recalculateInvoiceLineRate(MInvoice invoice, MInvoiceLine invoiceLine, boolean maintainPriceDiscount) {
if(invoiceLine.getC_OrderLine_ID() > 0) {
if(!invoiceLine.isProcessed()) {
MOrderLine orderLine = (MOrderLine) invoiceLine.getC_OrderLine();
Expand All @@ -68,10 +80,30 @@ public static final void recalculateInvoiceLineRate(MInvoice invoice, MInvoiceLi
BigDecimal invoicePriceList = orderPriceList.multiply(conversionRate).setScale(currencyTo.getStdPrecision(), RoundingMode.HALF_UP);
BigDecimal invoicePriceActual = orderPriceActual.multiply(conversionRate).setScale(currencyTo.getStdPrecision(), RoundingMode.HALF_UP);
BigDecimal invoicePriceEntered = orderPriceEntered.multiply(conversionRate).setScale(currencyTo.getStdPrecision(), RoundingMode.HALF_UP);
// Set Price
invoiceLine.setPriceList(invoicePriceList);
invoiceLine.setPriceActual(invoicePriceActual);
invoiceLine.setPriceEntered(invoicePriceEntered);

if (maintainPriceDiscount
&& orderLine.getDiscount().compareTo(Env.ZERO) !=0
&& orderLine.getM_Product_ID() > 0) {
//Set Price
BigDecimal discount = invoicePriceList.multiply(orderLine.getDiscount().divide(Env.ONEHUNDRED, MathContext.DECIMAL128), MathContext.DECIMAL128);
BigDecimal priceWithDiscount = invoicePriceList.subtract(discount);
invoiceLine.setPriceList(invoicePriceList);

if (invoiceLine.getQtyEntered().compareTo(invoiceLine.getQtyInvoiced()) == 0)
invoiceLine.setPrice(priceWithDiscount);
else {
invoiceLine.setPriceActual(priceWithDiscount);
BigDecimal priceEntered = MUOMConversion.convertProductFrom (invoiceLine.getCtx(), invoiceLine.getM_Product_ID(),
invoiceLine.getC_UOM_ID(), invoiceLine.getPriceActual());
invoiceLine.setPriceEntered(priceEntered);
}
}else {
//Set Price
invoiceLine.setPriceList(invoicePriceList);
invoiceLine.setPriceActual(invoicePriceActual);
invoiceLine.setPriceEntered(invoicePriceEntered);
}

invoiceLine.setLineNetAmt();
invoiceLine.setTaxAmt();
}
Expand Down

0 comments on commit 1fe81ae

Please sign in to comment.