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

surajk 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 c03e27d  Improved: Changed decimals, rounding, zero static variables 
names as per best practices in order component. (#196)
c03e27d is described below

commit c03e27d73e860ccb3a9bd8950f3771d68e8dd0dc
Author: Suraj Khurana <64310724+surajkhur...@users.noreply.github.com>
AuthorDate: Sat Jun 13 14:26:52 2020 +0530

    Improved: Changed decimals, rounding, zero static variables names as per 
best practices in order component. (#196)
    
    (OFBIZ-11804)
    Also make them private data members of the class.
---
 .../apache/ofbiz/order/order/OrderReadHelper.java  | 162 ++++++++++-----------
 .../ofbiz/order/order/OrderReturnServices.java     |  30 ++--
 .../apache/ofbiz/order/order/OrderServices.java    |  67 +++++----
 .../ofbiz/order/shoppingcart/CheckOutHelper.java   |   8 +-
 .../ofbiz/order/shoppingcart/ShoppingCart.java     |  31 ++--
 .../shoppingcart/product/ProductPromoWorker.java   |  15 +-
 6 files changed, 155 insertions(+), 158 deletions(-)

diff --git 
a/applications/order/src/main/java/org/apache/ofbiz/order/order/OrderReadHelper.java
 
b/applications/order/src/main/java/org/apache/ofbiz/order/order/OrderReadHelper.java
index 1e3b8a7..4f13416 100644
--- 
a/applications/order/src/main/java/org/apache/ofbiz/order/order/OrderReadHelper.java
+++ 
b/applications/order/src/main/java/org/apache/ofbiz/order/order/OrderReadHelper.java
@@ -65,14 +65,14 @@ public class OrderReadHelper {
 
     private static final String MODULE = OrderReadHelper.class.getName();
 
-    // scales and rounding modes for BigDecimal math
-    public static final int scale = 
UtilNumber.getBigDecimalScale("order.decimals");
-    public static final RoundingMode rounding = 
UtilNumber.getRoundingMode("order.rounding");
-    public static final int taxCalcScale = 
UtilNumber.getBigDecimalScale("salestax.calc.decimals");
-    public static final int taxFinalScale = 
UtilNumber.getBigDecimalScale("salestax.final.decimals");
-    public static final RoundingMode taxRounding = 
UtilNumber.getRoundingMode("salestax.rounding");
-    public static final BigDecimal ZERO = (BigDecimal.ZERO).setScale(scale, 
rounding);
-    public static final BigDecimal percentage = (new 
BigDecimal("0.01")).setScale(scale, rounding);
+    // scales and ROUNDING modes for BigDecimal math
+    private static final int DECIMALS = 
UtilNumber.getBigDecimalScale("order.decimals");
+    private static final RoundingMode ROUNDING = 
UtilNumber.getRoundingMode("order.rounding");
+    private static final int TAX_SCALE = 
UtilNumber.getBigDecimalScale("salestax.calc.decimals");
+    private static final int TAX_FINAL_SCALE = 
UtilNumber.getBigDecimalScale("salestax.final.decimals");
+    private static final RoundingMode TAX_ROUNDING = 
UtilNumber.getRoundingMode("salestax.rounding");
+    private static final BigDecimal ZERO = 
(BigDecimal.ZERO).setScale(DECIMALS, ROUNDING);
+    private static final BigDecimal PERCENTAGE = (new 
BigDecimal("0.01")).setScale(DECIMALS, ROUNDING);
 
     protected GenericValue orderHeader = null;
     protected List<GenericValue> orderItemAndShipGrp = null;
@@ -236,7 +236,7 @@ public class OrderReadHelper {
             BigDecimal chargedToPaymentPref = ZERO;
             for (GenericValue payment : payments) {
                 if (payment.get("amount") != null) {
-                    chargedToPaymentPref = 
chargedToPaymentPref.add(payment.getBigDecimal("amount")).setScale(scale+1, 
rounding);
+                    chargedToPaymentPref = 
chargedToPaymentPref.add(payment.getBigDecimal("amount")).setScale(DECIMALS+1, 
ROUNDING);
                 }
             }
 
@@ -249,7 +249,7 @@ public class OrderReadHelper {
                         chargedToPaymentPref = chargedToPaymentPref.add(value);
                     }
                 }
-                paymentMethodAmounts.put(paymentMethodKey, 
chargedToPaymentPref.setScale(scale, rounding));
+                paymentMethodAmounts.put(paymentMethodKey, 
chargedToPaymentPref.setScale(DECIMALS, ROUNDING));
             }
         }
         return paymentMethodAmounts;
@@ -271,12 +271,12 @@ public class OrderReadHelper {
             }
             BigDecimal refundedToPaymentPref = ZERO;
             for (GenericValue returnItemResponse : returnItemResponses) {
-                refundedToPaymentPref = 
refundedToPaymentPref.add(returnItemResponse.getBigDecimal("responseAmount")).setScale(scale+1,
 rounding);
+                refundedToPaymentPref = 
refundedToPaymentPref.add(returnItemResponse.getBigDecimal("responseAmount")).setScale(DECIMALS+1,
 ROUNDING);
             }
 
             if (refundedToPaymentPref.compareTo(ZERO) == 1) {
                 String paymentMethodId = 
paymentPref.getString("paymentMethodId") != null ? 
paymentPref.getString("paymentMethodId") : 
paymentPref.getString("paymentMethodTypeId");
-                paymentMethodAmounts.put(paymentMethodId, 
refundedToPaymentPref.setScale(scale, rounding));
+                paymentMethodAmounts.put(paymentMethodId, 
refundedToPaymentPref.setScale(DECIMALS, ROUNDING));
             }
         }
         return paymentMethodAmounts;
@@ -924,12 +924,12 @@ public class OrderReadHelper {
                 }
                 if (product != null) {
                     if (ProductWorker.shippingApplies(product)) {
-                        shippableTotal = 
shippableTotal.add(OrderReadHelper.getOrderItemSubTotal(item, getAdjustments(), 
false, true)).setScale(scale, rounding);
+                        shippableTotal = 
shippableTotal.add(OrderReadHelper.getOrderItemSubTotal(item, getAdjustments(), 
false, true)).setScale(DECIMALS, ROUNDING);
                     }
                 }
             }
         }
-        return shippableTotal.setScale(scale, rounding);
+        return shippableTotal.setScale(DECIMALS, ROUNDING);
     }
 
     public BigDecimal getShippableQuantity() {
@@ -940,7 +940,7 @@ public class OrderReadHelper {
                 shippableQuantity = 
shippableQuantity.add(getShippableQuantity(shipGroup.getString("shipGroupSeqId")));
             }
         }
-        return shippableQuantity.setScale(scale, rounding);
+        return shippableQuantity.setScale(DECIMALS, ROUNDING);
     }
 
     public BigDecimal getShippableQuantity(String shipGroupSeqId) {
@@ -957,12 +957,12 @@ public class OrderReadHelper {
                 }
                 if (product != null) {
                     if (ProductWorker.shippingApplies(product)) {
-                        shippableQuantity = 
shippableQuantity.add(getOrderItemQuantity(item)).setScale(scale, rounding);
+                        shippableQuantity = 
shippableQuantity.add(getOrderItemQuantity(item)).setScale(DECIMALS, ROUNDING);
                     }
                 }
             }
         }
-        return shippableQuantity.setScale(scale, rounding);
+        return shippableQuantity.setScale(DECIMALS, ROUNDING);
     }
 
     public BigDecimal getShippableWeight(String shipGroupSeqId) {
@@ -970,11 +970,11 @@ public class OrderReadHelper {
         List<GenericValue> validItems = getValidOrderItems(shipGroupSeqId);
         if (validItems != null) {
             for (GenericValue item : validItems) {
-                shippableWeight = 
shippableWeight.add(this.getItemWeight(item).multiply(getOrderItemQuantity(item))).setScale(scale,
 rounding);
+                shippableWeight = 
shippableWeight.add(this.getItemWeight(item).multiply(getOrderItemQuantity(item))).setScale(DECIMALS,
 ROUNDING);
             }
         }
 
-        return shippableWeight.setScale(scale, rounding);
+        return shippableWeight.setScale(DECIMALS, ROUNDING);
     }
 
     public BigDecimal getItemWeight(GenericValue item) {
@@ -1039,7 +1039,7 @@ public class OrderReadHelper {
                 continue;
             }
             if (paymentMethodTypeId == null || 
paymentMethodTypeId.equals(preference.get("paymentMethodTypeId"))) {
-                total = 
total.add(preference.getBigDecimal("maxAmount")).setScale(scale, rounding);
+                total = 
total.add(preference.getBigDecimal("maxAmount")).setScale(DECIMALS, ROUNDING);
             }
         }
         return total;
@@ -1087,7 +1087,7 @@ public class OrderReadHelper {
                 if (payment.get("amountApplied") == null) {
                     continue;
                 }
-                total = 
total.add(payment.getBigDecimal("amountApplied")).setScale(scale, rounding);
+                total = 
total.add(payment.getBigDecimal("amountApplied")).setScale(DECIMALS, ROUNDING);
             }
         } catch (GenericEntityException e) {
             Debug.logError(e, e.getMessage(), MODULE);
@@ -1297,7 +1297,7 @@ public class OrderReadHelper {
                 }
             }
         }
