src-db/database/model/functions/M_INOUT_POST.xml
changeset 20976 3f5e8c7117d6
parent 20963 a0563a002814
child 21195 26448a5e9156
child 21353 408b26ad5754
--- a/src-db/database/model/functions/M_INOUT_POST.xml	Mon Aug 12 10:36:36 2013 +0200
+++ b/src-db/database/model/functions/M_INOUT_POST.xml	Mon Aug 12 11:13:35 2013 +0200
@@ -262,12 +262,18 @@
         RAISE_APPLICATION_ERROR(-20000, '@ReturnInOutNegativeQty@');
       END IF;
     END IF;
-      SELECT count(*), max(p.name)
-        INTO v_count, v_productname
-      FROM m_inoutline il JOIN m_product p ON il.m_product_id = p.m_product_id
-      WHERE il.m_inout_id = v_record_id
-        AND COALESCE(p.isgeneric, 'N') = 'Y';
+      SELECT count(*) INTO v_count
+      FROM dual
+      WHERE EXISTS (
+          SELECT 1
+          FROM m_inoutline il JOIN m_product p ON il.m_product_id = p.m_product_id
+          WHERE il.m_inout_id = v_record_id
+            AND p.isgeneric = 'Y');
       IF (v_count > 0) THEN
+        SELECT max(p.name) INTO v_productname
+        FROM m_inoutline il JOIN m_product p ON il.m_product_id = p.m_product_id
+        WHERE il.m_inout_id = v_record_id
+          AND p.isgeneric = 'Y';
         RAISE_APPLICATION_ERROR(-20000, '@CannotUseGenericProduct@ ' || v_productName);
       END IF;