Skip to content

Commit

Permalink
Improved: Enforce noninstantiability to BillingAccountWorker Class. (#…
Browse files Browse the repository at this point in the history
…167)

(OFBIZ-11721)
Made class as final, added private constructor, changed data members to private and corrected names as per naming convention.
  • Loading branch information
surajkhurana committed Jun 4, 2020
1 parent e92becb commit 9ade9d7
Showing 1 changed file with 9 additions and 7 deletions.
Expand Up @@ -50,13 +50,15 @@
/**
* Worker methods for BillingAccounts
*/
public class BillingAccountWorker {
public final class BillingAccountWorker {

private static final String MODULE = BillingAccountWorker.class.getName();
private static final String RES_ERROR = "AccountingUiLabels";
public static final int decimals = UtilNumber.getBigDecimalScale("order.decimals");
public static final RoundingMode rounding = UtilNumber.getRoundingMode("order.rounding");
public static final BigDecimal ZERO = BigDecimal.ZERO.setScale(decimals, 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(DECIMALS, ROUNDING);

protected BillingAccountWorker() { }

public static List<Map<String, Object>> makePartyBillingAccountList(GenericValue userLogin, String currencyUomId, String partyId, Delegator delegator, LocalDispatcher dispatcher) throws GeneralException {
List<Map<String, Object>> billingAccountList = new LinkedList<>();
Expand Down Expand Up @@ -123,7 +125,7 @@ public static List<GenericValue> getBillingAccountOpenOrders(Delegator delegator
public static BigDecimal getBillingAccountAvailableBalance(GenericValue billingAccount) throws GenericEntityException {
if ((billingAccount != null) && (billingAccount.get("accountLimit") != null)) {
BigDecimal accountLimit = billingAccount.getBigDecimal("accountLimit");
BigDecimal availableBalance = accountLimit.subtract(OrderReadHelper.getBillingAccountBalance(billingAccount)).setScale(decimals, rounding);
BigDecimal availableBalance = accountLimit.subtract(OrderReadHelper.getBillingAccountBalance(billingAccount)).setScale(DECIMALS, ROUNDING);
return availableBalance;
}
Debug.logWarning("Available balance requested for null billing account, returning zero", MODULE);
Expand Down Expand Up @@ -161,7 +163,7 @@ public static BigDecimal getBillingAccountNetBalance(Delegator delegator, String
}
}

balance = balance.setScale(decimals, rounding);
balance = balance.setScale(DECIMALS, ROUNDING);
return balance;
}

Expand All @@ -175,7 +177,7 @@ public static BigDecimal availableToCapture(GenericValue billingAccount) throws
BigDecimal netBalance = getBillingAccountNetBalance(billingAccount.getDelegator(), billingAccount.getString("billingAccountId"));
BigDecimal accountLimit = billingAccount.getBigDecimal("accountLimit");

return accountLimit.subtract(netBalance).setScale(decimals, rounding);
return accountLimit.subtract(netBalance).setScale(DECIMALS, ROUNDING);
}

public static Map<String, Object> calcBillingAccountBalance(DispatchContext dctx, Map<String, ? extends Object> context) {
Expand Down

0 comments on commit 9ade9d7

Please sign in to comment.