From 6fbc51b63997f314dece268422380b4f7bf6a2b2 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Wed, 16 Dec 2009 04:21:32 +0000 Subject: [PATCH] Fix [2904193] - Posting zero for interest bank statement line https://sourceforge.net/tracker/?func=detail&atid=879332&aid=2904193&group_id=176962 Found a bigger problem with this - in postgresql reading a zero can lead to read a 0E-12 (zero with scale 12) and the comparison of this number .equals(Env.ZERO) return false - comparing with compareTo returns true SF Tracker: 2904193 --- base/src/org/compiere/acct/FactLine.java | 8 ++++--- base/src/org/compiere/acct/Matcher.java | 2 +- base/src/org/compiere/acct/ProductInfo.java | 18 +++++++-------- .../compiere/model/CalloutTimeExpense.java | 2 +- base/src/org/compiere/model/MAsset.java | 2 +- .../org/compiere/model/MConversionRate.java | 2 +- .../org/compiere/model/MUOMConversion.java | 6 ++--- base/src/org/compiere/model/ProductCost.java | 22 +++++++++---------- .../posterita/businesslogic/POSManager.java | 10 ++++----- .../businesslogic/ShoppingcartManager.java | 2 +- .../POSSalesReportManager.java | 4 ++-- .../businesslogic/stock/StockManager.java | 4 ++-- 12 files changed, 42 insertions(+), 40 deletions(-) diff --git a/base/src/org/compiere/acct/FactLine.java b/base/src/org/compiere/acct/FactLine.java index 0e0a3d1f2b..ae920c4d01 100644 --- a/base/src/org/compiere/acct/FactLine.java +++ b/base/src/org/compiere/acct/FactLine.java @@ -230,20 +230,22 @@ public final class FactLine extends X_Fact_Acct if (AmtSourceCr != null) setAmtSourceCr (AmtSourceCr); // one needs to be non zero - if (getAmtSourceDr().equals(Env.ZERO) && getAmtSourceCr().equals(Env.ZERO)) + if (getAmtSourceDr().compareTo(Env.ZERO)==0 && getAmtSourceCr().compareTo(Env.ZERO)==0) return false; // Currency Precision int precision = MCurrency.getStdPrecision(getCtx(), C_Currency_ID); if (AmtSourceDr != null && AmtSourceDr.scale() > precision) { BigDecimal AmtSourceDr1 = AmtSourceDr.setScale(precision, BigDecimal.ROUND_HALF_UP); - log.warning("Source DR Precision " + AmtSourceDr + " -> " + AmtSourceDr1); + if (AmtSourceDr1.compareTo(AmtSourceDr) != 0) + log.warning("Source DR Precision " + AmtSourceDr + " -> " + AmtSourceDr1); setAmtSourceDr(AmtSourceDr1); } if (AmtSourceCr != null && AmtSourceCr.scale() > precision) { BigDecimal AmtSourceCr1 = AmtSourceCr.setScale(precision, BigDecimal.ROUND_HALF_UP); - log.warning("Source CR Precision " + AmtSourceCr + " -> " + AmtSourceCr1); + if (AmtSourceCr1.compareTo(AmtSourceCr) != 0) + log.warning("Source CR Precision " + AmtSourceCr + " -> " + AmtSourceCr1); setAmtSourceCr(AmtSourceCr1); } return true; diff --git a/base/src/org/compiere/acct/Matcher.java b/base/src/org/compiere/acct/Matcher.java index c210d93eba..caae0744e3 100644 --- a/base/src/org/compiere/acct/Matcher.java +++ b/base/src/org/compiere/acct/Matcher.java @@ -104,7 +104,7 @@ public class Matcher BigDecimal qty1 = rs.getBigDecimal(8); BigDecimal qty2 = rs.getBigDecimal(9); BigDecimal Qty = qty1.min(qty2); - if (Qty.equals(Env.ZERO)) + if (Qty.compareTo(Env.ZERO)==0) continue; Timestamp dateTrx1 = rs.getTimestamp(6); Timestamp dateTrx2 = rs.getTimestamp(7); diff --git a/base/src/org/compiere/acct/ProductInfo.java b/base/src/org/compiere/acct/ProductInfo.java index 08cc528e38..75ec1da2b2 100644 --- a/base/src/org/compiere/acct/ProductInfo.java +++ b/base/src/org/compiere/acct/ProductInfo.java @@ -263,19 +263,19 @@ public class ProductInfo // Try to find non ZERO Price String costSource = "PriceList-PO"; BigDecimal costs = getPriceList (as, true); - if (costs == null || costs.equals(Env.ZERO)) + if (costs == null || costs.compareTo(Env.ZERO)==0) { costSource = "PO Cost"; costs = getPOCost(as); } - if (costs == null || costs.equals(Env.ZERO)) + if (costs == null || costs.compareTo(Env.ZERO)==0) { costSource = "PriceList"; costs = getPriceList (as, false); } // if not found use $1 (to be able to do material transactions) - if (costs == null || costs.equals(Env.ZERO)) + if (costs == null || costs.compareTo(Env.ZERO)==0) { costSource = "Not Found"; costs = new BigDecimal("1"); @@ -341,12 +341,12 @@ public class ProductInfo return null; BigDecimal price = PriceLimit; // best bet - if (price == null || price.equals(Env.ZERO)) + if (price == null || price.compareTo(Env.ZERO)==0) price = PriceStd; - if (price == null || price.equals(Env.ZERO)) + if (price == null || price.compareTo(Env.ZERO)==0) price = PriceList; // Convert - if (price != null && !price.equals(Env.ZERO)) + if (price != null && price.compareTo(Env.ZERO)!=0) price = MConversionRate.convert (as.getCtx(), price, C_Currency_ID, as.getC_Currency_ID(), as.getAD_Client_ID(), 0); @@ -396,12 +396,12 @@ public class ProductInfo return null; BigDecimal cost = PriceLastPO; // best bet - if (cost == null || cost.equals(Env.ZERO)) + if (cost == null || cost.compareTo(Env.ZERO)==0) cost = PricePO; - if (cost == null || cost.equals(Env.ZERO)) + if (cost == null || cost.compareTo(Env.ZERO)==0) cost = PriceList; // Convert - standard precision!! - should be costing precision - if (cost != null && !cost.equals(Env.ZERO)) + if (cost != null && cost.compareTo(Env.ZERO)!=0) cost = MConversionRate.convert (as.getCtx(), cost, C_Currency_ID, as.getC_Currency_ID(), m_AD_Client_ID, m_AD_Org_ID); return cost; diff --git a/base/src/org/compiere/model/CalloutTimeExpense.java b/base/src/org/compiere/model/CalloutTimeExpense.java index 05dfb1d130..1cba9a246f 100644 --- a/base/src/org/compiere/model/CalloutTimeExpense.java +++ b/base/src/org/compiere/model/CalloutTimeExpense.java @@ -193,7 +193,7 @@ public class CalloutTimeExpense extends CalloutEngine // Converted Amount = Unit price BigDecimal ConvertedAmt = ExpenseAmt; // convert if required - if (!ConvertedAmt.equals(Env.ZERO) && C_Currency_To_ID != C_Currency_From_ID.intValue()) + if (ConvertedAmt.compareTo(Env.ZERO)!=0 && C_Currency_To_ID != C_Currency_From_ID.intValue()) { int AD_Client_ID = Env.getContextAsInt (ctx, WindowNo, "AD_Client_ID"); int AD_Org_ID = Env.getContextAsInt (ctx, WindowNo, "AD_Org_ID"); diff --git a/base/src/org/compiere/model/MAsset.java b/base/src/org/compiere/model/MAsset.java index fa56cfb05b..40c0bac119 100644 --- a/base/src/org/compiere/model/MAsset.java +++ b/base/src/org/compiere/model/MAsset.java @@ -239,7 +239,7 @@ public class MAsset extends X_A_Asset public BigDecimal getQty () { BigDecimal qty = super.getQty(); - if (qty == null || qty.equals(Env.ZERO)) + if (qty == null || qty.compareTo(Env.ZERO)==0) setQty(Env.ONE); return super.getQty(); } // getQty diff --git a/base/src/org/compiere/model/MConversionRate.java b/base/src/org/compiere/model/MConversionRate.java index 4bf48f99be..4fcbb96764 100644 --- a/base/src/org/compiere/model/MConversionRate.java +++ b/base/src/org/compiere/model/MConversionRate.java @@ -106,7 +106,7 @@ public class MConversionRate extends X_C_Conversion_Rate { if (Amt == null) throw new IllegalArgumentException("Required parameter missing - Amt"); - if (CurFrom_ID == CurTo_ID || Amt.equals(Env.ZERO)) + if (CurFrom_ID == CurTo_ID || Amt.compareTo(Env.ZERO)==0) return Amt; // Get Rate BigDecimal retValue = getRate (CurFrom_ID, CurTo_ID, diff --git a/base/src/org/compiere/model/MUOMConversion.java b/base/src/org/compiere/model/MUOMConversion.java index 1a5d345906..c95cefb0c2 100644 --- a/base/src/org/compiere/model/MUOMConversion.java +++ b/base/src/org/compiere/model/MUOMConversion.java @@ -62,7 +62,7 @@ public class MUOMConversion extends X_C_UOM_Conversion static public BigDecimal convert (Properties ctx, int C_UOM_ID, int C_UOM_To_ID, BigDecimal qty) { - if (qty == null || qty.equals(Env.ZERO) || C_UOM_ID == C_UOM_To_ID) + if (qty == null || qty.compareTo(Env.ZERO)==0 || C_UOM_ID == C_UOM_To_ID) return qty; BigDecimal retValue = getRate (ctx, C_UOM_ID, C_UOM_To_ID); if (retValue != null) @@ -397,7 +397,7 @@ public class MUOMConversion extends X_C_UOM_Conversion BigDecimal qty, boolean StdPrecision) { // Nothing to do - if (qty == null || qty.equals(Env.ZERO) + if (qty == null || qty.compareTo(Env.ZERO)==0 || C_UOM_From_ID == C_UOM_To_ID) return qty; // @@ -530,7 +530,7 @@ public class MUOMConversion extends X_C_UOM_Conversion int M_Product_ID, int C_UOM_To_ID, BigDecimal qtyPrice) { // No conversion - if (qtyPrice == null || qtyPrice.equals(Env.ZERO) + if (qtyPrice == null || qtyPrice.compareTo(Env.ZERO)==0 || C_UOM_To_ID == 0|| M_Product_ID == 0) { s_log.fine("No Conversion - QtyPrice=" + qtyPrice); diff --git a/base/src/org/compiere/model/ProductCost.java b/base/src/org/compiere/model/ProductCost.java index 2c8127483d..a811927a31 100644 --- a/base/src/org/compiere/model/ProductCost.java +++ b/base/src/org/compiere/model/ProductCost.java @@ -365,12 +365,12 @@ public class ProductCost } // Return Costs - if (costType != null && cost != null && !cost.equals(Env.ZERO)) + if (costType != null && cost != null && cost.compareTo(Env.ZERO)!=0) { log.fine("Costs=" + cost); return cost; } - else if (current != null && !current.equals(Env.ZERO)) + else if (current != null && current.compareTo(Env.ZERO)!=0) { log.fine("Current=" + current); return current; @@ -414,19 +414,19 @@ public class ProductCost // Try to find non ZERO Price String costSource = "PriceList-PO"; BigDecimal costs = getPriceList (as, true); - if (costs == null || costs.equals(Env.ZERO)) + if (costs == null || costs.compareTo(Env.ZERO)==0) { costSource = "PO Cost"; costs = getPOCost(as); } - if (costs == null || costs.equals(Env.ZERO)) + if (costs == null || costs.compareTo(Env.ZERO)==0) { costSource = "PriceList"; costs = getPriceList (as, false); } // if not found use $1 (to be able to do material transactions) - if (costs == null || costs.equals(Env.ZERO)) + if (costs == null || costs.compareTo(Env.ZERO)==0) { costSource = "Not Found"; costs = new BigDecimal("1"); @@ -492,12 +492,12 @@ public class ProductCost return null; BigDecimal price = PriceLimit; // best bet - if (price == null || price.equals(Env.ZERO)) + if (price == null || price.compareTo(Env.ZERO)==0) price = PriceStd; - if (price == null || price.equals(Env.ZERO)) + if (price == null || price.compareTo(Env.ZERO)==0) price = PriceList; // Convert - if (price != null && !price.equals(Env.ZERO)) + if (price != null && price.compareTo(Env.ZERO)!=0) price = MConversionRate.convert (as.getCtx(), price, C_Currency_ID, as.getC_Currency_ID(), as.getAD_Client_ID(), 0); @@ -547,12 +547,12 @@ public class ProductCost return null; BigDecimal cost = PriceLastPO; // best bet - if (cost == null || cost.equals(Env.ZERO)) + if (cost == null || cost.compareTo(Env.ZERO)==0) cost = PricePO; - if (cost == null || cost.equals(Env.ZERO)) + if (cost == null || cost.compareTo(Env.ZERO)==0) cost = PriceList; // Convert - standard precision!! - should be costing precision - if (cost != null && !cost.equals(Env.ZERO)) + if (cost != null && cost.compareTo(Env.ZERO)!=0) cost = MConversionRate.convert (as.getCtx(), cost, C_Currency_ID, as.getC_Currency_ID(), as.getAD_Client_ID(), as.getAD_Org_ID()); return cost; diff --git a/posterita/posterita/src/main/org/posterita/businesslogic/POSManager.java b/posterita/posterita/src/main/org/posterita/businesslogic/POSManager.java index c098f1c781..cbe9b8f6a7 100644 --- a/posterita/posterita/src/main/org/posterita/businesslogic/POSManager.java +++ b/posterita/posterita/src/main/org/posterita/businesslogic/POSManager.java @@ -526,7 +526,7 @@ public class POSManager cashLine.setWriteOffAmt(writeOffAmount); cashLine.setDiscountAmt(discountAmt); - if(!(discountAmt.equals(Env.ZERO))) + if(!(discountAmt.compareTo(Env.ZERO)==0)) { cashLine.setAmount(invoice.getGrandTotal().subtract(discountAmt).subtract(writeOffAmount)); } @@ -570,7 +570,7 @@ public class POSManager paymentCreated = true; BigDecimal amt = null; - if(!(discountAmt.equals(Env.ZERO))) + if(!(discountAmt.compareTo(Env.ZERO)==0)) { amt = invoice.getGrandTotal().subtract(discountAmt).subtract(writeOffAmount); } @@ -833,7 +833,7 @@ public class POSManager } } - if(!subTotal.equals(Env.ZERO)) + if(subTotal.compareTo(Env.ZERO)!=0) { try { @@ -891,11 +891,11 @@ public class POSManager totalLines = totalLines.add(bean.getLineNetAmt()); totalTax = totalTax.add(bean.getTaxAmt()); totalQty=totalQty.add(bean.getQtyTotal()); - if (bean.getDiscountAmt()!=null && !bean.getDiscountAmt().equals(Env.ZERO)) + if (bean.getDiscountAmt()!=null && bean.getDiscountAmt().compareTo(Env.ZERO)!=0) { discountAmt = bean.getDiscountAmt(); } - if (bean.getWriteOffAmt()!=null && !bean.getWriteOffAmt().equals(Env.ZERO)) + if (bean.getWriteOffAmt()!=null && bean.getWriteOffAmt().compareTo(Env.ZERO)!=0) { writeOffAmt = bean.getWriteOffAmt(); } diff --git a/posterita/posterita/src/main/org/posterita/businesslogic/ShoppingcartManager.java b/posterita/posterita/src/main/org/posterita/businesslogic/ShoppingcartManager.java index d8f2e90828..9c1c7c3669 100644 --- a/posterita/posterita/src/main/org/posterita/businesslogic/ShoppingcartManager.java +++ b/posterita/posterita/src/main/org/posterita/businesslogic/ShoppingcartManager.java @@ -295,7 +295,7 @@ public class ShoppingcartManager //weird logic! BigDecimal discountedTotal = bean.getPayAmt(); - /*if(bean.getDiscountAmt()!=null && bean.getDiscountAmt().equals(Env.ZERO)) + /*if(bean.getDiscountAmt()!=null && bean.getDiscountAmt().compareTo(Env.ZERO)==0) { discountedTotal = null; } */ diff --git a/posterita/posterita/src/main/org/posterita/businesslogic/performanceanalysis/POSSalesReportManager.java b/posterita/posterita/src/main/org/posterita/businesslogic/performanceanalysis/POSSalesReportManager.java index 645f30f714..d8dfdffb8d 100644 --- a/posterita/posterita/src/main/org/posterita/businesslogic/performanceanalysis/POSSalesReportManager.java +++ b/posterita/posterita/src/main/org/posterita/businesslogic/performanceanalysis/POSSalesReportManager.java @@ -289,7 +289,7 @@ public class POSSalesReportManager taxAmt = webOrderLineBean.getTaxAmt(); - if(taxAmt.equals(Env.ZERO)) + if(taxAmt.compareTo(Env.ZERO)==0) { if(order.getOrderType().equals(UDIOrderTypes.POS_ORDER.getOrderType())) @@ -859,7 +859,7 @@ public class POSSalesReportManager - if (!sales.equals(Env.ZERO)) + if (sales.compareTo(Env.ZERO)!=0) { BigDecimal profit = sales.subtract(cost); diff --git a/posterita/posterita/src/main/org/posterita/businesslogic/stock/StockManager.java b/posterita/posterita/src/main/org/posterita/businesslogic/stock/StockManager.java index d1e7582011..09fda5e78d 100644 --- a/posterita/posterita/src/main/org/posterita/businesslogic/stock/StockManager.java +++ b/posterita/posterita/src/main/org/posterita/businesslogic/stock/StockManager.java @@ -318,13 +318,13 @@ public class StockManager discountedLineTotal = bean.getPrice(); } - if (discountPercentOnLine != null && !discountPercentOnLine.equals(Env.ZERO)) + if (discountPercentOnLine != null && discountPercentOnLine.compareTo(Env.ZERO)!=0) { BigDecimal discFactor = (Env.ONEHUNDRED.subtract(discountPercentOnLine)).divide(Env.ONEHUNDRED, 12, RoundingMode.HALF_DOWN); actualLineInclTotalPrice = (lineTotal).multiply(discFactor).setScale(2, RoundingMode.HALF_UP); } - else if (discountedLineInclUnitPrice != null && !discountedLineInclUnitPrice.equals(Env.ZERO)) + else if (discountedLineInclUnitPrice != null && discountedLineInclUnitPrice.compareTo(Env.ZERO)!=0) { if(isTaxIncluded) {