details:   https://code.openbravo.com/erp/devel/pi/rev/07cbc0d9c389
changeset: 33898:07cbc0d9c389
user:      Armaignac <collazoandy4 <at> gmail.com>
date:      Fri Apr 27 19:14:34 2018 -0400
summary:   Fixes issue 38302:Tax tab info is not correctly recalculated when 
negative child
tax defined as "cascade" is modified

When an orderlinetax is removed and the line order it's not take into account
the triggers calculations can be incorrect.

Now the orderlinetax are removed in the proper order (lineno asc) to avoid
wrong calculations in the triggers.

diffstat:

 src-db/database/model/triggers/C_ORDERLINE_TRG2.xml |  15 ++++++++++++---
 1 files changed, 12 insertions(+), 3 deletions(-)

diffs (32 lines):

diff -r ceaf52d36601 -r 07cbc0d9c389 
src-db/database/model/triggers/C_ORDERLINE_TRG2.xml
--- a/src-db/database/model/triggers/C_ORDERLINE_TRG2.xml       Wed May 02 
09:55:08 2018 +0200
+++ b/src-db/database/model/triggers/C_ORDERLINE_TRG2.xml       Fri Apr 27 
19:14:34 2018 -0400
@@ -58,7 +58,8 @@
   v_CalcLine NUMBER;
           
   TYPE RECORD IS REF CURSOR;
-  Cur_BOM RECORD;        
+  Cur_BOM RECORD; 
+  Cur_TAXLINES RECORD;      
 BEGIN
     
     IF AD_isTriggerEnabled()='N' THEN RETURN;
@@ -121,8 +122,16 @@
       v_oldLineAlternate := COALESCE(:old.TaxBaseAmt,0) + 
COALESCE(:old.FreightAmt,0) + COALESCE(:old.ChargeAmt,0);
       IF (:new.AD_Org_ID <> :old.AD_Org_ID OR :new.C_Tax_ID <> :old.C_Tax_ID OR
           v_newLineNetAmt <> v_oldLine OR v_newLineAlternate <> 
v_oldLineAlternate OR
-          :new.line_gross_amount <> :old.line_gross_amount) THEN
-        DELETE FROM C_ORDERLINETAX WHERE C_ORDERLINE_ID = :new.C_OrderLine_ID;
+          :new.line_gross_amount <> :old.line_gross_amount) THEN        
+         -- Delete the TaxLines using a Cursor to be able to delete them in 
the proper order.
+         -- If not, the calculations done in the triggers can be incorrect
+         FOR Cur_TAXLINES IN (SELECT C_ORDERLINETAX_ID
+                              FROM C_ORDERLINETAX
+                              WHERE C_ORDERLINE_ID = :new.C_OrderLine_ID
+                              ORDER BY line ASC)
+         LOOP
+           DELETE FROM C_ORDERLINETAX WHERE C_ORDERLINETAX_ID = 
Cur_TAXLINES.C_OrderLineTax_ID;
+         END LOOP;
         v_create := 'Y';
       ELSE        
         v_create := 'N';        

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to