Fixes Issue 32337:Division by zero error when completing an invoice
authorAtul Gaware <atul.gaware@openbravo.com>
Mon, 29 Feb 2016 18:07:19 +0530
changeset 28691 e86261103636
parent 28690 88faf8e87290
child 28692 b2626fca4c8f
Fixes Issue 32337:Division by zero error when completing an invoice
associated to a closed order (quantity 0) with a promotion

While calculating promotion if qty ordered is non zero then only
use divide by statement else set values to zero
src-db/database/model/functions/M_PROMOTION_CALCULATE.xml
--- a/src-db/database/model/functions/M_PROMOTION_CALCULATE.xml	Tue Mar 01 18:02:57 2016 +0100
+++ b/src-db/database/model/functions/M_PROMOTION_CALCULATE.xml	Mon Feb 29 18:07:19 2016 +0530
@@ -22,7 +22,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) 2012-2015 Openbravo SLU
+* All portions are Copyright (C) 2012-2016 Openbravo SLU
 * All Rights Reserved.
 * Contributor(s):  ______________________________________.
 ************************************************************************/
@@ -180,8 +180,13 @@
           v_totalamt := Cur_Offer.totalamt;
           v_displayedtotalamt := Cur_Offer.displayedtotalamt;
         else
-          v_totalamt := round(Cur_Offer.totalamt * v_qtyinvoiced / v_qtyordered, v_precision);
-          v_displayedtotalamt := round(Cur_Offer.displayedtotalamt * v_qtyinvoiced / v_qtyordered, v_precision);
+          IF(v_qtyordered <> 0) THEN
+            v_totalamt := round(Cur_Offer.totalamt * v_qtyinvoiced / v_qtyordered, v_precision);
+            v_displayedtotalamt := round(Cur_Offer.displayedtotalamt * v_qtyinvoiced / v_qtyordered, v_precision);
+          ELSE
+            v_totalamt := 0;
+            v_displayedtotalamt := 0;
+          END IF;
         end if;
         
         insert into c_invoiceline_offer