-        openAmount = total.subtract(openAmount).setScale(scale, rounding);
+        openAmount = total.subtract(openAmount).setScale(DECIMALS, ROUNDING);
         // return either a positive amount or positive zero
         return openAmount.compareTo(BigDecimal.ZERO) > 0 ? openAmount : 
BigDecimal.ZERO;
     }
@@ -1732,10 +1732,10 @@ public class OrderReadHelper {
         BigDecimal returnedQuantity = ZERO;
         for (GenericValue returnedItem : returnedItems) {
             if (returnedItem.get("returnQuantity") != null) {
-                returnedQuantity = 
returnedQuantity.add(returnedItem.getBigDecimal("returnQuantity")).setScale(scale,
 rounding);
+                returnedQuantity = 
returnedQuantity.add(returnedItem.getBigDecimal("returnQuantity")).setScale(DECIMALS,
 ROUNDING);
             }
         }
-        return returnedQuantity.setScale(scale, rounding);
+        return returnedQuantity.setScale(DECIMALS, ROUNDING);
     }
 
     /**
@@ -1765,7 +1765,7 @@ public class OrderReadHelper {
         List<String> returnHeaderList = new LinkedList<>();
         for (GenericValue returnedItem : returnedItems) {
             if ((returnedItem.get("returnPrice") != null) && 
(returnedItem.get("returnQuantity") != null)) {
-                returnedAmount = 
returnedAmount.add(returnedItem.getBigDecimal("returnPrice").multiply(returnedItem.getBigDecimal("returnQuantity")).setScale(scale,
 rounding));
+                returnedAmount = 
returnedAmount.add(returnedItem.getBigDecimal("returnPrice").multiply(returnedItem.getBigDecimal("returnQuantity")).setScale(DECIMALS,
 ROUNDING));
             }
             Map<String, Object> itemAdjustmentCondition = 
UtilMisc.toMap("returnId", returnedItem.get("returnId"), "returnItemSeqId", 
returnedItem.get("returnItemSeqId"));
             if (UtilValidate.isNotEmpty(returnTypeId)) {
@@ -1779,9 +1779,9 @@ public class OrderReadHelper {
         //get  returnedAmount from returnHeader adjustments whose orderId must 
equals to current orderHeader.orderId
         for (String returnId : returnHeaderList) {
             Map<String, Object> returnHeaderAdjFilter = UtilMisc.<String, 
Object>toMap("returnId", returnId, "returnItemSeqId", "_NA_", "returnTypeId", 
returnTypeId);
-            returnedAmount 
=returnedAmount.add(getReturnAdjustmentTotal(orderHeader.getDelegator(), 
returnHeaderAdjFilter)).setScale(scale, rounding);
+            returnedAmount 
=returnedAmount.add(getReturnAdjustmentTotal(orderHeader.getDelegator(), 
returnHeaderAdjFilter)).setScale(DECIMALS, ROUNDING);
         }
-        return returnedAmount.setScale(scale, rounding);
+        return returnedAmount.setScale(DECIMALS, ROUNDING);
     }
 
     /** Gets the total return credit for COMPLETED and RECEIVED returns. */
@@ -1853,13 +1853,13 @@ public class OrderReadHelper {
             BigDecimal quantityNotReturned = 
itemQuantity.subtract(quantityReturned);
 
             // pro-rated factor (quantity not returned / total items ordered), 
which shouldn't be rounded to 2 decimals
-            BigDecimal factorNotReturned = 
quantityNotReturned.divide(itemQuantity, 100, rounding);
+            BigDecimal factorNotReturned = 
quantityNotReturned.divide(itemQuantity, 100, ROUNDING);
 
-            BigDecimal subTotalNotReturned = 
itemSubTotal.multiply(factorNotReturned).setScale(scale, rounding);
+            BigDecimal subTotalNotReturned = 
itemSubTotal.multiply(factorNotReturned).setScale(DECIMALS, ROUNDING);
 
             // calculate tax and shipping adjustments for each item, add to 
accumulators
-            BigDecimal itemTaxNotReturned = 
itemTaxes.multiply(factorNotReturned).setScale(scale, rounding);
-            BigDecimal itemShippingNotReturned = 
itemShipping.multiply(factorNotReturned).setScale(scale, rounding);
+            BigDecimal itemTaxNotReturned = 
itemTaxes.multiply(factorNotReturned).setScale(DECIMALS, ROUNDING);
+            BigDecimal itemShippingNotReturned = 
itemShipping.multiply(factorNotReturned).setScale(DECIMALS, ROUNDING);
 
             totalSubTotalNotReturned = 
totalSubTotalNotReturned.add(subTotalNotReturned);
             totalTaxNotReturned = totalTaxNotReturned.add(itemTaxNotReturned);
@@ -1871,12 +1871,12 @@ public class OrderReadHelper {
         BigDecimal orderFactorNotReturned = ZERO;
         if (orderItemsSubTotal.signum() != 0) {
             // pro-rated factor (subtotal not returned / item subtotal), which 
shouldn't be rounded to 2 decimals
-            orderFactorNotReturned = 
totalSubTotalNotReturned.divide(orderItemsSubTotal, 100, rounding);
+            orderFactorNotReturned = 
totalSubTotalNotReturned.divide(orderItemsSubTotal, 100, ROUNDING);
         }
-        BigDecimal orderTaxNotReturned = 
this.getHeaderTaxTotal().multiply(orderFactorNotReturned).setScale(scale, 
rounding);
-        BigDecimal orderShippingNotReturned = 
this.getShippingTotal().multiply(orderFactorNotReturned).setScale(scale, 
rounding);
+        BigDecimal orderTaxNotReturned = 
this.getHeaderTaxTotal().multiply(orderFactorNotReturned).setScale(DECIMALS, 
ROUNDING);
+        BigDecimal orderShippingNotReturned = 
this.getShippingTotal().multiply(orderFactorNotReturned).setScale(DECIMALS, 
ROUNDING);
 
-        return 
totalTaxNotReturned.add(totalShippingNotReturned).add(orderTaxNotReturned).add(orderShippingNotReturned).setScale(scale,
 rounding);
+        return 
totalTaxNotReturned.add(totalShippingNotReturned).add(orderTaxNotReturned).add(orderShippingNotReturned).setScale(DECIMALS,
 ROUNDING);
     }
 
     /** Gets the total refunded to the order billing account by type.  Specify 
null to get total over all types. */
@@ -1904,7 +1904,7 @@ public class OrderReadHelper {
                 }
 
                 // we can just add the response amounts
-                returnedAmount = 
returnedAmount.add(returnItemResponse.getBigDecimal("responseAmount")).setScale(scale,
 rounding);
+                returnedAmount = 
returnedAmount.add(returnItemResponse.getBigDecimal("responseAmount")).setScale(DECIMALS,
 ROUNDING);
             }
         } catch (GenericEntityException e) {
             Debug.logError(e, e.getMessage(), MODULE);
@@ -1942,13 +1942,13 @@ public class OrderReadHelper {
                     for (GenericValue res : reses) {
                         BigDecimal nav = 
res.getBigDecimal("quantityNotAvailable");
                         if (nav != null) {
-                            backorder = backorder.add(nav).setScale(scale, 
rounding);
+                            backorder = backorder.add(nav).setScale(DECIMALS, 
ROUNDING);
                         }
                     }
                 }
             }
         }
-        return backorder.setScale(scale, rounding);
+        return backorder.setScale(DECIMALS, ROUNDING);
     }
 
     public BigDecimal getItemPickedQuantityBd(GenericValue orderItem) {
@@ -1971,11 +1971,11 @@ public class OrderReadHelper {
             for (GenericValue pickedItem : picked) {
                 BigDecimal issueQty = pickedItem.getBigDecimal("quantity");
                 if (issueQty != null) {
-                    quantityPicked = 
quantityPicked.add(issueQty).setScale(scale, rounding);
+                    quantityPicked = 
quantityPicked.add(issueQty).setScale(DECIMALS, ROUNDING);
                 }
             }
         }
-        return quantityPicked.setScale(scale, rounding);
+        return quantityPicked.setScale(DECIMALS, ROUNDING);
     }
 
     public BigDecimal getItemShippedQuantity(GenericValue orderItem) {
@@ -1991,10 +1991,10 @@ public class OrderReadHelper {
                 if (issueQty == null) {
                     issueQty = ZERO;
                 }
-                quantityShipped = 
quantityShipped.add(issueQty.subtract(cancelQty)).setScale(scale, rounding);
+                quantityShipped = 
quantityShipped.add(issueQty.subtract(cancelQty)).setScale(DECIMALS, ROUNDING);
             }
         }
