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/10 03:39:32 UTC

(ofbiz-framework) branch trunk updated: Fixed: straightLineDepreciation uses wrong field for elapsed years (OFBIZ-13524)

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 a4f7483ebd Fixed: straightLineDepreciation uses wrong field for elapsed years (OFBIZ-13524)
a4f7483ebd is described below

commit a4f7483ebd5de3ceffc1f62d0d399229c0873230
Author: Mridul Pathak <mr...@gmail.com>
AuthorDate: Wed Sep 9 18:43:27 2026 +0530

    Fixed: straightLineDepreciation uses wrong field for elapsed years (OFBIZ-13524)
    
    - Compute intUsageYears locally from parameters.usageYears.intValue() and cap it at numberOfYears, replacing reads of nonexistent parameters.intUsageYears that previously broke the usage-years cap logic and caused remainingYears to ignore elapsed asset life.
    - Fix nextDepreciationAmount calculation to subtract salvageValue instead of usageYears.
    - Assign the result of setScale(2, RoundingMode.HALF_EVEN) back to depreciation and nextDepreciationAmount, ensuring calculated amounts are properly rounded to two decimal places.
---
 .../accounting/fixedasset/FixedAssetServices.groovy   | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/applications/accounting/src/main/groovy/org/apache/ofbiz/accounting/fixedasset/FixedAssetServices.groovy b/applications/accounting/src/main/groovy/org/apache/ofbiz/accounting/fixedasset/FixedAssetServices.groovy
index 1428b299ad..a463a01b70 100644
--- a/applications/accounting/src/main/groovy/org/apache/ofbiz/accounting/fixedasset/FixedAssetServices.groovy
+++ b/applications/accounting/src/main/groovy/org/apache/ofbiz/accounting/fixedasset/FixedAssetServices.groovy
@@ -260,19 +260,23 @@ Map straightLineDepreciation() {
     BigDecimal purchaseCost = parameters.purchaseCost
     BigDecimal expEndOfLifeYear = parameters.expEndOfLifeYear ?: 0
     BigDecimal assetAcquiredYear = parameters.assetAcquiredYear ?: 0
+    BigDecimal salvageValue = parameters.salvageValue ?: 0
 
     GenericValue fixedAsset = from('FixedAsset').where(parameters).queryOne()
     if (!fixedAsset) {
         return error(label('AccountingErrorUiLabels', 'AccountingFixedAssetNotFound'))
     }
     BigDecimal depreciation = fixedAsset.depreciation ?: 0
-    if (parameters.usageYears > 0) {
+    int intUsageYears = parameters.usageYears ? parameters.usageYears.intValue() : 0
+    if (intUsageYears > 0) {
         //FORMULA :  depreciation = (purchaseCost - salvageValue) / (expectedEndOfLife - dateAcquired)
         int numberOfYears = parameters.expEndOfLifeYear - parameters.assetAcquiredYear
         if (numberOfYears > 0) {
-            depreciation = (purchaseCost - parameters.salvageValue) / numberOfYears
-            depreciation.setScale(2, RoundingMode.HALF_EVEN)
-            int intUsageYears =  (numberOfYears < parameters.intUsageYears) ? parameters.intUsageYears : numberOfYears
+            depreciation = (purchaseCost - salvageValue) / numberOfYears
+            depreciation = depreciation.setScale(2, RoundingMode.HALF_EVEN)
+            if (numberOfYears < intUsageYears) {
+                intUsageYears = numberOfYears
+            }
             for (int i = 0; i < intUsageYears; i++) {
                 purchaseCost -= depreciation
                 depreciationTotal += depreciation
@@ -300,11 +304,10 @@ Map straightLineDepreciation() {
     BigDecimal nextDepreciationAmount = 0
 
     // FORMULA : depreciation = (purchaseCost - salvageValue - pastDepreciations) / remainingYears
-    int usageYears = parameters.intUsageYears ?: 0
-    BigDecimal remainingYears  = expEndOfLifeYear - assetAcquiredYear - usageYears
+    BigDecimal remainingYears = expEndOfLifeYear - assetAcquiredYear - intUsageYears
     if (remainingYears > 0) {
-        nextDepreciationAmount = ((fixedAsset.purchaseCost ?: 0) - usageYears - (fixedAsset.depreciation ?: 0)) / remainingYears
-        nextDepreciationAmount.setScale(2, RoundingMode.HALF_EVEN)
+        nextDepreciationAmount = ((fixedAsset.purchaseCost ?: 0) - salvageValue - (fixedAsset.depreciation ?: 0)) / remainingYears
+        nextDepreciationAmount = nextDepreciationAmount.setScale(2, RoundingMode.HALF_EVEN)
     }
     return success([assetDepreciationTillDate: assetDepreciationTillDate,
         assetNBVAfterDepreciation: assetNBVAfterDepreciation,