Fixes Issue 32280:Amortization Process / Unprocess should only update Fully
authorAtul Gaware <atul.gaware@openbravo.com>
Tue, 23 Feb 2016 16:05:13 +0530
changeset 28633 216fb4e6048c
parent 28632 64dcdb9cf68b
child 28634 50d727a06177
Fixes Issue 32280:Amortization Process / Unprocess should only update Fully
Depreciated field of the assets included on it and need the update

Condition added in update query to only update those assets record on which
amortization process is being called
src-db/database/model/functions/A_AMORTIZATION_PROCESS.xml
--- a/src-db/database/model/functions/A_AMORTIZATION_PROCESS.xml	Tue Feb 23 16:37:30 2016 +0100
+++ b/src-db/database/model/functions/A_AMORTIZATION_PROCESS.xml	Tue Feb 23 16:05:13 2016 +0530
@@ -16,7 +16,7 @@
 * under the License.
 * The Original Code is Openbravo ERP.
 * The Initial Developer of the Original Code is Openbravo SLU
-* All portions are Copyright (C) 2001-2015 Openbravo SLU
+* All portions are Copyright (C) 2001-2016 Openbravo SLU
 * All Rights Reserved.
 * Contributor(s):  ______________________________________.
 ************************************************************************/
@@ -149,10 +149,24 @@
           AND am.A_Amortization_ID=V_Record_ID);
       UPDATE a_asset
         SET IsFullyDepreciated='Y',Updated=now(),UpdatedBy=v_AD_User_ID
-      WHERE COALESCE(DepreciatedPlan, -1)=COALESCE(DepreciatedValue, -2) ;
+      WHERE COALESCE(DepreciatedPlan, -1)=COALESCE(DepreciatedValue, -2)
+      AND exists
+        (SELECT 1
+        FROM a_amortizationline al, a_amortization am
+        WHERE a_asset.a_asset_id=al.a_asset_id
+          AND al.A_Amortization_ID=am.A_Amortization_ID
+          AND am.A_Amortization_ID=V_Record_ID)
+      AND IsFullyDepreciated='N';
       UPDATE a_asset
         SET IsFullyDepreciated='N',Updated=now(),UpdatedBy=v_AD_User_ID
-      WHERE DepreciatedPlan<>DepreciatedValue;
+      WHERE DepreciatedPlan<>DepreciatedValue
+      AND exists
+        (SELECT 1
+        FROM a_amortizationline al, a_amortization am
+        WHERE a_asset.a_asset_id=al.a_asset_id
+          AND al.A_Amortization_ID=am.A_Amortization_ID
+          AND am.A_Amortization_ID=V_Record_ID)
+      AND IsFullyDepreciated='Y';
     END IF;
     --<<FINISH_PROCESS>>
     IF(p_PInstance_ID IS NOT NULL) THEN