This is an automated email from the ASF dual-hosted git repository.

jleroux pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git


The following commit(s) were added to refs/heads/trunk by this push:
     new b57e2d1916 Improved: Replace deprecated BigDecimal.ROUND_HALF by  
RoundingMode.HALF (OFBIZ-13103)
b57e2d1916 is described below

commit b57e2d1916b54ed840f441b03e2356a3a56ecfc4
Author: Jacques Le Roux <jacques.le.r...@les7arts.com>
AuthorDate: Fri May 24 15:45:38 2024 +0200

    Improved: Replace deprecated BigDecimal.ROUND_HALF by  RoundingMode.HALF 
(OFBIZ-13103)
    
    Address this deprecation
    
    int java.math.BigDecimal.ROUND_HALF_UP
    Deprecated. Use RoundingMode.HALF_UP instead.
    
    Rounding mode to round towards "nearest neighbor" unless both neighbors are
    equidistant, in which case round up. Behaves as for ROUND_UP if the 
discarded
    fraction is ≥ 0.5; otherwise, behaves as for ROUND_DOWN. Note that this is 
the
    rounding mode that most of us were taught in grade school.
---
 .../ofbiz/accounting/admin/AcctgAdminServices.groovy   |  6 ++++--
 .../ofbiz/party/party/PartyFinancialHistory.groovy     | 18 ++++++++++--------
 .../ofbiz/party/party/UnAppliedInvoicesForParty.groovy |  6 ++++--
 .../ofbiz/party/party/UnAppliedPaymentsForParty.groovy |  4 +++-
 .../ofbiz/product/catalog/product/BestProducts.groovy  |  4 +++-
 .../java/org/apache/ofbiz/base/util/UtilNumber.java    |  4 ++--
 6 files changed, 26 insertions(+), 16 deletions(-)

diff --git 
a/applications/accounting/src/main/groovy/org/apache/ofbiz/accounting/admin/AcctgAdminServices.groovy
 
b/applications/accounting/src/main/groovy/org/apache/ofbiz/accounting/admin/AcctgAdminServices.groovy
index 1a4dda7b9b..46a6c9e061 100644
--- 
a/applications/accounting/src/main/groovy/org/apache/ofbiz/accounting/admin/AcctgAdminServices.groovy
+++ 
b/applications/accounting/src/main/groovy/org/apache/ofbiz/accounting/admin/AcctgAdminServices.groovy
@@ -19,10 +19,12 @@
 package org.apache.ofbiz.accounting.admin
 
 import java.sql.Timestamp
+import java.math.RoundingMode
+
 import org.apache.ofbiz.base.util.UtilDateTime
 import org.apache.ofbiz.base.util.UtilProperties
-import org.apache.ofbiz.entity.condition.EntityConditionBuilder
 import org.apache.ofbiz.entity.GenericValue
+import org.apache.ofbiz.entity.condition.EntityConditionBuilder
 import org.apache.ofbiz.entity.util.EntityUtil
 import org.apache.ofbiz.service.ModelService
 
