Skip to content

Commit

Permalink
Improved: Changed decimals, rounding, zero static variables names as …
Browse files Browse the repository at this point in the history
…per best practices in manufacturing component. (#200)

(OFBIZ-11804)
Also make them private data members of the class.
  • Loading branch information
surajkhurana committed Jun 12, 2020
1 parent 33deb94 commit 575defd
Showing 1 changed file with 9 additions and 9 deletions.
Expand Up @@ -70,9 +70,9 @@ public class ProductionRunServices {
private static final String RES_ORDER = "OrderErrorUiLabels";
private static final String RES_PRODUCT = "ProductUiLabels";

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

/**
* Cancels a ProductionRun.
Expand Down Expand Up @@ -1209,7 +1209,7 @@ public static Map<String, Object> createProductionRunTaskCosts(DispatchContext c
if (variableCost == null) {
variableCost = BigDecimal.ZERO;
}
BigDecimal totalCost = fixedCost.add(variableCost.multiply(BigDecimal.valueOf(totalTime))).setScale(decimals, rounding);
BigDecimal totalCost = fixedCost.add(variableCost.multiply(BigDecimal.valueOf(totalTime))).setScale(DECIMALS, ROUNDING);
// store the cost
Map<String, Object> inMap = UtilMisc.<String, Object>toMap("userLogin", userLogin, "workEffortId", productionRunTaskId);
inMap.put("costComponentTypeId", "ACTUAL_" + workEffortCostCalc.getString("costComponentTypeId"));
Expand Down Expand Up @@ -1253,8 +1253,8 @@ public static Map<String, Object> createProductionRunTaskCosts(DispatchContext c
if (usageCost != null) {
usageCostAmount = usageCost.getBigDecimal("amount").multiply(BigDecimal.valueOf(actualMilliSeconds));
}
BigDecimal fixedAssetCost = setupCostAmount.add(usageCostAmount).setScale(decimals, rounding);
fixedAssetCost = fixedAssetCost.divide(BigDecimal.valueOf(3600000), decimals, rounding);
BigDecimal fixedAssetCost = setupCostAmount.add(usageCostAmount).setScale(DECIMALS, ROUNDING);
fixedAssetCost = fixedAssetCost.divide(BigDecimal.valueOf(3600000), DECIMALS, ROUNDING);
// store the cost
Map<String, Object> inMap = UtilMisc.<String, Object>toMap("userLogin", userLogin,
"workEffortId", productionRunTaskId);
Expand Down Expand Up @@ -1288,7 +1288,7 @@ public static Map<String, Object> createProductionRunTaskCosts(DispatchContext c
materialsCostByCurrency.put(currencyUomId, BigDecimal.ZERO);
}
BigDecimal materialsCost = materialsCostByCurrency.get(currencyUomId);
materialsCost = materialsCost.add(unitCost.multiply(quantity)).setScale(decimals, rounding);
materialsCost = materialsCost.add(unitCost.multiply(quantity)).setScale(DECIMALS, ROUNDING);
materialsCostByCurrency.put(currencyUomId, materialsCost);
}
for (String currencyUomId : materialsCostByCurrency.keySet()) {
Expand Down Expand Up @@ -2379,7 +2379,7 @@ public static Map<String, Object> updateProductionRunTask(DispatchContext ctx, M
try {
List<GenericValue> components = theTask.getRelated("WorkEffortGoodStandard", null, null, false);
for (GenericValue component : components) {
BigDecimal totalRequiredMaterialQuantity = component.getBigDecimal("estimatedQuantity").multiply(totalQuantityProduced).divide(quantityToProduce, rounding);
BigDecimal totalRequiredMaterialQuantity = component.getBigDecimal("estimatedQuantity").multiply(totalQuantityProduced).divide(quantityToProduce, ROUNDING);
// now get the units that have been already issued and subtract them
List<GenericValue> issuances = EntityQuery.use(delegator).from("WorkEffortAndInventoryAssign")
.where("workEffortId", workEffortId,
Expand Down Expand Up @@ -3426,7 +3426,7 @@ public static Map<String, Object> decomposeInventoryItem(DispatchContext ctx, Ma
// will be equal to the components' standard costs
costCoefficient = BigDecimal.ONE;
} else {
costCoefficient = inventoryItemCost.divide(packageCost, 10, rounding);
costCoefficient = inventoryItemCost.divide(packageCost, 10, ROUNDING);
}

// the components are retrieved
Expand Down

0 comments on commit 575defd

Please sign in to comment.