details: https://code.openbravo.com/erp/devel/pi/rev/33329a8720b2 changeset: 26186:33329a8720b2 user: Atul Gaware <atul.gaware <at> openbravo.com> date: Mon Mar 16 00:07:30 2015 +0530 summary: Fixes Issue 29171:The sales order is not taking into account the unit price of the product when is 0
Corner case regression, when ever unit price is set to zero in the price list details: https://code.openbravo.com/erp/devel/pi/rev/e4c7b3d0a0ff changeset: 26187:e4c7b3d0a0ff user: Alvaro Ferraz <alvaro.ferraz <at> openbravo.com> date: Mon Mar 16 16:35:31 2015 +0100 summary: Related to issue 29171: Update copyright diffstat: src/org/openbravo/erpCommon/ad_callouts/SL_Order_Amt.java | 21 ++------- src/org/openbravo/erpCommon/businessUtility/PriceAdjustment.java | 17 ++++++- 2 files changed, 18 insertions(+), 20 deletions(-) diffs (83 lines): diff -r ed413e5f8b7a -r e4c7b3d0a0ff src/org/openbravo/erpCommon/ad_callouts/SL_Order_Amt.java --- a/src/org/openbravo/erpCommon/ad_callouts/SL_Order_Amt.java Mon Mar 16 14:56:47 2015 +0000 +++ b/src/org/openbravo/erpCommon/ad_callouts/SL_Order_Amt.java Mon Mar 16 16:35:31 2015 +0100 @@ -11,7 +11,7 @@ * under the License. * The Original Code is Openbravo ERP. * The Initial Developer of the Original Code is Openbravo SLU - * All portions are Copyright (C) 2001-2014 Openbravo SLU + * All portions are Copyright (C) 2001-2015 Openbravo SLU * All Rights Reserved. * Contributor(s): ______________________________________. ************************************************************************ @@ -221,13 +221,8 @@ log4j.debug("priceActual:" + priceActual.toString()); if (!cancelPriceAd) { priceStd = PriceAdjustment.calculatePriceStd(order, product, qtyOrdered, priceActual); - if (PriceAdjustment.calculatePriceActual( - order, - product, - qtyOrdered, - (strPriceStd.equals("") ? ZERO : (new BigDecimal(strPriceStd))).setScale( - pricePrecision, BigDecimal.ROUND_HALF_UP)).compareTo(ZERO) == 0 - && priceActual.compareTo(ZERO) == 0) { + if (!priceStd.equals(priceActual) && priceStd.compareTo(ZERO) == 0) { + // Check whether price adjustment sets priceStd as Zero calcDiscount = false; } else { calcDiscount = true; @@ -281,18 +276,12 @@ RoundingMode.HALF_UP); priceStd = FinancialUtils.calculateNetFromGross(strTaxId, baseGrossAmount, pricePrecision, taxBaseAmt, qtyOrdered); - if (PriceAdjustment.calculatePriceActual( - order, - product, - qtyOrdered, - (strGrossUnitPrice.equals("") ? ZERO : (new BigDecimal(strGrossUnitPrice))).setScale( - pricePrecision, BigDecimal.ROUND_HALF_UP)).compareTo(ZERO) == 0 - && grossUnitPrice.compareTo(ZERO) == 0) { + if (!grossBaseUnitPrice.equals(grossUnitPrice) && grossBaseUnitPrice.compareTo(ZERO) == 0) { + // Check whether price adjustment sets grossBaseUnitPrice as Zero calcDiscount = false; } else { calcDiscount = true; } - } resultado.append("new Array(\"inpgrosspricestd\", " + grossBaseUnitPrice.toString() + "),"); diff -r ed413e5f8b7a -r e4c7b3d0a0ff src/org/openbravo/erpCommon/businessUtility/PriceAdjustment.java --- a/src/org/openbravo/erpCommon/businessUtility/PriceAdjustment.java Mon Mar 16 14:56:47 2015 +0000 +++ b/src/org/openbravo/erpCommon/businessUtility/PriceAdjustment.java Mon Mar 16 16:35:31 2015 +0100 @@ -11,7 +11,7 @@ * under the License. * The Original Code is Openbravo ERP. * The Initial Developer of the Original Code is Openbravo SLU - * All portions are Copyright (C) 2014 Openbravo SLU + * All portions are Copyright (C) 2014-2015 Openbravo SLU * All Rights Reserved. * Contributor(s): ______________________________________. ************************************************************************ @@ -116,9 +116,18 @@ } log.debug("promo: " + promo + "- " + promo.getDiscount()); if (applyDiscount) { - priceStd = priceStd.add(promo.getDiscountAmount()).divide( - BigDecimal.ONE.subtract(promo.getDiscount().divide(BigDecimal.valueOf(100), - precision, BigDecimal.ROUND_HALF_UP)), precision, BigDecimal.ROUND_HALF_UP); + // Avoids divide by zero error + if (BigDecimal.ONE.subtract( + promo.getDiscount().divide(BigDecimal.valueOf(100), precision, + BigDecimal.ROUND_HALF_UP)).compareTo(BigDecimal.ZERO) != 0) { + priceStd = priceStd.add(promo.getDiscountAmount()).divide( + BigDecimal.ONE.subtract(promo.getDiscount().divide(BigDecimal.valueOf(100), + precision, BigDecimal.ROUND_HALF_UP)), precision, BigDecimal.ROUND_HALF_UP); + } else { + // 100 % Discount in price adjustment results in priceStd = Zero + priceStd = BigDecimal.ZERO; + } + } } ------------------------------------------------------------------------------ Dive into the World of Parallel Programming The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/ _______________________________________________ Openbravo-commits mailing list Openbravo-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbravo-commits