Author: jacopoc
Date: Fri Mar 19 10:21:41 2010 New Revision: 925162 URL: http://svn.apache.org/viewvc?rev=925162&view=rev Log: Fixed a series of errors thrown by the depreciation algorithms on certain data (null pointer exceptions, divide by zero operations). This also fixes a bug reported in the users list by Jhanneth Andrade Sajami. Modified: ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/fixedasset/FixedAssetServices.xml ofbiz/trunk/applications/accounting/widget/FixedAssetScreens.xml Modified: ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/fixedasset/FixedAssetServices.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/fixedasset/FixedAssetServices.xml?rev=925162&r1=925161&r2=925162&view=diff ============================================================================== --- ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/fixedasset/FixedAssetServices.xml (original) +++ ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/fixedasset/FixedAssetServices.xml Fri Mar 19 10:21:41 2010 @@ -573,18 +573,23 @@ under the License. <then> <set field="depreciation" value="0.0" type="BigDecimal"/> <!--FORMULA : depreciation = (purchaseCost - salvageValue) / (expectedEndOfLife - dateAcquired) --> - <calculate field="depreciation" decimal-scale="2"> - <calcop operator="divide"> - <calcop operator="subtract"> - <calcop operator="get" field="purchaseCost"/> - <calcop operator="get" field="salvageValue"/> - </calcop> - <calcop operator="subtract"> - <calcop operator="get" field="expEndOfLifeYear"/> - <calcop operator="get" field="assetAcquiredYear"/> - </calcop> + <calculate field="numberOfYears"> + <calcop operator="subtract"> + <calcop operator="get" field="expEndOfLifeYear"/> + <calcop operator="get" field="assetAcquiredYear"/> </calcop> </calculate> + <if-compare field="numberOfYears" operator="greater" value="0.0" type="BigDecimal"> + <calculate field="depreciation" decimal-scale="2"> + <calcop operator="divide"> + <calcop operator="subtract"> + <calcop operator="get" field="purchaseCost"/> + <calcop operator="get" field="salvageValue"/> + </calcop> + <calcop operator="get" field="numberOfYears"/> + </calcop> + </calculate> + </if-compare> <set field="depreciationYear" from-field="assetAcquiredYear" type="BigDecimal"/> <loop count="${intUsageYears}"> <calculate field="purchaseCost"> @@ -640,21 +645,25 @@ under the License. <then> <entity-one entity-name="FixedAsset" value-field="fixedAsset"/> <!--FORMULA : depreciation = (purchaseCost - salvageValue - pastDepreciations) / remainingYears --> - <calculate field="nextDepreciationAmount" decimal-scale="2"> - <calcop operator="divide"> - <calcop operator="subtract"> - <calcop operator="get" field="fixedAsset.purchaseCost"/> - <calcop operator="get" field="salvageValue"/> - <calcop operator="get" field="fixedAsset.depreciation"/> - </calcop> - <!-- Remaining years --> - <calcop operator="subtract"> - <calcop operator="get" field="expEndOfLifeYear"/> - <calcop operator="get" field="assetAcquiredYear"/> - <calcop operator="get" field="intUsageYears"/> - </calcop> + <calculate field="remainingYears"> + <calcop operator="subtract"> + <calcop operator="get" field="expEndOfLifeYear"/> + <calcop operator="get" field="assetAcquiredYear"/> + <calcop operator="get" field="intUsageYears"/> </calcop> </calculate> + <if-compare field="remainingYears" operator="greater" value="0.0" type="BigDecimal"> + <calculate field="nextDepreciationAmount" decimal-scale="2"> + <calcop operator="divide"> + <calcop operator="subtract"> + <calcop operator="get" field="fixedAsset.purchaseCost"/> + <calcop operator="get" field="salvageValue"/> + <calcop operator="get" field="fixedAsset.depreciation"/> + </calcop> + <calcop operator="get" field="remainingYears"/> + </calcop> + </calculate> + </if-compare> </then> </if> <field-to-result field="nextDepreciationAmount"/> @@ -676,24 +685,28 @@ under the License. <then> <entity-one entity-name="FixedAsset" value-field="fixedAsset"/> <!--FORMULA : depreciation = 2 * (purchaseCost - salvageValue - pastDepreciations) / remainingYears --> - <calculate field="nextDepreciationAmount" decimal-scale="2"> - <calcop operator="multiply"> - <calcop operator="divide"> - <calcop operator="subtract"> - <calcop operator="get" field="fixedAsset.purchaseCost"/> - <calcop operator="get" field="salvageValue"/> - <calcop operator="get" field="fixedAsset.depreciation"/> - </calcop> - <!-- Remaining years --> - <calcop operator="subtract"> - <calcop operator="get" field="expEndOfLifeYear"/> - <calcop operator="get" field="assetAcquiredYear"/> - <calcop operator="get" field="intUsageYears"/> - </calcop> - </calcop> - <number value="2"/> + <calculate field="remainingYears"> + <calcop operator="subtract"> + <calcop operator="get" field="expEndOfLifeYear"/> + <calcop operator="get" field="assetAcquiredYear"/> + <calcop operator="get" field="intUsageYears"/> </calcop> </calculate> + <if-compare field="remainingYears" operator="greater" value="0.0" type="BigDecimal"> + <calculate field="nextDepreciationAmount" decimal-scale="2"> + <calcop operator="multiply"> + <calcop operator="divide"> + <calcop operator="subtract"> + <calcop operator="get" field="fixedAsset.purchaseCost"/> + <calcop operator="get" field="salvageValue"/> + <calcop operator="get" field="fixedAsset.depreciation"/> + </calcop> + <calcop operator="get" field="remainingYears"/> + </calcop> + <number value="2"/> + </calcop> + </calculate> + </if-compare> </then> </if> <field-to-result field="nextDepreciationAmount"/> @@ -712,21 +725,26 @@ under the License. <loop count="${intUsageYears}"> <set field="depreciation" value="0.0" type="BigDecimal"/> <!--FORMULA : depreciation = (NBV - salvageValue) * 2 / (expectedEndOfLife - dateAcquired) --> - <calculate field="depreciation" decimal-scale="2"> - <calcop operator="multiply"> - <calcop operator="divide"> - <calcop operator="subtract"> - <calcop operator="get" field="purchaseCost"/> - <calcop operator="get" field="salvageValue"/> - </calcop> - <calcop operator="subtract"> - <calcop operator="get" field="expEndOfLifeYear"/> - <calcop operator="get" field="assetAcquiredYear"/> - </calcop> - </calcop> - <number value="2"/> + <calculate field="numberOfYears"> + <calcop operator="subtract"> + <calcop operator="get" field="expEndOfLifeYear"/> + <calcop operator="get" field="assetAcquiredYear"/> </calcop> </calculate> + <if-compare field="numberOfYears" operator="greater" value="0.0" type="BigDecimal"> + <calculate field="depreciation" decimal-scale="2"> + <calcop operator="multiply"> + <calcop operator="divide"> + <calcop operator="subtract"> + <calcop operator="get" field="purchaseCost"/> + <calcop operator="get" field="salvageValue"/> + </calcop> + <calcop operator="get" field="numberOfYears"/> + </calcop> + <number value="2"/> + </calcop> + </calculate> + </if-compare> <calculate field="assetAcquiredYear"> <calcop operator="add"> <calcop operator="get" field="assetAcquiredYear"/> Modified: ofbiz/trunk/applications/accounting/widget/FixedAssetScreens.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/widget/FixedAssetScreens.xml?rev=925162&r1=925161&r2=925162&view=diff ============================================================================== --- ofbiz/trunk/applications/accounting/widget/FixedAssetScreens.xml (original) +++ ofbiz/trunk/applications/accounting/widget/FixedAssetScreens.xml Fri Mar 19 10:21:41 2010 @@ -538,8 +538,9 @@ under the License. <section> <condition> <and> - <if-compare-field field="assetDepreciationResultMap.plannedPastDepreciationTotal" to-field="depreciation" operator="greater"/> + <not><if-empty field="assetDepreciationResultMap.plannedPastDepreciationTotal"/></not> <not><if-empty field="fixedAsset.partyId"/></not> + <if-compare-field field="assetDepreciationResultMap.plannedPastDepreciationTotal" to-field="depreciation" operator="greater" type="BigDecimal"/> </and> </condition> <actions> |
Free forum by Nabble | Edit this page |