This is an automated email from the ASF dual-hosted git repository.
mridulpathak pushed a commit to branch release24.09
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
The following commit(s) were added to refs/heads/release24.09 by this push:
new af635eadeb Fixed: Three regressions in the minilang-to-Groovy
conversion of CostServices.groovy (OFBIZ-13617)
af635eadeb is described below
commit af635eadebf24c3ddbd465ace5ca26d8b15fe5bf
Author: Mridul Pathak <[email protected]>
AuthorDate: Sun Sep 27 13:31:32 2026 +0530
Fixed: Three regressions in the minilang-to-Groovy conversion of
CostServices.groovy (OFBIZ-13617)
- calculateProductCosts() referenced the undeclared totalCostByType instead
of totalCostsByType, silently dropping prior task-cost accumulation for
repeated cost types.
- calculateProductAverageCost() rounded totals once at the end instead of
after every iteration (HALF_EVEN, 2 decimals) as mini-lang's <calculate>
defaults to, which can shift the final average by a cent.
- updateProductAverageCostOnReceiveInventory() read the nonexistent
property finaccout.decimals instead of finaccount.decimals, silently falling
back to a hardcoded default.
---
.../ofbiz/product/product/cost/CostServices.groovy | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git
a/applications/product/src/main/groovy/org/apache/ofbiz/product/product/cost/CostServices.groovy
b/applications/product/src/main/groovy/org/apache/ofbiz/product/product/cost/CostServices.groovy
index f9fa122d15..a305be00f8 100644
---
a/applications/product/src/main/groovy/org/apache/ofbiz/product/product/cost/CostServices.groovy
+++
b/applications/product/src/main/groovy/org/apache/ofbiz/product/product/cost/CostServices.groovy
@@ -304,7 +304,7 @@ Map calculateProductCosts() {
totalTaskCost = totalTaskCost.setScale(6)
costsByType.entrySet().each { Map.Entry entry ->
if (totalCostsByType."${entry.key}") {
- totalCostsByType."${entry.key}" = entry.value +
totalCostByType."${entry.key}"
+ totalCostsByType."${entry.key}" = entry.value +
totalCostsByType."${entry.key}"
} else {
totalCostsByType."${entry.key}" = entry.value
}
@@ -386,19 +386,22 @@ Map calculateProductAverageCost() {
Boolean differentCurrencies = false
String currencyUomId
for (GenericValue inventoryItem : inventoryItems) {
- totalQuantityOnHand += inventoryItem.quantityOnHandTotal
+ totalQuantityOnHand = (totalQuantityOnHand +
inventoryItem.quantityOnHandTotal).setScale(2, RoundingMode.HALF_EVEN)
currencyUomId = currencyUomId ?: inventoryItem.currencyUomId
if (!differentCurrencies) {
if (currencyUomId == inventoryItem.currencyUomId) {
- totalInventoryCost += (inventoryItem.unitCost *
inventoryItem.quantityOnHandTotal)
+ totalInventoryCost = (totalInventoryCost +
(inventoryItem.unitCost * inventoryItem.quantityOnHandTotal))
+ .setScale(2, RoundingMode.HALF_EVEN)
// calculation of absolute values of QOH and total inventory
cost
if (inventoryItem.quantityOnHandTotal < (BigDecimal) 0) {
- absValOfTotalQOH = absValOfTotalQOH -
inventoryItem.quantityOnHandTotal
- absValOfTotalInvCost = absValOfTotalInvCost + (-1 *
inventoryItem.quantityOnHandTotal * inventoryItem.unitCost)
+ absValOfTotalQOH = (absValOfTotalQOH -
inventoryItem.quantityOnHandTotal).setScale(2, RoundingMode.HALF_EVEN)
+ absValOfTotalInvCost = (absValOfTotalInvCost + (-1 *
inventoryItem.quantityOnHandTotal * inventoryItem.unitCost))
+ .setScale(2, RoundingMode.HALF_EVEN)
} else {
- absValOfTotalQOH += inventoryItem.quantityOnHandTotal
- absValOfTotalInvCost = absValOfTotalInvCost +
(inventoryItem.quantityOnHandTotal * inventoryItem.unitCost)
+ absValOfTotalQOH = (absValOfTotalQOH +
inventoryItem.quantityOnHandTotal).setScale(2, RoundingMode.HALF_EVEN)
+ absValOfTotalInvCost = (absValOfTotalInvCost +
(inventoryItem.quantityOnHandTotal * inventoryItem.unitCost))
+ .setScale(2, RoundingMode.HALF_EVEN)
}
} else {
differentCurrencies = true
@@ -456,7 +459,7 @@ Map updateProductAverageCostOnReceiveInventory() {
BigDecimal oldProductQuantity = quantityOnHandTotal -
parameters.quantityAccepted
BigDecimal averageCost = ((productAverageCost.averageCost *
oldProductQuantity)
+ (inventoryItem.unitCost * parameters.quantityAccepted)) /
(quantityOnHandTotal)
- int roundingDecimal =
UtilProperties.getPropertyAsInteger('arithmetic', 'finaccout.decimals', 2)
+ int roundingDecimal =
UtilProperties.getPropertyAsInteger('arithmetic', 'finaccount.decimals', 2)
String roundingMode = UtilProperties.getPropertyValue('arithmetic',
'finaccount.roundingGroovyMethod', 'HALF_UP')
averageCost = averageCost.setScale(roundingDecimal,
RoundingMode."${roundingMode}")
productAverageCostMap.averageCost = averageCost