Fixes Issue 14229: Delete Parent Organizations
authorHarikrishnan Raja <harikrishnan.raja@openbravo.com>
Tue, 14 Sep 2010 13:32:07 +0530
changeset 8389 97a50a6985e3
parent 8388 1d0e1fd77ec2
child 8390 000d6e7b83fc
Fixes Issue 14229: Delete Parent Organizations
src-db/database/model/tables/AD_TREENODE.xml
src-db/database/model/triggers/AD_ORG_TRG.xml
src-db/database/sourcedata/AD_MESSAGE.xml
--- a/src-db/database/model/tables/AD_TREENODE.xml	Mon Sep 13 19:33:03 2010 +0200
+++ b/src-db/database/model/tables/AD_TREENODE.xml	Tue Sep 14 13:32:07 2010 +0530
@@ -52,7 +52,7 @@
       <foreign-key foreignTable="AD_CLIENT" name="AD_TREENODE_AD_CLIENT">
         <reference local="AD_CLIENT_ID" foreign="AD_CLIENT_ID"/>
       </foreign-key>
-      <foreign-key foreignTable="AD_ORG" name="AD_TREENODE_AD_ORG" onDelete="cascade">
+      <foreign-key foreignTable="AD_ORG" name="AD_TREENODE_AD_ORG">
         <reference local="AD_ORG_ID" foreign="AD_ORG_ID"/>
       </foreign-key>
       <foreign-key foreignTable="AD_TREE" name="AD_TREENODE_AD_TREE" onDelete="cascade">
--- a/src-db/database/model/triggers/AD_ORG_TRG.xml	Mon Sep 13 19:33:03 2010 +0200
+++ b/src-db/database/model/triggers/AD_ORG_TRG.xml	Tue Sep 14 13:32:07 2010 +0530
@@ -26,6 +26,7 @@
   v_xParent_ID VARCHAR2(32);
   TYPE RECORD IS REF CURSOR;
     CUR_PeriodControl RECORD;
+    v_count NUMBER;
   
     
 BEGIN
@@ -111,6 +112,11 @@
     INTO v_xTree_ID
     FROM AD_ClientInfo c
     WHERE c.AD_Client_ID=:old.AD_Client_ID;
+    select COUNT(*) INTO v_count from AD_TREENODE where parent_id=:old.AD_ORG_ID
+  	and AD_TREE_ID=v_xTree_ID;
+    IF(v_count>0) THEN
+    	RAISE_APPLICATION_ERROR(-20000, '@ChildOrgCheck@') ;
+    END IF;
     DELETE
     FROM AD_TREENODE
     WHERE AD_CLIENT_ID=:old.AD_Client_ID
--- a/src-db/database/sourcedata/AD_MESSAGE.xml	Mon Sep 13 19:33:03 2010 +0200
+++ b/src-db/database/sourcedata/AD_MESSAGE.xml	Tue Sep 14 13:32:07 2010 +0530
@@ -29932,6 +29932,17 @@
 <!--173455990A494A799F86C2737D8F9617-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--173455990A494A799F86C2737D8F9617--></AD_MESSAGE>
 
+<!--17456DF6F0804BF2996AE696DFA31EC9--><AD_MESSAGE>
+<!--17456DF6F0804BF2996AE696DFA31EC9-->  <AD_MESSAGE_ID><![CDATA[17456DF6F0804BF2996AE696DFA31EC9]]></AD_MESSAGE_ID>
+<!--17456DF6F0804BF2996AE696DFA31EC9-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--17456DF6F0804BF2996AE696DFA31EC9-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--17456DF6F0804BF2996AE696DFA31EC9-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--17456DF6F0804BF2996AE696DFA31EC9-->  <VALUE><![CDATA[ChildOrgCheck]]></VALUE>
+<!--17456DF6F0804BF2996AE696DFA31EC9-->  <MSGTEXT><![CDATA[This organization cannot be deleted because it has child organizations. Please, delete the child organizations first]]></MSGTEXT>
+<!--17456DF6F0804BF2996AE696DFA31EC9-->  <MSGTYPE><![CDATA[E]]></MSGTYPE>
+<!--17456DF6F0804BF2996AE696DFA31EC9-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--17456DF6F0804BF2996AE696DFA31EC9--></AD_MESSAGE>
+
 <!--17EB942A41BC417FA70FDFCA35027276--><AD_MESSAGE>
 <!--17EB942A41BC417FA70FDFCA35027276-->  <AD_MESSAGE_ID><![CDATA[17EB942A41BC417FA70FDFCA35027276]]></AD_MESSAGE_ID>
 <!--17EB942A41BC417FA70FDFCA35027276-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>