@@ -156,7 +158,7 @@ Map getFXConversion() {
 
     BigDecimal conversionRate
     int decimalScale = 2
-    int roundingMode = BigDecimal.ROUND_HALF_UP
+    int roundingMode = RoundingMode.ROUND_HALF_UP
     if (rates) {
         conversionFactor = 
EntityUtil.getFirst(rates).getBigDecimal('conversionFactor')
         BigDecimal originalValue = BigDecimal.ONE
diff --git 
a/applications/party/src/main/groovy/org/apache/ofbiz/party/party/PartyFinancialHistory.groovy
 
b/applications/party/src/main/groovy/org/apache/ofbiz/party/party/PartyFinancialHistory.groovy
index aaca58f5c3..88b30fb882 100644
--- 
a/applications/party/src/main/groovy/org/apache/ofbiz/party/party/PartyFinancialHistory.groovy
+++ 
b/applications/party/src/main/groovy/org/apache/ofbiz/party/party/PartyFinancialHistory.groovy
@@ -18,6 +18,8 @@
 */
 package org.apache.ofbiz.party.party
 
+import java.math.RoundingMode
+
 import org.apache.ofbiz.accounting.invoice.InvoiceWorker
 import org.apache.ofbiz.accounting.payment.PaymentWorker
 import org.apache.ofbiz.entity.condition.EntityCondition
@@ -61,12 +63,12 @@ while (invIterator.next()) {
     Boolean isSalesInvoice = EntityTypeUtil.hasParentType(delegator, 
'InvoiceType', 'invoiceTypeId', (String) invoice.getString('invoiceTypeId'),
             'parentTypeId', 'SALES_INVOICE')
     if (isPurchaseInvoice) {
-        totalInvPuApplied += InvoiceWorker.getInvoiceApplied(invoice, 
actualCurrency).setScale(2, BigDecimal.ROUND_HALF_UP)
-        totalInvPuNotApplied += InvoiceWorker.getInvoiceNotApplied(invoice, 
actualCurrency).setScale(2, BigDecimal.ROUND_HALF_UP)
+        totalInvPuApplied += InvoiceWorker.getInvoiceApplied(invoice, 
actualCurrency).setScale(2, RoundingMode.ROUND_HALF_UP)
+        totalInvPuNotApplied += InvoiceWorker.getInvoiceNotApplied(invoice, 
actualCurrency).setScale(2, RoundingMode.ROUND_HALF_UP)
     }
     else if (isSalesInvoice) {
-        totalInvSaApplied += InvoiceWorker.getInvoiceApplied(invoice, 
actualCurrency).setScale(2, BigDecimal.ROUND_HALF_UP)
-        totalInvSaNotApplied += InvoiceWorker.getInvoiceNotApplied(invoice, 
actualCurrency).setScale(2, BigDecimal.ROUND_HALF_UP)
+        totalInvSaApplied += InvoiceWorker.getInvoiceApplied(invoice, 
actualCurrency).setScale(2, RoundingMode.ROUND_HALF_UP)
+        totalInvSaNotApplied += InvoiceWorker.getInvoiceNotApplied(invoice, 
actualCurrency).setScale(2, RoundingMode.ROUND_HALF_UP)
     }
     else {
         logError('InvoiceType: ' + invoice.invoiceTypeId + ' without a valid 
parentTypeId: ' + invoice.parentTypeId
@@ -101,12 +103,12 @@ payIterator = 
from('PaymentAndType').where(payExprs).cursorScrollInsensitive().d
 while (payIterator.next()) {
     payment = payIterator.next()
     if (payment.parentTypeId == 'DISBURSEMENT' || payment.parentTypeId == 
'TAX_PAYMENT') {
-        totalPayOutApplied += PaymentWorker.getPaymentApplied(payment, 
actualCurrency).setScale(2, BigDecimal.ROUND_HALF_UP)
-        totalPayOutNotApplied += PaymentWorker.getPaymentNotApplied(payment, 
actualCurrency).setScale(2, BigDecimal.ROUND_HALF_UP)
+        totalPayOutApplied += PaymentWorker.getPaymentApplied(payment, 
actualCurrency).setScale(2, RoundingMode.ROUND_HALF_UP)
+        totalPayOutNotApplied += PaymentWorker.getPaymentNotApplied(payment, 
actualCurrency).setScale(2, RoundingMode.ROUND_HALF_UP)
     }
     else if (payment.parentTypeId == 'RECEIPT') {
-        totalPayInApplied += PaymentWorker.getPaymentApplied(payment, 
actualCurrency).setScale(2, BigDecimal.ROUND_HALF_UP)
-        totalPayInNotApplied += PaymentWorker.getPaymentNotApplied(payment, 
actualCurrency).setScale(2, BigDecimal.ROUND_HALF_UP)
+        totalPayInApplied += PaymentWorker.getPaymentApplied(payment, 
actualCurrency).setScale(2, RoundingMode.ROUND_HALF_UP)
+        totalPayInNotApplied += PaymentWorker.getPaymentNotApplied(payment, 
actualCurrency).setScale(2, RoundingMode.ROUND_HALF_UP)
     }
     else {
         logError('PaymentTypeId: ' + payment.paymentTypeId + ' without a valid 
parentTypeId: ' + payment.parentTypeId
diff --git 
a/applications/party/src/main/groovy/org/apache/ofbiz/party/party/UnAppliedInvoicesForParty.groovy
 
b/applications/party/src/main/groovy/org/apache/ofbiz/party/party/UnAppliedInvoicesForParty.groovy
index 61ab4c8fbf..d802a46ad2 100644
--- 
a/applications/party/src/main/groovy/org/apache/ofbiz/party/party/UnAppliedInvoicesForParty.groovy
+++ 
b/applications/party/src/main/groovy/org/apache/ofbiz/party/party/UnAppliedInvoicesForParty.groovy
@@ -18,6 +18,8 @@
 */
 package org.apache.ofbiz.party.party
 
+import java.math.RoundingMode
+
 import org.apache.ofbiz.accounting.invoice.InvoiceWorker
 import org.apache.ofbiz.entity.condition.EntityCondition
 import org.apache.ofbiz.entity.condition.EntityOperator
@@ -48,7 +50,7 @@ invIterator = 
from('InvoiceAndType').where(invExprs).cursorScrollInsensitive().d
 invoiceList = []
 while (invIterator.next()) {
     invoice = invIterator.next()
-    unAppliedAmount = InvoiceWorker.getInvoiceNotApplied(invoice, 
actualCurrency).setScale(2, BigDecimal.ROUND_HALF_UP)
+    unAppliedAmount = InvoiceWorker.getInvoiceNotApplied(invoice, 
actualCurrency).setScale(2, RoundingMode.ROUND_HALF_UP)
     if (unAppliedAmount.signum() == 1) {
         if (actualCurrency == true) {
             invoiceCurrencyUomId = invoice.currencyUomId
@@ -59,7 +61,7 @@ while (invIterator.next()) {
                          invoiceDate: invoice.invoiceDate,
                          unAppliedAmount: unAppliedAmount,
                          invoiceCurrencyUomId: invoiceCurrencyUomId,
-                         amount: InvoiceWorker.getInvoiceTotal(invoice, 
actualCurrency).setScale(2, BigDecimal.ROUND_HALF_UP),
+                         amount: InvoiceWorker.getInvoiceTotal(invoice, 
actualCurrency).setScale(2, RoundingMode.ROUND_HALF_UP),
                          invoiceTypeId: invoice.invoiceTypeId,
                          invoiceParentTypeId: invoice.parentTypeId])
     }
diff --git 
a/applications/party/src/main/groovy/org/apache/ofbiz/party/party/UnAppliedPaymentsForParty.groovy
 
b/applications/party/src/main/groovy/org/apache/ofbiz/party/party/UnAppliedPaymentsForParty.groovy
index 1860746f1e..d105889078 100644
--- 
a/applications/party/src/main/groovy/org/apache/ofbiz/party/party/UnAppliedPaymentsForParty.groovy
+++ 
b/applications/party/src/main/groovy/org/apache/ofbiz/party/party/UnAppliedPaymentsForParty.groovy
@@ -18,6 +18,8 @@
 */
 package org.apache.ofbiz.party.party
 
+import java.math.RoundingMode
+
 import org.apache.ofbiz.accounting.payment.PaymentWorker
 import org.apache.ofbiz.entity.util.EntityFindOptions
 import org.apache.ofbiz.entity.condition.EntityCondition
@@ -50,7 +52,7 @@ payIterator = 
from('PaymentAndType').where(payExprs).cursorScrollInsensitive().d
 
 while (payIterator.next()) {
     payment = payIterator.next()
-    unAppliedAmount = PaymentWorker.getPaymentNotApplied(payment, 
actualCurrency).setScale(2, BigDecimal.ROUND_HALF_UP)
+    unAppliedAmount = PaymentWorker.getPaymentNotApplied(payment, 
actualCurrency).setScale(2, RoundingMode.ROUND_HALF_UP)
     if (unAppliedAmount.signum() == 1) {
         if (actualCurrency == true && payment.actualCurrencyAmount && 
payment.actualCurrencyUomId) {
             amount = payment.actualCurrencyAmount
diff --git 
a/applications/product/src/main/groovy/org/apache/ofbiz/product/catalog/product/BestProducts.groovy
 
b/applications/product/src/main/groovy/org/apache/ofbiz/product/catalog/product/BestProducts.groovy
index eb9ba80469..1ec7153767 100644
--- 
a/applications/product/src/main/groovy/org/apache/ofbiz/product/catalog/product/BestProducts.groovy
+++ 
b/applications/product/src/main/groovy/org/apache/ofbiz/product/catalog/product/BestProducts.groovy
@@ -18,6 +18,8 @@
 */
 package org.apache.ofbiz.product.catalog.product
 
+import java.math.RoundingMode
+
 import org.apache.ofbiz.base.util.UtilDateTime
 import org.apache.ofbiz.entity.condition.EntityCondition
 import org.apache.ofbiz.entity.condition.EntityOperator
@@ -92,7 +94,7 @@ while (itr <= 5) {
     }
     if (!orderItemDetail.isEmpty()) {
         if (orderItemDetail.amount) {
-            orderItemDetail.amount = orderItemDetail.amount.setScale(2, 
BigDecimal.ROUND_HALF_UP)
+            orderItemDetail.amount = orderItemDetail.amount.setScale(2, 
RoundingMode.ROUND_HALF_UP)
         }
         topSellingProducts.add(orderItemDetail)
         bestSellingProducts.remove(orderItemDetail)
diff --git 
a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilNumber.java 
b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilNumber.java
index 0eac51b432..048c1c4b16 100644
--- a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilNumber.java
+++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilNumber.java
@@ -217,7 +217,7 @@ public final class UtilNumber {
      * Method to get BigDecimal rounding mode from a property
      * @param   file     - Name of the property file
      * @param   property - Name of the config property from ARITH_PROP_FILE 
(e.g., "invoice.rounding")
-     * @return  int - Rounding mode to pass to BigDecimal's methods. Defaults 
to BigDecimal.ROUND_HALF_UP
+     * @return  int - Rounding mode to pass to BigDecimal's methods. Defaults 
to RoundingMode.ROUND_HALF_UP
      * @deprecated Use {@link #getRoundingMode(String, String)} instead
      */
     @Deprecated
@@ -228,7 +228,7 @@ public final class UtilNumber {
     /**
      * Method to get BigDecimal rounding mode from a property. Use the default 
ARITH_PROP_FILE properties file
      * @param   property - Name of the config property from ARITH_PROP_FILE 
(e.g., "invoice.rounding")
-     * @return  int - Rounding mode to pass to BigDecimal's methods. Defaults 
to BigDecimal.ROUND_HALF_UP
+     * @return  int - Rounding mode to pass to BigDecimal's methods. Defaults 
to RoundingMode.ROUND_HALF_UP
      * @deprecated Use {@link #getRoundingMode(String)} instead
      */
     @Deprecated

Reply via email to