Fixes issue 22883: Partial goods shipments from orders
authorJavier Etxarri <javier.echarri@openbravo.com>
Wed, 30 Jan 2013 18:02:39 +0100
changeset 19525 388afb7bcd0d
parent 19524 841c9df2a9d8
child 19526 2a17ea3bee3a
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	Wed Jan 30 15:47:57 2013 +0100
+++ b/src-db/database/model/triggers/M_INOUTLINE_TRG.xml	Wed Jan 30 18:02:39 2013 +0100
@@ -84,12 +84,20 @@
    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;
+       v_count:=0;
+       SELECT count(*)
+       INTO V_COUNT
+       FROM m_inout mi
+            LEFT JOIN m_inoutline ml ON ml.m_inout_id=mi.m_inout_id
+            LEFT JOIN c_orderline ol ON ml.c_orderline_id = ol.c_orderline_id 
+       WHERE ml.c_orderline_id = :NEW.C_ORDERLINE_ID 
+       AND (mi.docstatus='CO' or ml.m_inout_id = :NEW.m_inout_id)
+       GROUP BY ml.c_orderline_id,ol.QTYORDERED
+       HAVING abs(sum(ml.MOVEMENTQTY)) > ABS(ol.QTYORDERED);
+
+       IF(V_COUNT <> 0) THEN
+	 RAISE_APPLICATION_ERROR(-20000, '@MovementQtyCheck@');
+       END IF;
    END IF;
  END IF;