modules/org.openbravo.client.application/src-db/database/model/triggers/OBUIAPP_PARAMETER_MOD_TRG.xml
changeset 9076 c4f1a5c7d7c2
child 10780 bcc1e52f9ea9
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/org.openbravo.client.application/src-db/database/model/triggers/OBUIAPP_PARAMETER_MOD_TRG.xml	Fri Dec 10 19:47:45 2010 +0100
@@ -0,0 +1,99 @@
+<?xml version="1.0"?>
+  <database name="TRIGGER OBUIAPP_PARAMETER_MOD_TRG">
+    <trigger name="OBUIAPP_PARAMETER_MOD_TRG" table="OBUIAPP_PARAMETER" fires="before" insert="true" update="true" delete="true" foreach="row">
+      <body><![CDATA[
+
+/*************************************************************************
+* The contents of this file are subject to the Openbravo  Public  License
+* Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
+* Version 1.1  with a permitted attribution clause; you may not  use this
+* file except in compliance with the License. You  may  obtain  a copy of
+* the License at http://www.openbravo.com/legal/license.html
+* Software distributed under the License  is  distributed  on  an "AS IS"
+* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+* License for the specific  language  governing  rights  and  limitations
+* under the License.
+* The Original Code is Openbravo ERP.
+* The Initial Developer of the Original Code is Openbravo SLU
+* All portions are Copyright (C) 2010 Openbravo SLU
+* All Rights Reserved.
+* Contributor(s):  ______________________________________.
+************************************************************************/
+  devTemplate NUMBER;
+  fieldCount NUMBER;
+  selectorCount NUMBER;
+  devModule   CHAR(1);
+  currentModuleID  VARCHAR2(32);
+  vAux NUMBER;
+
+BEGIN
+    
+    IF AD_isTriggerEnabled()='N' THEN RETURN;
+    END IF;
+
+    -- check that we can't change to a module not in development
+    IF (UPDATING) THEN
+        IF (COALESCE(:NEW.AD_Module_ID , '.') != COALESCE(:OLD.AD_Module_ID , '.')) THEN
+            SELECT COUNT(*) 
+                INTO vAux
+                FROM AD_MODULE
+                WHERE AD_MODULE_ID = :old.AD_Module_ID
+                AND isindevelopment = 'N';
+            IF (vAux!=0) THEN
+                RAISE_APPLICATION_ERROR(-20000, '@ChangeNotInDevModule@');
+            END IF;
+        END IF;
+    END IF;
+
+    SELECT COUNT(*)
+        INTO devTemplate
+        FROM AD_MODULE
+        WHERE IsInDevelopment = 'Y'
+        AND Type = 'T';
+     
+    IF (UPDATING OR INSERTING) THEN
+        currentModuleID := :new.AD_Module_ID;
+    ELSE
+        currentModuleID := :old.AD_Module_ID;
+    END IF;
+
+    SELECT M.IsInDevelopment
+        INTO devModule
+        FROM AD_MODULE M
+        WHERE M.AD_MODULE_ID = currentModuleID;
+
+    IF (UPDATING AND devTemplate=0 AND devModule='N') THEN
+        IF (
+            COALESCE(:NEW.AD_Client_ID , '.') != COALESCE(:OLD.AD_Client_ID , '.') OR
+            COALESCE(:NEW.AD_Org_ID , '.') != COALESCE(:OLD.AD_Org_ID , '.') OR
+            COALESCE(:NEW.AD_Module_ID , '.') != COALESCE(:OLD.AD_Module_ID , '.') OR
+            COALESCE(:NEW.IsActive , '.') != COALESCE(:OLD.IsActive , '.') OR
+            COALESCE(:NEW.Name , '.') != COALESCE(:OLD.Name , '.') OR
+            COALESCE(:NEW.Description , '.') != COALESCE(:OLD.Description , '.') OR
+            COALESCE(:NEW.Help , '.') != COALESCE(:OLD.Help , '.') OR
+            COALESCE(:NEW.seqno , 0) != COALESCE(:OLD.seqno , 0) OR
+            COALESCE(:NEW.ad_reference_id , '.') != COALESCE(:OLD.ad_reference_id , '.') OR
+            COALESCE(:NEW.ad_reference_value_id , '.') != COALESCE(:OLD.ad_reference_value_id , '.') OR
+            COALESCE(:NEW.columnname , '.') != COALESCE(:OLD.columnname , '.') OR
+            COALESCE(:NEW.iscentrallymaintained , '.') != COALESCE(:OLD.iscentrallymaintained , '.') OR
+            COALESCE(:NEW.fieldlength , 0) != COALESCE(:OLD.fieldlength , 0) OR
+            COALESCE(:NEW.ismandatory , '.') != COALESCE(:OLD.ismandatory , '.') OR
+            COALESCE(:NEW.defaultvalue , '.') != COALESCE(:OLD.defaultvalue , '.') OR
+            COALESCE(:NEW.ad_element_id , '.') != COALESCE(:OLD.ad_element_id , '.') OR
+            COALESCE(:NEW.isfixed , '.') != COALESCE(:OLD.isfixed , '.') OR
+            COALESCE(:NEW.fixedvalue , '.') != COALESCE(:OLD.fixedvalue , '.') OR
+            COALESCE(:NEW.em_obkmo_widget_class_id , '.') != COALESCE(:OLD.em_obkmo_widget_class_id , '.') OR
+            1=2) THEN
+            RAISE_APPLICATION_ERROR(-20000, '@20532@');
+        END IF;
+    END IF;
+
+
+    -- don't allow insert/delete if not in development
+    IF ((DELETING OR INSERTING) AND devModule='N') THEN
+        RAISE_APPLICATION_ERROR(-20000, '@20533@');
+    END IF;
+END OBUIAPP_PARAMETER_MOD_TRG
+]]></body>
+    </trigger>
+  </database>