Fixes issue 0020880: The organization in project phase and project task should
authorJon Alegría <jon.alegria@openbravo.com>
Tue, 03 Jul 2012 12:26:29 +0200
changeset 9871 c9b5c1ab5b1f
parent 9870 b7a1578e7492
child 9872 00dc02380cab
Fixes issue 0020880: The organization in project phase and project task should
change if the header org changes
src-db/database/model/triggers/C_PROJECTPHASE_TRG.xml
src-db/database/model/triggers/C_PROJECT_TRG.xml
--- a/src-db/database/model/triggers/C_PROJECTPHASE_TRG.xml	Tue Jun 26 13:29:03 2012 +0000
+++ b/src-db/database/model/triggers/C_PROJECTPHASE_TRG.xml	Tue Jul 03 12:26:29 2012 +0200
@@ -44,11 +44,13 @@
 END IF;
 
 IF UPDATING THEN
-  SELECT COUNT(*) INTO v_Count FROM C_PROJECTTASK WHERE C_PROJECTPHASE_ID = :NEW.C_PROJECTPHASE_ID;
-  IF(v_Count > 0) THEN
-    UPDATE C_PROJECTTASK
-    SET AD_ORG_ID = :NEW.AD_ORG_ID
-    WHERE C_PROJECTPHASE_ID = :NEW.C_PROJECTPHASE_ID;
+  IF (:new.AD_ORG_ID <> :old.AD_ORG_ID) THEN
+    SELECT COUNT(*) INTO v_Count FROM C_PROJECTTASK WHERE C_PROJECTPHASE_ID = :NEW.C_PROJECTPHASE_ID;
+    IF(v_Count > 0) THEN
+      UPDATE C_PROJECTTASK
+      SET AD_ORG_ID = :NEW.AD_ORG_ID
+      WHERE C_PROJECTPHASE_ID = :NEW.C_PROJECTPHASE_ID;
+    END IF;
   END IF;
 END IF;
 
--- a/src-db/database/model/triggers/C_PROJECT_TRG.xml	Tue Jun 26 13:29:03 2012 +0000
+++ b/src-db/database/model/triggers/C_PROJECT_TRG.xml	Tue Jul 03 12:26:29 2012 +0200
@@ -111,15 +111,17 @@
       )
       ;
     ELSIF (UPDATING) THEN
-     SELECT COUNT(*) INTO v_Count FROM C_PROJECTPHASE WHERE C_PROJECT_ID = :new.C_PROJECT_ID;
-     IF(v_Count > 0) THEN
-      UPDATE C_PROJECTPHASE
-      SET AD_ORG_ID = :new.AD_ORG_ID
-      WHERE C_PROJECT_ID = :new.C_PROJECT_ID;
-     END IF;
+     IF (:new.AD_ORG_ID <> :old.AD_ORG_ID) THEN
+       SELECT COUNT(*) INTO v_Count FROM C_PROJECTPHASE WHERE C_PROJECT_ID = :new.C_PROJECT_ID;
+       IF(v_Count > 0) THEN
+        UPDATE C_PROJECTPHASE
+        SET AD_ORG_ID = :new.AD_ORG_ID
+        WHERE C_PROJECT_ID = :new.C_PROJECT_ID;
+       END IF;
      
-     UPDATE C_PROJECT_ACCT SET AD_ORG_ID = :new.AD_ORG_ID
-     WHERE C_PROJECT_ID = :new.C_PROJECT_ID;
+       UPDATE C_PROJECT_ACCT SET AD_ORG_ID = :new.AD_ORG_ID
+       WHERE C_PROJECT_ID = :new.C_PROJECT_ID;
+      END IF;
     END IF;
     -- Summary Nodes first
 EXCEPTION