[Print PDF] Changed trigger C_FILE_TRG2 to check only other c_files for the same record
authorAaron Calero <aaron.calero@openbravo.com>
Wed, 13 Mar 2019 15:45:10 +0100
changeset 32494 672664220013
parent 32493 8d3f9f3ba6e5
child 32495 c191a834ff54
[Print PDF] Changed trigger C_FILE_TRG2 to check only other c_files for the same record
src-db/database/model/triggers/C_FILE_TRG2.xml
--- a/src-db/database/model/triggers/C_FILE_TRG2.xml	Mon Mar 11 17:20:27 2019 +0100
+++ b/src-db/database/model/triggers/C_FILE_TRG2.xml	Wed Mar 13 15:45:10 2019 +0100
@@ -1,6 +1,6 @@
 <?xml version="1.0"?>
   <database name="TRIGGER C_FILE_TRG2">
-    <trigger name="C_FILE_TRG2" table="C_FILE" fires="after" insert="true" update="true" delete="false" foreach="statement">
+    <trigger name="C_FILE_TRG2" table="C_FILE" fires="before" insert="true" update="true" delete="false" foreach="row">
       <body><![CDATA[
     /*************************************************************************
     * The contents of this file are subject to the Openbravo  Public  License
@@ -25,12 +25,11 @@
   END IF;
 
   -- Get number of attachments with multiple prints stored
-  SELECT COUNT(*) INTO v_count
-  FROM dual
-  WHERE EXISTS (SELECT 1
-                FROM c_file
-                WHERE keepandattachprintfile = 'Y'
-                GROUP BY ad_table_id, ad_record_id HAVING COUNT(*) > 1);
+  SELECT count(1) INTO v_count
+    FROM c_file
+    WHERE keepandattachprintfile = 'Y'
+    AND :new.ad_table_id = ad_table_id
+    AND :new.ad_record_id = ad_record_id;
 
   IF (v_count > 0) THEN
     RAISE_APPLICATION_ERROR(-20000, '@DuplicatedStoredPrinting@');