-        return quantityShipped.setScale(scale, rounding);
+        return quantityShipped.setScale(DECIMALS, ROUNDING);
     }
 
     public BigDecimal getItemShipGroupAssocShippedQuantity(GenericValue 
orderItem, String shipGroupSeqId) {
@@ -2025,10 +2025,10 @@ public class OrderReadHelper {
                 if (issueQty == null) {
                     issueQty = ZERO;
                 }
-                quantityShipped = 
quantityShipped.add(issueQty.subtract(cancelQty)).setScale(scale, rounding);
+                quantityShipped = 
quantityShipped.add(issueQty.subtract(cancelQty)).setScale(DECIMALS, ROUNDING);
             }
         }
-        return quantityShipped.setScale(scale, rounding);
+        return quantityShipped.setScale(DECIMALS, ROUNDING);
     }
 
     public BigDecimal getItemReservedQuantity(GenericValue orderItem) {
@@ -2039,11 +2039,11 @@ public class OrderReadHelper {
             for (GenericValue res : reses) {
                 BigDecimal quantity = res.getBigDecimal("quantity");
                 if (quantity != null) {
-                    reserved = reserved.add(quantity).setScale(scale, 
rounding);
+                    reserved = reserved.add(quantity).setScale(DECIMALS, 
ROUNDING);
                 }
             }
         }
-        return reserved.setScale(scale, rounding);
+        return reserved.setScale(DECIMALS, ROUNDING);
     }
 
     public BigDecimal getItemBackorderedQuantity(GenericValue orderItem) {
@@ -2062,7 +2062,7 @@ public class OrderReadHelper {
                 if (autoCancel != null || (shipDate != null && 
shipDate.after(promised))) {
                     BigDecimal resQty = res.getBigDecimal("quantity");
                     if (resQty != null) {
-                        backOrdered = backOrdered.add(resQty).setScale(scale, 
rounding);
+                        backOrdered = 
backOrdered.add(resQty).setScale(DECIMALS, ROUNDING);
                     }
                 }
             }
@@ -2073,7 +2073,7 @@ public class OrderReadHelper {
     public BigDecimal getItemPendingShipmentQuantity(GenericValue orderItem) {
         BigDecimal reservedQty = getItemReservedQuantity(orderItem);
         BigDecimal backordered = getItemBackorderedQuantity(orderItem);
-        return reservedQty.subtract(backordered).setScale(scale, rounding);
+        return reservedQty.subtract(backordered).setScale(DECIMALS, ROUNDING);
     }
 
     public BigDecimal getItemCanceledQuantity(GenericValue orderItem) {
@@ -2091,9 +2091,9 @@ public class OrderReadHelper {
         for (int i = 0; i < orderItems.size(); i++) {
             GenericValue oi = orderItems.get(i);
 
-            totalItems = 
totalItems.add(getOrderItemQuantity(oi)).setScale(scale, rounding);
+            totalItems = 
totalItems.add(getOrderItemQuantity(oi)).setScale(DECIMALS, ROUNDING);
         }
-        return totalItems.setScale(scale, rounding);
+        return totalItems.setScale(DECIMALS, ROUNDING);
     }
 
     public BigDecimal getTotalOrderItemsOrderedQuantity() {
@@ -2103,7 +2103,7 @@ public class OrderReadHelper {
         for (int i = 0; i < orderItems.size(); i++) {
             GenericValue oi = orderItems.get(i);
 
-            totalItems = 
totalItems.add(oi.getBigDecimal("quantity")).setScale(scale, rounding);
+            totalItems = 
totalItems.add(oi.getBigDecimal("quantity")).setScale(DECIMALS, ROUNDING);
         }
         return totalItems;
     }
@@ -2296,7 +2296,7 @@ public class OrderReadHelper {
         adjustments = EntityUtil.filterByAnd(adjustments, 
UtilMisc.toList(EntityCondition.makeCondition("orderAdjustmentTypeId", 
EntityOperator.NOT_EQUAL, "SALES_TAX")));
         BigDecimal total = getOrderItemsTotal(orderItems, adjustments);
         BigDecimal adj = getOrderAdjustmentsTotal(orderItems, adjustments);
-        total = ((total.add(taxGrandTotal)).add(adj)).setScale(scale,rounding);
+        total = ((total.add(taxGrandTotal)).add(adj)).setScale(DECIMALS, 
ROUNDING);
         return total;
     }
 
@@ -2382,10 +2382,10 @@ public class OrderReadHelper {
         if (UtilValidate.isNotEmpty(orderHeaderAdjustments)) {
             List<GenericValue> filteredAdjs = 
filterOrderAdjustments(orderHeaderAdjustments, includeOther, includeTax, 
includeShipping, false, false);
             for (GenericValue orderAdjustment : filteredAdjs) {
-                adjTotal = 
adjTotal.add(OrderReadHelper.calcOrderAdjustment(orderAdjustment, 
subTotal)).setScale(scale, rounding);
+                adjTotal = 
adjTotal.add(OrderReadHelper.calcOrderAdjustment(orderAdjustment, 
subTotal)).setScale(DECIMALS, ROUNDING);
             }
         }
-        return adjTotal.setScale(scale, rounding);
+        return adjTotal.setScale(DECIMALS, ROUNDING);
     }
 
     public static BigDecimal calcOrderAdjustment(GenericValue orderAdjustment, 
BigDecimal orderSubTotal) {
@@ -2396,13 +2396,13 @@ public class OrderReadHelper {
             adjustment = adjustment.add(amount);
         } else if (orderAdjustment.get("sourcePercentage") != null) {
             BigDecimal percent = 
orderAdjustment.getBigDecimal("sourcePercentage");
-            BigDecimal amount = 
orderSubTotal.multiply(percent).multiply(percentage);
+            BigDecimal amount = 
orderSubTotal.multiply(percent).multiply(PERCENTAGE);
             adjustment = adjustment.add(amount);
         }
         if ("SALES_TAX".equals(orderAdjustment.get("orderAdjustmentTypeId"))) {
-            return adjustment.setScale(taxCalcScale, taxRounding);
+            return adjustment.setScale(TAX_SCALE, TAX_ROUNDING);
         }
-        return adjustment.setScale(scale, rounding);
+        return adjustment.setScale(DECIMALS, ROUNDING);
     }
 
     // ================= Order Item Adjustments =================
@@ -2423,15 +2423,15 @@ public class OrderReadHelper {
                 while (weIter != null && weIter.hasNext()) {
                     GenericValue workEffort = weIter.next();
                     if 
(workEffort.getString("workEffortId").compareTo(orderItem.getString("orderItemSeqId"))
 == 0)    {
-                        itemTotal = 
itemTotal.multiply(getWorkEffortRentalQuantity(workEffort)).setScale(scale, 
rounding);
+                        itemTotal = 
itemTotal.multiply(getWorkEffortRentalQuantity(workEffort)).setScale(DECIMALS, 
ROUNDING);
                         break;
                     }
                 }
             }
-            result = result.add(itemTotal).setScale(scale, rounding);
+            result = result.add(itemTotal).setScale(DECIMALS, ROUNDING);
 
         }
-        return result.setScale(scale, rounding);
+        return result.setScale(DECIMALS, ROUNDING);
     }
 
     /** The passed adjustments can be all adjustments for the order, ie for 
all line items */
@@ -2480,7 +2480,7 @@ public class OrderReadHelper {
         // subtotal also includes non tax and shipping adjustments; tax and 
shipping will be calculated using this adjusted value
         result = result.add(getOrderItemAdjustmentsTotal(orderItem, 
adjustments, true, false, false, forTax, forShipping));
 
-        return result.setScale(scale, rounding);
+        return result.setScale(DECIMALS, ROUNDING);
     }
 
     public static BigDecimal getOrderItemsTotal(List<GenericValue> orderItems, 
List<GenericValue> adjustments) {
@@ -2490,7 +2490,7 @@ public class OrderReadHelper {
         while (itemIter != null && itemIter.hasNext()) {
             result = result.add(getOrderItemTotal(itemIter.next(), 
adjustments));
         }
-        return result.setScale(scale,  rounding);
+        return result.setScale(DECIMALS,  ROUNDING);
     }
 
     public static BigDecimal getOrderItemTotal(GenericValue orderItem, 
List<GenericValue> adjustments) {
@@ -2508,12 +2508,12 @@ public class OrderReadHelper {
             while (promoAdjIter.hasNext()) {
                 GenericValue promoAdjustment = promoAdjIter.next();
                 if (promoAdjustment != null) {
-                    BigDecimal amount = 
promoAdjustment.getBigDecimal("amount").setScale(taxCalcScale, taxRounding);
+                    BigDecimal amount = 
promoAdjustment.getBigDecimal("amount").setScale(TAX_SCALE, TAX_ROUNDING);
                     promoAdjTotal = promoAdjTotal.add(amount);
                 }
             }
         }
-        return promoAdjTotal.setScale(scale, rounding);
+        return promoAdjTotal.setScale(DECIMALS, ROUNDING);
     }
 
     public static BigDecimal getWorkEffortRentalLength(GenericValue 
workEffort) {
@@ -2558,7 +2558,7 @@ public class OrderReadHelper {
             }
         }
         rentalAdjustment = rentalAdjustment.add(new BigDecimal(100));  // add 
final 100 percent for first person
-        rentalAdjustment = rentalAdjustment.divide(new BigDecimal(100), scale, 
rounding).multiply(new BigDecimal(String.valueOf(length)));
+        rentalAdjustment = rentalAdjustment.divide(new BigDecimal(100), 
DECIMALS, ROUNDING).multiply(new BigDecimal(String.valueOf(length)));
         return rentalAdjustment; // return total rental adjustment
     }
 
@@ -2569,7 +2569,7 @@ public class OrderReadHelper {
         while (itemIter != null && itemIter.hasNext()) {
             result = result.add(getOrderItemAdjustmentsTotal(itemIter.next(), 
adjustments, includeOther, includeTax, includeShipping));
         }
-        return result.setScale(scale, rounding);
+        return result.setScale(DECIMALS, ROUNDING);
     }
 
     /** The passed adjustments can be all adjustments for the order, ie for 
all line items */
@@ -2620,7 +2620,7 @@ public class OrderReadHelper {
         if (UtilValidate.isNotEmpty(adjustments)) {
             List<GenericValue> filteredAdjs = 
filterOrderAdjustments(adjustments, includeOther, includeTax, includeShipping, 
forTax, forShipping);
             for (GenericValue orderAdjustment : filteredAdjs) {
-                adjTotal = 
adjTotal.add(OrderReadHelper.calcItemAdjustmentRecurringBd(orderAdjustment, 
quantity, unitPrice)).setScale(scale, rounding);
+                adjTotal = 
adjTotal.add(OrderReadHelper.calcItemAdjustmentRecurringBd(orderAdjustment, 
quantity, unitPrice)).setScale(DECIMALS, ROUNDING);
             }
         }
         return adjTotal;
@@ -2636,8 +2636,8 @@ public class OrderReadHelper {
             //shouldn't round amounts here, wait until item total is added up 
otherwise incremental errors are introduced, and there is code that calls this 
method that does that already: adjustment = 
adjustment.add(setScaleByType("SALES_TAX".equals(itemAdjustment.get("orderAdjustmentTypeId")),
 itemAdjustment.getBigDecimal("amount")));
             adjustment = 
adjustment.add(itemAdjustment.getBigDecimal("amount"));
         } else if (itemAdjustment.get("sourcePercentage") != null) {
-            // see comment above about rounding: adjustment = 
adjustment.add(setScaleByType("SALES_TAX".equals(itemAdjustment.get("orderAdjustmentTypeId")),
 
itemAdjustment.getBigDecimal("sourcePercentage").multiply(quantity).multiply(unitPrice).multiply(percentage)));
-            adjustment = 
adjustment.add(itemAdjustment.getBigDecimal("sourcePercentage").multiply(quantity).multiply(unitPrice).multiply(percentage));
+            // see comment above about ROUNDING: adjustment = 
adjustment.add(setScaleByType("SALES_TAX".equals(itemAdjustment.get("orderAdjustmentTypeId")),
 
itemAdjustment.getBigDecimal("sourcePercentage").multiply(quantity).multiply(unitPrice).multiply(PERCENTAGE)));
+            adjustment = 
adjustment.add(itemAdjustment.getBigDecimal("sourcePercentage").multiply(quantity).multiply(unitPrice).multiply(PERCENTAGE));
         }
         if (Debug.verboseOn()) {
             Debug.logVerbose("calcItemAdjustment: " + itemAdjustment + ", 
quantity=" + quantity + ", unitPrice=" + unitPrice + ", adjustment=" + 
adjustment, MODULE);
@@ -2653,7 +2653,7 @@ public class OrderReadHelper {
         if (Debug.verboseOn()) {
             Debug.logVerbose("calcItemAdjustmentRecurring: " + itemAdjustment 
+ ", quantity=" + quantity + ", unitPrice=" + unitPrice + ", 
adjustmentRecurring=" + adjustmentRecurring, MODULE);
         }
-        return adjustmentRecurring.setScale(scale, rounding);
+        return adjustmentRecurring.setScale(DECIMALS, ROUNDING);
     }
 
     public static List<GenericValue> filterOrderAdjustments(List<GenericValue> 
adjustments, boolean includeOther, boolean includeTax, boolean includeShipping, 
boolean forTax, boolean forShipping) {
@@ -2807,9 +2807,9 @@ public class OrderReadHelper {
         return total;
     }
 
-    // little helper method to set the scale according to tax type
+    // little helper method to set the DECIMALS according to tax type
     public static BigDecimal setScaleByType(boolean isTax, BigDecimal value) {
-        return isTax ? value.setScale(taxCalcScale, taxRounding) : 
value.setScale(scale, rounding);
+        return isTax ? value.setScale(TAX_SCALE, TAX_ROUNDING) : 
value.setScale(DECIMALS, ROUNDING);
     }
 
     /** Get the quantity of order items that have been invoiced */
@@ -2949,10 +2949,10 @@ public class OrderReadHelper {
                             if (amount == null) {
                                 amount = ZERO;
                             }
-                            totalAmount = 
totalAmount.add(amount).setScale(taxCalcScale, taxRounding);
+                            totalAmount = 
totalAmount.add(amount).setScale(TAX_SCALE, TAX_ROUNDING);
                             processedAdjustments.add(orderAdjustment);
                         }
-                        totalAmount = totalAmount.setScale(taxFinalScale, 
taxRounding);
+                        totalAmount = totalAmount.setScale(TAX_FINAL_SCALE, 
TAX_ROUNDING);
                         taxByTaxAuthGeoAndPartyList.add(UtilMisc.<String, 
Object>toMap("taxAuthPartyId", taxAuthPartyId, "taxAuthGeoId", taxAuthGeoId, 
"totalAmount", totalAmount));
                         taxGrandTotal = taxGrandTotal.add(totalAmount);
                     }
@@ -2963,9 +2963,9 @@ public class OrderReadHelper {
             missedAdjustments.addAll(orderAdjustments);
             missedAdjustments.removeAll(processedAdjustments);
             for (GenericValue orderAdjustment : missedAdjustments) {
-                taxGrandTotal = 
taxGrandTotal.add(orderAdjustment.getBigDecimal("amount").setScale(taxCalcScale,
 taxRounding));
+                taxGrandTotal = 
taxGrandTotal.add(orderAdjustment.getBigDecimal("amount").setScale(TAX_SCALE, 
TAX_ROUNDING));
             }
-            taxGrandTotal = taxGrandTotal.setScale(taxFinalScale, taxRounding);
+            taxGrandTotal = taxGrandTotal.setScale(TAX_FINAL_SCALE, 
TAX_ROUNDING);
         }
         Map<String, Object> result = new HashMap<>();
         result.put("taxByTaxAuthGeoAndPartyList", taxByTaxAuthGeoAndPartyList);
@@ -3011,10 +3011,10 @@ public class OrderReadHelper {
                                 // this is the only case where the VAT_TAX 
amountAlreadyIncluded should be added in, and should just be for display and 
not to calculate the order grandTotal
                                 totalAmount = 
totalAmount.add(orderAdjustment.getBigDecimal("amountAlreadyIncluded"));
                             }
-                            totalAmount = totalAmount.setScale(taxCalcScale, 
taxRounding);
+                            totalAmount = totalAmount.setScale(TAX_SCALE, 
TAX_ROUNDING);
                             processedAdjustments.add(orderAdjustment);
                         }
-                        totalAmount = totalAmount.setScale(taxFinalScale, 
taxRounding);
+                        totalAmount = totalAmount.setScale(TAX_FINAL_SCALE, 
TAX_ROUNDING);
                         taxByTaxAuthGeoAndPartyList.add(UtilMisc.<String, 
Object>toMap("taxAuthPartyId", taxAuthPartyId, "taxAuthGeoId", taxAuthGeoId, 
"totalAmount", totalAmount));
                         taxGrandTotal = taxGrandTotal.add(totalAmount);
                     }
@@ -3025,9 +3025,9 @@ public class OrderReadHelper {
             missedAdjustments.addAll(orderAdjustmentsToUse);
             missedAdjustments.removeAll(processedAdjustments);
             for (GenericValue orderAdjustment : missedAdjustments) {
-                taxGrandTotal = 
taxGrandTotal.add(orderAdjustment.getBigDecimal("amount").setScale(taxCalcScale,
 taxRounding));
+                taxGrandTotal = 
taxGrandTotal.add(orderAdjustment.getBigDecimal("amount").setScale(TAX_SCALE, 
TAX_ROUNDING));
             }
-            taxGrandTotal = taxGrandTotal.setScale(taxFinalScale, taxRounding);
+            taxGrandTotal = taxGrandTotal.setScale(TAX_FINAL_SCALE, 
TAX_ROUNDING);
         }
         Map<String, Object> result = new HashMap<>();
         result.put("taxByTaxAuthGeoAndPartyList", taxByTaxAuthGeoAndPartyList);
@@ -3075,7 +3075,7 @@ public class OrderReadHelper {
             }
         }
 
-        balance = balance.setScale(scale, rounding);
+        balance = balance.setScale(DECIMALS, ROUNDING);
         return balance;
     }
 
diff --git 
a/applications/order/src/main/java/org/apache/ofbiz/order/order/OrderReturnServices.java
 
b/applications/order/src/main/java/org/apache/ofbiz/order/order/OrderReturnServices.java
index 330069e..d0ff84a 100644
--- 
a/applications/order/src/main/java/org/apache/ofbiz/order/order/OrderReturnServices.java
+++ 
b/applications/order/src/main/java/org/apache/ofbiz/order/order/OrderReturnServices.java
@@ -75,9 +75,9 @@ public class OrderReturnServices {
     private static final String RES_PRODUCT = "ProductUiLabels";
 
     //  set some BigDecimal properties
-    public static final int decimals = 
UtilNumber.getBigDecimalScale("invoice.decimals");
-    public static final RoundingMode rounding = 
UtilNumber.getRoundingMode("invoice.rounding");
-    public static final BigDecimal ZERO = BigDecimal.ZERO.setScale(decimals, 
rounding);
+    private static final int DECIMALS = 
UtilNumber.getBigDecimalScale("invoice.decimals");
+    private static final RoundingMode ROUNDING = 
UtilNumber.getRoundingMode("invoice.rounding");
+    private static final BigDecimal ZERO = BigDecimal.ZERO.setScale(DECIMALS, 
ROUNDING);
 
     // locate the return item's initial inventory item cost
     public static Map<String, Object> getReturnItemInitialCost(DispatchContext 
dctx, Map<String, ? extends Object> context) {
@@ -889,11 +889,11 @@ public class OrderReturnServices {
                 if (price == null) {
                     price = ZERO;
                 }
-                creditTotal = 
creditTotal.add(price.multiply(quantity).setScale(decimals, rounding));
+                creditTotal = 
creditTotal.add(price.multiply(quantity).setScale(DECIMALS, ROUNDING));
             }
 
             // add the adjustments to the total
-            creditTotal = creditTotal.add(adjustments.setScale(decimals, 
rounding));
+            creditTotal = creditTotal.add(adjustments.setScale(DECIMALS, 
ROUNDING));
 
             // create finAccountRole and finAccountTrans
             String finAccountTransId = null;
@@ -1285,7 +1285,7 @@ public class OrderReturnServices {
                     // See how much we can refund to the payment method
                     BigDecimal orderPayPrefReceivedTotal = ZERO;
                     if 
(receivedPaymentTotalsByPaymentMethod.containsKey(orderPayPrefKey)) {
-                        orderPayPrefReceivedTotal = 
orderPayPrefReceivedTotal.add(receivedPaymentTotalsByPaymentMethod.get(orderPayPrefKey)).setScale(decimals,
 rounding);
+                        orderPayPrefReceivedTotal = 
orderPayPrefReceivedTotal.add(receivedPaymentTotalsByPaymentMethod.get(orderPayPrefKey)).setScale(DECIMALS,
 ROUNDING);
                     }
 
                     if (receivedPaymentTotalsByBillingAccount != null) {
@@ -1293,7 +1293,7 @@ public class OrderReturnServices {
                     }
                     BigDecimal orderPayPrefRefundedTotal = ZERO;
                     if 
(refundedTotalsByPaymentMethod.containsKey(orderPayPrefKey)) {
-                        orderPayPrefRefundedTotal = 
orderPayPrefRefundedTotal.add(refundedTotalsByPaymentMethod.get(orderPayPrefKey)).setScale(decimals,
 rounding);
+                        orderPayPrefRefundedTotal = 
orderPayPrefRefundedTotal.add(refundedTotalsByPaymentMethod.get(orderPayPrefKey)).setScale(DECIMALS,
 ROUNDING);
                     }
                     BigDecimal orderPayPrefAvailableTotal = 
orderPayPrefReceivedTotal.subtract(orderPayPrefRefundedTotal);
 
@@ -1311,7 +1311,7 @@ public class OrderReturnServices {
                 }
 
                 // Keep a decreasing total of the amount remaining to refund
-                BigDecimal amountLeftToRefund = orderTotal.setScale(decimals, 
rounding);
+                BigDecimal amountLeftToRefund = orderTotal.setScale(DECIMALS, 
ROUNDING);
 
                 // This can be extended to support additional electronic types
                 List<String> electronicTypes = 
UtilMisc.<String>toList("CREDIT_CARD", "EFT_ACCOUNT", "FIN_ACCOUNT", 
"GIFT_CARD");
@@ -1376,7 +1376,7 @@ public class OrderReturnServices {
                                     serviceContext.put("paymentMethodId", 
orderPaymentPreference.getString("paymentMethodId"));
                                     serviceContext.put("paymentMethodTypeId", 
orderPaymentPreference.getString("paymentMethodTypeId"));
                                     serviceContext.put("statusId", 
orderPaymentPreference.getString("statusId"));
-                                    serviceContext.put("maxAmount", 
amountToRefund.setScale(decimals, rounding));
+                                    serviceContext.put("maxAmount", 
amountToRefund.setScale(DECIMALS, ROUNDING));
                                     String orderPaymentPreferenceNewId = null;
                                     Map<String, Object> result = 
dispatcher.runSync("createOrderPaymentPreference", serviceContext);
                                     if (ServiceUtil.isError(result)) {
@@ -1388,7 +1388,7 @@ public class OrderReturnServices {
                                     } catch (GenericEntityException e) {
                                         return 
ServiceUtil.returnError(UtilProperties.getMessage(RES_ERROR,"OrderProblemsWithTheRefundSeeLogs",
 locale));
                                     }
-                                    serviceResult = 
dispatcher.runSync("refundPayment", UtilMisc.<String, 
Object>toMap("orderPaymentPreference", refundOrderPaymentPreference, 
"refundAmount", amountToRefund.setScale(decimals, rounding), "userLogin", 
userLogin));
+                                    serviceResult = 
dispatcher.runSync("refundPayment", UtilMisc.<String, 
Object>toMap("orderPaymentPreference", refundOrderPaymentPreference, 
"refundAmount", amountToRefund.setScale(DECIMALS, ROUNDING), "userLogin", 
userLogin));
                                     if (ServiceUtil.isError(serviceResult) || 
ServiceUtil.isFailure(serviceResult)) {
                                         Debug.logError("Error in refund 
payment: " + ServiceUtil.getErrorMessage(serviceResult), MODULE);
                                         continue;
@@ -1404,7 +1404,7 @@ public class OrderReturnServices {
                                     // for Billing Account refunds
                                     serviceResult = 
dispatcher.runSync("refundBillingAccountPayment",
                                             UtilMisc.<String, Object> 
toMap("orderPaymentPreference", orderPaymentPreference, "refundAmount",
-                                                    
amountToRefund.setScale(decimals, rounding), "userLogin", userLogin));
+                                                    
amountToRefund.setScale(DECIMALS, ROUNDING), "userLogin", userLogin));
                                     if (ServiceUtil.isError(serviceResult) || 
ServiceUtil.isFailure(serviceResult)) {
                                         Debug.logError("Error in refund 
payment: " + ServiceUtil.getErrorMessage(serviceResult), MODULE);
                                         continue;
@@ -1446,7 +1446,7 @@ public class OrderReturnServices {
                             } else {
                                 response.put("orderPaymentPreferenceId", 
orderPaymentPreference.getString("orderPaymentPreferenceId"));
                             }
-                            response.put("responseAmount", 
amountRefunded.setScale(decimals, rounding));
+                            response.put("responseAmount", 
amountRefunded.setScale(DECIMALS, ROUNDING));
                             response.put("responseDate", now);
                             response.put("userLogin", userLogin);
                             response.put("paymentId", paymentId);
@@ -1620,7 +1620,7 @@ public class OrderReturnServices {
             if (response == null) {
                  return 
ServiceUtil.returnError(UtilProperties.getMessage(RES_ERROR, 
"OrderReturnItemResponseNotFound", UtilMisc.toMap("errorMsg", 
errorMsg,"responseId", responseId), locale));
             }
-            BigDecimal responseAmount = 
response.getBigDecimal("responseAmount").setScale(decimals, rounding);
+            BigDecimal responseAmount = 
response.getBigDecimal("responseAmount").setScale(DECIMALS, ROUNDING);
             String paymentId = response.getString("paymentId");
 
             // for each return item in the response, get the list of return 
item billings and then a list of invoices
@@ -1645,7 +1645,7 @@ public class OrderReturnServices {
                 List<GenericValue> billings = 
invoice.getRelated("ReturnItemBilling", null, null, false);
                 BigDecimal runningTotal = ZERO;
                 for (GenericValue billing : billings) {
-                    runningTotal = 
runningTotal.add(billing.getBigDecimal("amount").multiply(billing.getBigDecimal("quantity")).setScale(decimals,
 rounding));
+                    runningTotal = 
runningTotal.add(billing.getBigDecimal("amount").multiply(billing.getBigDecimal("quantity")).setScale(DECIMALS,
 ROUNDING));
                 }
 
                 invoiceTotals.put(invoice.getString("invoiceId"), 
runningTotal);
@@ -1657,7 +1657,7 @@ public class OrderReturnServices {
                 String invoiceId = invoice.getString("invoiceId");
                 BigDecimal invoiceTotal = invoiceTotals.get(invoiceId);
 
-                BigDecimal amountApplied = 
responseAmount.multiply(invoiceTotal).divide(grandTotal, decimals, 
rounding).setScale(decimals, rounding);
+                BigDecimal amountApplied = 
responseAmount.multiply(invoiceTotal).divide(grandTotal, DECIMALS, 
ROUNDING).setScale(DECIMALS, ROUNDING);
 
                 if (paymentId != null) {
                     // create a payment application for the invoice
diff --git 
a/applications/order/src/main/java/org/apache/ofbiz/order/order/OrderServices.java
 
b/applications/order/src/main/java/org/apache/ofbiz/order/order/OrderServices.java
index 99ff0bf..4223295 100644
--- 
a/applications/order/src/main/java/org/apache/ofbiz/order/order/OrderServices.java
+++ 
b/applications/order/src/main/java/org/apache/ofbiz/order/order/OrderServices.java
@@ -95,26 +95,25 @@ public class OrderServices {
     private static final String RES_ERROR = "OrderErrorUiLabels";
     private static final String RES_PRODUCT = "ProductUiLabels";
 
-    private static Map<String, String> salesAttributeRoleMap = new HashMap<>();
-    private static Map<String, String> purchaseAttributeRoleMap = new 
HashMap<>();
+    private static final Map<String, String> SALES_ROLE_MAP = new HashMap<>();
+    private static final Map<String, String> PURCHASE_ROLE_MAP = new 
HashMap<>();
     static {
-        salesAttributeRoleMap.put("placingCustomerPartyId", 
"PLACING_CUSTOMER");
-        salesAttributeRoleMap.put("billToCustomerPartyId", "BILL_TO_CUSTOMER");
-        salesAttributeRoleMap.put("billFromVendorPartyId", "BILL_FROM_VENDOR");
-        salesAttributeRoleMap.put("shipToCustomerPartyId", "SHIP_TO_CUSTOMER");
-        salesAttributeRoleMap.put("endUserCustomerPartyId", 
"END_USER_CUSTOMER");
-
-        purchaseAttributeRoleMap.put("billToCustomerPartyId", 
"BILL_TO_CUSTOMER");
-        purchaseAttributeRoleMap.put("billFromVendorPartyId", 
"BILL_FROM_VENDOR");
-        purchaseAttributeRoleMap.put("shipFromVendorPartyId", 
"SHIP_FROM_VENDOR");
-        purchaseAttributeRoleMap.put("supplierAgentPartyId", "SUPPLIER_AGENT");
+        SALES_ROLE_MAP.put("placingCustomerPartyId", "PLACING_CUSTOMER");
+        SALES_ROLE_MAP.put("billToCustomerPartyId", "BILL_TO_CUSTOMER");
+        SALES_ROLE_MAP.put("billFromVendorPartyId", "BILL_FROM_VENDOR");
+        SALES_ROLE_MAP.put("shipToCustomerPartyId", "SHIP_TO_CUSTOMER");
+        SALES_ROLE_MAP.put("endUserCustomerPartyId", "END_USER_CUSTOMER");
+
+        PURCHASE_ROLE_MAP.put("billToCustomerPartyId", "BILL_TO_CUSTOMER");
+        PURCHASE_ROLE_MAP.put("billFromVendorPartyId", "BILL_FROM_VENDOR");
+        PURCHASE_ROLE_MAP.put("shipFromVendorPartyId", "SHIP_FROM_VENDOR");
+        PURCHASE_ROLE_MAP.put("supplierAgentPartyId", "SUPPLIER_AGENT");
     }
-    public static final int taxDecimals = 
UtilNumber.getBigDecimalScale("salestax.calc.decimals");
-    public static final RoundingMode taxRounding = 
UtilNumber.getRoundingMode("salestax.rounding");
-    public static final int orderDecimals = 
UtilNumber.getBigDecimalScale("order.decimals");
-    public static final RoundingMode orderRounding = 
UtilNumber.getRoundingMode("order.rounding");
-    public static final BigDecimal ZERO = 
BigDecimal.ZERO.setScale(taxDecimals, taxRounding);
-
+    private static final int TAX_SCALE = 
UtilNumber.getBigDecimalScale("salestax.calc.decimals");
+    private static final RoundingMode TAX_ROUNDING = 
UtilNumber.getRoundingMode("salestax.rounding");
+    private static final int DECIMALS = 
UtilNumber.getBigDecimalScale("order.decimals");
+    private static final RoundingMode ROUNDING = 
UtilNumber.getRoundingMode("order.rounding");
+    private static final BigDecimal ZERO = BigDecimal.ZERO.setScale(TAX_SCALE, 
TAX_ROUNDING);
 
     private static boolean hasPermission(String orderId, GenericValue 
userLogin, String action, Security security, Delegator delegator) {
         OrderReadHelper orh = new OrderReadHelper(delegator, orderId);
@@ -931,9 +930,9 @@ public class OrderServices {
         }
 
         // see the attributeRoleMap definition near the top of this file for 
attribute-role mappings
-        Map<String, String> attributeRoleMap = salesAttributeRoleMap;
+        Map<String, String> attributeRoleMap = SALES_ROLE_MAP;
         if ("PURCHASE_ORDER".equals(orderTypeId)) {
-            attributeRoleMap = purchaseAttributeRoleMap;
+            attributeRoleMap = PURCHASE_ROLE_MAP;
         }
         for (Map.Entry<String, String> attributeRoleEntry : 
attributeRoleMap.entrySet()) {
             if 
(UtilValidate.isNotEmpty(context.get(attributeRoleEntry.getKey()))) {
@@ -1592,7 +1591,7 @@ public class OrderServices {
         BigDecimal totalExistingOrderTax = ZERO;
         for (GenericValue orderTaxAdjustment : orderTaxAdjustments) {
             if (orderTaxAdjustment.get("amount") != null) {
-                totalExistingOrderTax = 
totalExistingOrderTax.add(orderTaxAdjustment.getBigDecimal("amount").setScale(taxDecimals,
 taxRounding));
+                totalExistingOrderTax = 
totalExistingOrderTax.add(orderTaxAdjustment.getBigDecimal("amount").setScale(TAX_SCALE,
 TAX_ROUNDING));
             }
         }
 
@@ -1600,7 +1599,7 @@ public class OrderServices {
         BigDecimal totalManuallyAddedOrderTax = ZERO;
         for (GenericValue orderTaxAdjustment : orderTaxAdjustments) {
             if (orderTaxAdjustment.get("amount") != null && 
"Y".equals(orderTaxAdjustment.getString("isManual"))) {
-                totalManuallyAddedOrderTax = 
totalManuallyAddedOrderTax.add(orderTaxAdjustment.getBigDecimal("amount").setScale(taxDecimals,
 taxRounding));
+                totalManuallyAddedOrderTax = 
totalManuallyAddedOrderTax.add(orderTaxAdjustment.getBigDecimal("amount").setScale(TAX_SCALE,
 TAX_ROUNDING));
             }
         }
 
@@ -1715,7 +1714,7 @@ public class OrderServices {
                     if (UtilValidate.isNotEmpty(orderAdj)) {
                         for (GenericValue oa : orderAdj) {
                             if (oa.get("amount") != null) {
-                                totalNewOrderTax = 
totalNewOrderTax.add(oa.getBigDecimal("amount").setScale(taxDecimals, 
taxRounding));
+                                totalNewOrderTax = 
totalNewOrderTax.add(oa.getBigDecimal("amount").setScale(TAX_SCALE, 
TAX_ROUNDING));
                             }
                         }
                     }
@@ -1726,7 +1725,7 @@ public class OrderServices {
                             List<GenericValue> itemAdjustments = 
itemAdj.get(i);
                             for (GenericValue ia : itemAdjustments) {
                                 if (ia.get("amount") != null) {
-                                    totalNewOrderTax = 
totalNewOrderTax.add(ia.getBigDecimal("amount").setScale(taxDecimals, 
taxRounding));
+                                    totalNewOrderTax = 
totalNewOrderTax.add(ia.getBigDecimal("amount").setScale(TAX_SCALE, 
TAX_ROUNDING));
                                 }
                             }
                         }
@@ -1736,11 +1735,11 @@ public class OrderServices {
 
             // If there is any manually added tax then add it into new system 
generated tax.
             if (totalManuallyAddedOrderTax.compareTo(BigDecimal.ZERO) > 0) {
-                totalNewOrderTax = 
totalNewOrderTax.add(totalManuallyAddedOrderTax).setScale(taxDecimals, 
taxRounding);
+                totalNewOrderTax = 
totalNewOrderTax.add(totalManuallyAddedOrderTax).setScale(TAX_SCALE, 
TAX_ROUNDING);
             }
 
             // Determine the difference between existing and new tax 
adjustment totals, if any
-            BigDecimal orderTaxDifference = 
totalNewOrderTax.subtract(totalExistingOrderTax).setScale(taxDecimals, 
taxRounding);
+            BigDecimal orderTaxDifference = 
totalNewOrderTax.subtract(totalExistingOrderTax).setScale(TAX_SCALE, 
TAX_ROUNDING);
 
             // If the total has changed, create an OrderAdjustment to reflect 
the fact
             if (orderTaxDifference.signum() != 0) {
@@ -1823,7 +1822,7 @@ public class OrderServices {
                     Debug.logInfo("No valid order items found - " + 
shippingTotal, MODULE);
                 } else {
                     shippingTotal = 
UtilValidate.isEmpty(shippingEstMap.get("shippingTotal")) ? ZERO : 
(BigDecimal)shippingEstMap.get("shippingTotal");
-                    shippingTotal = shippingTotal.setScale(orderDecimals, 
orderRounding);
+                    shippingTotal = shippingTotal.setScale(DECIMALS, ROUNDING);
                     Debug.logInfo("Got new shipping estimate - " + 
shippingTotal, MODULE);
                 }
                 if (Debug.infoOn()) {
@@ -2179,7 +2178,7 @@ public class OrderServices {
 
                     // log an order note
                     try {
-                        BigDecimal quantity = thisCancelQty.setScale(1, 
orderRounding);
+                        BigDecimal quantity = thisCancelQty.setScale(1, 
ROUNDING);
                         String cancelledItemToOrder = 
UtilProperties.getMessage(RESOURCE, "OrderCancelledItemToOrder", locale);
                         resp = dispatcher.runSync("createOrderNote", 
UtilMisc.<String, Object>toMap("orderId", orderId, "note", cancelledItemToOrder 
+
                                 orderItem.getString("productId") + " (" + 
quantity + ")", "internalNote", "Y", "userLogin", userLogin));
@@ -5478,7 +5477,7 @@ public class OrderServices {
                 List<GenericValue> orderItemBillings = 
EntityQuery.use(delegator).from("OrderItemBilling").where("orderId", orderId, 
"orderItemSeqId", orderItem.get("orderItemSeqId")).queryList();
                 for (GenericValue orderItemBilling : orderItemBillings) {
                     BigDecimal quantity = 
orderItemBilling.getBigDecimal("quantity");
-                    BigDecimal amount = 
orderItemBilling.getBigDecimal("amount").setScale(orderDecimals, orderRounding);
+                    BigDecimal amount = 
orderItemBilling.getBigDecimal("amount").setScale(DECIMALS, ROUNDING);
                     if (UtilValidate.isEmpty(invoicedQuantity) || 
UtilValidate.isEmpty(amount)) {
                         continue;
                     }
@@ -5501,7 +5500,7 @@ public class OrderServices {
                     // Look at the orderAdjustmentBillings to discove the 
amount ever invoiced for this order adjustment
                     List<GenericValue> orderAdjustmentBillings = 
EntityQuery.use(delegator).from("OrderAdjustmentBilling").where("orderAdjustmentId",
 orderAdjustment.get("orderAdjustmentId")).queryList();
                     for (GenericValue orderAjustmentBilling : 
orderAdjustmentBillings) {
-                        BigDecimal amount = 
orderAjustmentBilling.getBigDecimal("amount").setScale(orderDecimals, 
orderRounding);
+                        BigDecimal amount = 
orderAjustmentBilling.getBigDecimal("amount").setScale(DECIMALS, ROUNDING);
                         if (UtilValidate.isEmpty(amount)) {
                             continue;
                         }
@@ -5532,7 +5531,7 @@ public class OrderServices {
             for (GenericValue orderHeaderAdjustment : orderHeaderAdjustments) {
                 List<GenericValue> orderHeaderAdjustmentBillings = 
EntityQuery.use(delegator).from("OrderAdjustmentBilling").where("orderAdjustmentId",
 orderHeaderAdjustment.get("orderAdjustmentId")).queryList();
                 for (GenericValue orderHeaderAdjustmentBilling : 
orderHeaderAdjustmentBillings) {
-                    BigDecimal amount = 
orderHeaderAdjustmentBilling.getBigDecimal("amount").setScale(orderDecimals, 
orderRounding);
+                    BigDecimal amount = 
orderHeaderAdjustmentBilling.getBigDecimal("amount").setScale(DECIMALS, 
ROUNDING);
                     if (UtilValidate.isEmpty(amount)) {
                         continue;
                     }
@@ -5545,7 +5544,7 @@ public class OrderServices {
             //  figures don't take tax- and shipping- adjustments into 
account, so as to be in accordance with the code in InvoiceServices
             BigDecimal invoicedAmountProportion = ZERO;
             if (orderItemsSubtotal.signum() != 0) {
-                invoicedAmountProportion = 
invoicedTotal.divide(orderItemsSubtotal, 5, orderRounding);
+                invoicedAmountProportion = 
invoicedTotal.divide(orderItemsSubtotal, 5, ROUNDING);
             }
             BigDecimal orderItemHeaderAjustmentAmount = 
orderHeaderAdjustmentsTotalValue.multiply(invoicedAmountProportion);
             orderItemTotalValue = 
invoicedTotal.add(orderItemHeaderAjustmentAmount);
@@ -5559,8 +5558,8 @@ public class OrderServices {
         }
 
         Map<String, Object> result = ServiceUtil.returnSuccess();
-        result.put("invoicedAmount", 
orderItemTotalValue.setScale(orderDecimals, orderRounding));
-        result.put("invoicedQuantity", 
invoicedQuantity.setScale(orderDecimals, orderRounding));
+        result.put("invoicedAmount", orderItemTotalValue.setScale(DECIMALS, 
ROUNDING));
+        result.put("invoicedQuantity", invoicedQuantity.setScale(DECIMALS, 
ROUNDING));
         return result;
     }
 
diff --git 
a/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/CheckOutHelper.java
 
b/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/CheckOutHelper.java
index f6b0e5c..7ad51fb 100644
--- 
a/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/CheckOutHelper.java
+++ 
b/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/CheckOutHelper.java
@@ -74,8 +74,8 @@ public class CheckOutHelper {
     private static final String MODULE = CheckOutHelper.class.getName();
     private static final String RES_ERROR = "OrderErrorUiLabels";
 
-    public static final int scale = 
UtilNumber.getBigDecimalScale("order.decimals");
-    public static final RoundingMode rounding = 
UtilNumber.getRoundingMode("order.rounding");
+    private static final int DECIMALS = 
UtilNumber.getBigDecimalScale("order.decimals");
+    private static final RoundingMode ROUNDING = 
UtilNumber.getRoundingMode("order.rounding");
 
     protected LocalDispatcher dispatcher = null;
     protected Delegator delegator = null;
@@ -1631,8 +1631,8 @@ public class CheckOutHelper {
         BigDecimal reqAmtPreParse = 
cart.getGrandTotal().subtract(cart.getBillingAccountAmount());
         BigDecimal selectedPmnt = cart.getPaymentTotal();
 
-        BigDecimal selectedPaymentTotal = selectedPmnt.setScale(scale, 
rounding);
-        BigDecimal requiredAmount = reqAmtPreParse.setScale(scale, rounding);
+        BigDecimal selectedPaymentTotal = selectedPmnt.setScale(DECIMALS, 
ROUNDING);
+        BigDecimal requiredAmount = reqAmtPreParse.setScale(DECIMALS, 
ROUNDING);
 
         if (UtilValidate.isNotEmpty(paymentMethods) && 
requiredAmount.compareTo(selectedPaymentTotal) > 0) {
             Debug.logError("Required Amount : " + requiredAmount + " / 
Selected Amount : " + selectedPaymentTotal, MODULE);
diff --git 
a/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCart.java
 
b/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCart.java
index 5131be5..366f171 100644
--- 
a/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCart.java
+++ 
b/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCart.java
@@ -94,13 +94,12 @@ public class ShoppingCart implements 
Iterable<ShoppingCartItem>, Serializable {
     public static final int FILLED_ONLY = 3;
 
     // scales and rounding modes for BigDecimal math
-    public static final int scale = 
UtilNumber.getBigDecimalScale("order.decimals");
-    public static final RoundingMode rounding = 
UtilNumber.getRoundingMode("order.rounding");
-    public static final int taxCalcScale = 
UtilNumber.getBigDecimalScale("salestax.calc.decimals");
-    public static final int taxFinalScale = 
UtilNumber.getBigDecimalScale("salestax.final.decimals");
-    public static final RoundingMode taxRounding = 
UtilNumber.getRoundingMode("salestax.rounding");
-    public static final MathContext generalRounding = new MathContext(10);
-
+    private static final int DECIMALS = 
UtilNumber.getBigDecimalScale("order.decimals");
+    private static final RoundingMode ROUNDING = 
UtilNumber.getRoundingMode("order.rounding");
+    private static final int TAX_SCALE = 
UtilNumber.getBigDecimalScale("salestax.calc.decimals");
+    private static final int TAX_FINAL_SCALE = 
UtilNumber.getBigDecimalScale("salestax.final.decimals");
+    private static final RoundingMode TAX_ROUNDING = 
UtilNumber.getRoundingMode("salestax.rounding");
+    private static final MathContext GEN_ROUNDING = new MathContext(10);
 
     private String orderType = "SALES_ORDER"; // default orderType
     private String channel = "UNKNWN_SALES_CHANNEL"; // default channel enum
@@ -1400,7 +1399,7 @@ public class ShoppingCart implements 
Iterable<ShoppingCartItem>, Serializable {
             }
             BigDecimal diffMillis = new BigDecimal(nowTimestamp.getTime() - 
createdDate.getTime());
             // millis per day: 1000.0 * 60.0 * 60.0 * 24.0 = 86400000.0
-            return (diffMillis).divide(new BigDecimal("86400000"), 
generalRounding);
+            return (diffMillis).divide(new BigDecimal("86400000"), 
GEN_ROUNDING);
         } catch (GenericEntityException e) {
             Debug.logError(e, "Error looking up party when getting 
createdDate", MODULE);
             return null;
@@ -2715,9 +2714,9 @@ public class ShoppingCart implements 
Iterable<ShoppingCartItem>, Serializable {
         BigDecimal totalTax = BigDecimal.ZERO;
         for (int i = 0; i < shipInfo.size(); i++) {
             CartShipInfo csi = this.getShipInfo(i);
-            totalTax = 
totalTax.add(csi.getTotalTax(this)).setScale(taxCalcScale, taxRounding);
+            totalTax = totalTax.add(csi.getTotalTax(this)).setScale(TAX_SCALE, 
TAX_ROUNDING);
         }
-        return totalTax.setScale(taxFinalScale, taxRounding);
+        return totalTax.setScale(TAX_FINAL_SCALE, TAX_ROUNDING);
     }
 
     /** Returns the shipping amount from the cart object. */
@@ -2778,7 +2777,7 @@ public class ShoppingCart implements 
Iterable<ShoppingCartItem>, Serializable {
     }
     public BigDecimal getDisplayTaxIncluded() {
         BigDecimal taxIncluded  = getDisplaySubTotal().subtract(getSubTotal());
-        return taxIncluded.setScale(taxFinalScale, taxRounding);
+        return taxIncluded.setScale(TAX_FINAL_SCALE, TAX_ROUNDING);
     }
 
     public BigDecimal getDisplayRecurringSubTotal() {
@@ -4559,7 +4558,7 @@ public class ShoppingCart implements 
Iterable<ShoppingCartItem>, Serializable {
             if (totalAmount.compareTo(BigDecimal.ZERO) == 0) {
                 return BigDecimal.ZERO;
             }
-            return getTotalDiscountAmount().negate().divide(totalAmount, 
scale, rounding);
+            return getTotalDiscountAmount().negate().divide(totalAmount, 
DECIMALS, ROUNDING);
         }
 
         @Override
@@ -5010,7 +5009,7 @@ public class ShoppingCart implements 
Iterable<ShoppingCartItem>, Serializable {
                     itemTax = 
itemTax.add(OrderReadHelper.calcItemAdjustment(v, quantity, 
item.getBasePrice()));
                 }
 
-                return itemTax.setScale(taxCalcScale, taxRounding);
+                return itemTax.setScale(TAX_SCALE, TAX_ROUNDING);
             }
 
             public ShoppingCartItem getItem() {
@@ -5138,8 +5137,8 @@ public class ShoppingCart implements 
Iterable<ShoppingCartItem>, Serializable {
                 }
                 if ("Y".equals(splitPayPrefPerShpGrp)  && 
cart.paymentInfo.size() == 1) {
                     for (CartShipInfo csi : cart.getShipGroups()) {
-                        maxAmount = 
csi.getTotal().add(cart.getOrderOtherAdjustmentTotal().add(cart.getOrderGlobalAdjustments()).divide(new
 BigDecimal(cart.getShipGroupSize()), 
generalRounding)).add(csi.getShipEstimate().add(csi.getTotalTax(cart)));
-                        maxAmount = maxAmount.setScale(scale, rounding);
+                        maxAmount = 
csi.getTotal().add(cart.getOrderOtherAdjustmentTotal().add(cart.getOrderGlobalAdjustments()).divide(new
 BigDecimal(cart.getShipGroupSize()), 
GEN_ROUNDING)).add(csi.getShipEstimate().add(csi.getTotalTax(cart)));
+                        maxAmount = maxAmount.setScale(DECIMALS, ROUNDING);
 
                         // create the OrderPaymentPreference record
                         GenericValue opp = 
delegator.makeValue("OrderPaymentPreference");
@@ -5179,7 +5178,7 @@ public class ShoppingCart implements 
Iterable<ShoppingCartItem>, Serializable {
                     }
                 } else if ("N".equals(splitPayPrefPerShpGrp)) {
                     maxAmount = maxAmount.add(amount);
-                    maxAmount = maxAmount.setScale(scale, rounding);
+                    maxAmount = maxAmount.setScale(DECIMALS, ROUNDING);
 
                     // create the OrderPaymentPreference record
                     GenericValue opp = 
delegator.makeValue("OrderPaymentPreference");
diff --git 
a/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/product/ProductPromoWorker.java
 
b/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/product/ProductPromoWorker.java
index 7f4c26b..fac31c0 100644
--- 
a/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/product/ProductPromoWorker.java
+++ 
b/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/product/ProductPromoWorker.java
@@ -71,12 +71,11 @@ public final class ProductPromoWorker {
     private static final String RESOURCE = "OrderUiLabels";
     private static final String RES_ERROR = "OrderErrorUiLabels";
 
-    private static final int decimals = 
UtilNumber.getBigDecimalScale("order.decimals");
-    private static final RoundingMode rounding = 
UtilNumber.getRoundingMode("order.rounding");
+    private static final int DECIMALS = 
UtilNumber.getBigDecimalScale("order.decimals");
+    private static final RoundingMode ROUNDING = 
UtilNumber.getRoundingMode("order.rounding");
+    private static final MathContext GEN_ROUNDING = new MathContext(10);
 
-    private static final MathContext generalRounding = new MathContext(10);
-
-    private ProductPromoWorker() {}
+    private ProductPromoWorker() { }
 
     public static List<GenericValue> getStoreProductPromos(Delegator 
delegator, LocalDispatcher dispatcher, ServletRequest request) {
         List<GenericValue> productPromos = new LinkedList<>();
@@ -1179,7 +1178,7 @@ public final class ProductPromoWorker {
             // to minimize rounding issues use the remaining total for the 
last one, otherwise use a calculated value
             if (cartItemsUsedIter.hasNext()) {
                 BigDecimal quantityUsed = 
cartItem.getPromoQuantityCandidateUseActionAndAllConds(productPromoAction);
-                BigDecimal ratioOfTotal = 
quantityUsed.multiply(cartItem.getBasePrice()).divide(totalAmount, 
generalRounding);
+                BigDecimal ratioOfTotal = 
quantityUsed.multiply(cartItem.getBasePrice()).divide(totalAmount, 
GEN_ROUNDING);
                 BigDecimal weightedAmount = 
ratioOfTotal.multiply(discountAmountTotal);
                 // round the weightedAmount to 3 decimal places, we don't want 
an exact number cents/whatever because this will be added up as part of a 
subtotal which will be rounded to 2 decimal places
                 weightedAmount = weightedAmount.setScale(3, 
RoundingMode.HALF_UP);
@@ -1218,7 +1217,7 @@ public final class ProductPromoWorker {
     public static void doOrderItemPromoAction(GenericValue productPromoAction, 
ShoppingCartItem cartItem, BigDecimal amount, String amountField, Delegator 
delegator) {
         // round the amount before setting to make sure we don't get funny 
numbers in there
         // only round to 3 places, we need more specific amounts in 
adjustments so that they add up cleaner as part of the item subtotal, which 
will then be rounded
-        amount = amount.setScale(3, rounding);
+        amount = amount.setScale(3, ROUNDING);
         boolean addNewAdjustment = true;
         List<GenericValue> adjustments = cartItem.getAdjustments();
         if (UtilValidate.isNotEmpty(adjustments)) {
@@ -1252,7 +1251,7 @@ public final class ProductPromoWorker {
 
     public static void doOrderPromoAction(GenericValue productPromoAction, 
ShoppingCart cart, BigDecimal amount, String amountField, Delegator delegator) {
         // round the amount before setting to make sure we don't get funny 
numbers in there
-        amount = amount.setScale(decimals, rounding);
+        amount = amount.setScale(DECIMALS, ROUNDING);
         GenericValue orderAdjustment = delegator.makeValue("OrderAdjustment",
                 UtilMisc.toMap("orderAdjustmentTypeId", 
"PROMOTION_ADJUSTMENT", amountField, amount,
                         "productPromoId", 
productPromoAction.get("productPromoId"),

Reply via email to