You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by mr...@apache.org on 2026/09/27 08:23:50 UTC

(ofbiz-framework) branch trunk updated: Fixed: Three regressions in the minilang-to-Groovy conversion of CostServices.groovy (OFBIZ-13617)

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

mridulpathak 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 e76ac3bf8e Fixed: Three regressions in the minilang-to-Groovy conversion of CostServices.groovy (OFBIZ-13617)
e76ac3bf8e is described below

commit e76ac3bf8ec2cb550a59928e8223f352f9cb5d76
Author: Mridul Pathak <mr...@gmail.com>
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 c06861291a..2897f3ca9a 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