Fixes issue 22883: Partial goods shipments
authorJavier Etxarri <javier.echarri@openbravo.com>
Fri, 01 Feb 2013 11:51:34 +0100
changeset 19543 ba202e7c6b2d
parent 19542 12449bbb64bd
child 19544 cad8ad34dd84
Fixes issue 22883: Partial goods shipments
from orders can be created with a higher amount than the ordered
src-db/database/model/triggers/M_INOUTLINE_TRG.xml
--- a/src-db/database/model/triggers/M_INOUTLINE_TRG.xml	Fri Feb 01 10:58:07 2013 +0100
+++ b/src-db/database/model/triggers/M_INOUTLINE_TRG.xml	Fri Feb 01 11:51:34 2013 +0100
@@ -84,12 +84,23 @@
    END IF;
 
    IF (v_QTYVARIABLE <> 'Y' AND v_ISSOTRX = 'Y' AND :NEW.C_ORDERLINE_ID IS NOT NULL) THEN
-      SELECT COUNT(*) INTO V_COUNT FROM C_ORDERLINE ol 
-      WHERE ol.C_ORDERLINE_ID = :NEW.C_ORDERLINE_ID 
-      AND ABS(:NEW.MOVEMENTQTY) > ABS(ol.QTYORDERED);
-          IF(V_COUNT <> 0) THEN
-	    RAISE_APPLICATION_ERROR(-20000, '@MovementQtyCheck@');
-	  END IF;
+       IF (UPDATING) THEN
+          IF(:old.MOVEMENTQTY <> :NEW.MOVEMENTQTY) THEN
+             SELECT COUNT(*) INTO V_COUNT 
+             FROM C_ORDERLINE ol 
+             WHERE ol.C_ORDERLINE_ID = :NEW.C_ORDERLINE_ID
+             AND ABS(:NEW.MOVEMENTQTY + coalesce(ol.QTYDELIVERED,0)) > ABS(ol.QTYORDERED);
+          END IF;
+       ELSE
+          SELECT COUNT(*) INTO V_COUNT 
+          FROM C_ORDERLINE ol 
+          WHERE ol.C_ORDERLINE_ID = :NEW.C_ORDERLINE_ID
+          AND ABS(:NEW.MOVEMENTQTY + coalesce(ol.QTYDELIVERED,0)) > ABS(ol.QTYORDERED);
+       END IF;
+
+       IF(V_COUNT <> 0) THEN
+	 RAISE_APPLICATION_ERROR(-20000, '@MovementQtyCheck@');
+       END IF;
    END IF;
  END IF;