src-db/database/model/triggers/AD_TABLE_MOD_TRG.xml
author Asier Lostalé <asier.lostale@openbravo.com>
Fri, 19 Feb 2010 14:16:19 +0100
changeset 6500 cbe25f0abf2c
parent 6498 6b8d9ce301fd
child 6702 690d2af86089
permissions -rw-r--r--
fixed erp_devel_pi-full-pgsql - Build # 783
asier@1929
     1
<?xml version="1.0"?>
asier@1929
     2
  <database name="TRIGGER AD_TABLE_MOD_TRG">
asier@1929
     3
    <trigger name="AD_TABLE_MOD_TRG" table="AD_TABLE" fires="before" insert="true" update="true" delete="true" foreach="row">
asier@1929
     4
      <body><![CDATA[
asier@1929
     5
asier@1929
     6
/*************************************************************************
asier@1929
     7
* The contents of this file are subject to the Openbravo  Public  License
asier@1929
     8
* Version  1.0  (the  "License"),  being   the  Mozilla   Public  License
asier@1929
     9
* Version 1.1  with a permitted attribution clause; you may not  use this
asier@1929
    10
* file except in compliance with the License. You  may  obtain  a copy of
asier@1929
    11
* the License at http://www.openbravo.com/legal/license.html
asier@1929
    12
* Software distributed under the License  is  distributed  on  an "AS IS"
asier@1929
    13
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
asier@1929
    14
* License for the specific  language  governing  rights  and  limitations
asier@1929
    15
* under the License.
asier@1929
    16
* The Original Code is Openbravo ERP.
asier@1929
    17
* The Initial Developer of the Original Code is Openbravo SL
asier@6498
    18
* All portions are Copyright (C) 2008-2010 Openbravo SL
asier@1929
    19
* All Rights Reserved.
asier@1929
    20
* Contributor(s):  ______________________________________.
asier@1929
    21
************************************************************************/
asier@1929
    22
  devTemplate NUMBER;
asier@1929
    23
  devModule   CHAR(1);
asier@1929
    24
  cuerrentID  VARCHAR2(32);
asier@1929
    25
  cuerrentModuleID  VARCHAR2(32);
asier@4009
    26
  vAux NUMBER;
asier@2084
    27
    
asier@1929
    28
BEGIN
asier@2084
    29
    
asier@2084
    30
    IF AD_isTriggerEnabled()='N' THEN RETURN;
asier@2078
    31
    END IF;
asier@2078
    32
asier@4009
    33
  --Check if trying to move object from module not in dev
asier@4009
    34
  IF (UPDATING) THEN
asier@4009
    35
    IF (COALESCE(:NEW.AD_Package_ID , '.') != COALESCE(:OLD.AD_Package_ID , '.')) THEN
asier@4009
    36
      SELECT COUNT(*) 
asier@4009
    37
        INTO vAux
asier@4009
    38
        FROM AD_MODULE M, AD_PACKAGE P
asier@4009
    39
       WHERE M.AD_MODULE_ID = P.AD_Module_ID
asier@4009
    40
        AND :old.AD_Package_ID = p.ad_package_id
asier@4009
    41
        AND M.isindevelopment = 'N';
asier@4009
    42
      IF (vAux!=0) THEN
asier@4009
    43
        RAISE_APPLICATION_ERROR(-20000, '@ChangeNotInDevModule@');
asier@4009
    44
      END IF;
asier@4009
    45
    END IF;
asier@4009
    46
  END IF;
asier@2078
    47
asier@1929
    48
  SELECT COUNT(*)
asier@1929
    49
    INTO devTemplate
asier@1929
    50
    FROM AD_MODULE
asier@1929
    51
   WHERE IsInDevelopment = 'Y'
asier@1929
    52
     AND Type = 'T';
asier@1929
    53
     
asier@1929
    54
  IF (UPDATING OR INSERTING) THEN
asier@1929
    55
    cuerrentID := :new.AD_Table_ID;
asier@1929
    56
    cuerrentModuleID := :new.AD_Package_ID;
asier@1929
    57
  ELSE
asier@1929
    58
    cuerrentID := :old.AD_Table_ID;
asier@1929
    59
    cuerrentModuleID := :old.AD_Package_ID;
asier@1929
    60
  END IF;
asier@1929
    61
  
asier@1929
    62
  SELECT M.IsInDevelopment
asier@1929
    63
    INTO devModule
asier@1929
    64
    FROM AD_MODULE M, AD_PACKAGE P
asier@1929
    65
   WHERE M.AD_MODULE_ID = P.AD_MODULE_ID
asier@1929
    66
     AND P.AD_PACKAGE_ID = cuerrentModuleID;
asier@1929
    67
     
asier@1929
    68
  IF (UPDATING AND devTemplate=0 AND devModule='N') THEN
asier@1929
    69
    IF (
asier@1929
    70
        COALESCE(:NEW.AD_Client_ID , '.') != COALESCE(:OLD.AD_Client_ID , '.') OR
asier@1929
    71
        COALESCE(:NEW.AD_Org_ID , '.') != COALESCE(:OLD.AD_Org_ID , '.') OR
asier@1929
    72
        COALESCE(:NEW.IsActive , '.') != COALESCE(:OLD.IsActive , '.') OR
asier@1929
    73
        COALESCE(:NEW.Name , '.') != COALESCE(:OLD.Name , '.') OR
asier@1929
    74
        COALESCE(:NEW.Description , '.') != COALESCE(:OLD.Description , '.') OR
asier@1929
    75
        COALESCE(:NEW.Help , '.') != COALESCE(:OLD.Help , '.') OR
asier@1929
    76
        COALESCE(:NEW.TableName , '.') != COALESCE(:OLD.TableName , '.') OR
asier@1929
    77
        COALESCE(:NEW.IsView , '.') != COALESCE(:OLD.IsView , '.') OR
asier@1929
    78
        COALESCE(:NEW.AccessLevel , '.') != COALESCE(:OLD.AccessLevel , '.') OR
asier@1929
    79
        COALESCE(:NEW.AD_Window_ID , '.') != COALESCE(:OLD.AD_Window_ID , '.') OR
asier@1929
    80
        COALESCE(:NEW.IsSecurityEnabled , '.') != COALESCE(:OLD.IsSecurityEnabled , '.') OR
asier@1929
    81
        COALESCE(:NEW.IsDeleteable , '.') != COALESCE(:OLD.IsDeleteable , '.') OR
asier@1929
    82
        COALESCE(:NEW.IsHighVolume , '.') != COALESCE(:OLD.IsHighVolume , '.') OR
asier@1929
    83
        COALESCE(:NEW.ImportTable , '.') != COALESCE(:OLD.ImportTable , '.') OR
asier@1929
    84
        COALESCE(:NEW.IsChangeLog , '.') != COALESCE(:OLD.IsChangeLog , '.') OR
asier@1929
    85
        COALESCE(:NEW.PO_Window_ID , '.') != COALESCE(:OLD.PO_Window_ID , '.') OR
asier@1929
    86
        COALESCE(:NEW.IsDefaultAcct , '.') != COALESCE(:OLD.IsDefaultAcct , '.') OR
asier@1929
    87
        COALESCE(:NEW.Developmentstatus , '.') != COALESCE(:OLD.Developmentstatus , '.') OR
asier@1929
    88
        COALESCE(:NEW.AD_Package_ID , '.') != COALESCE(:OLD.AD_Package_ID , '.') 
asier@1929
    89
        
asier@1929
    90
        --SQL_Record_Identifier is not going to be exported
asier@1929
    91
        ) THEN
asier@1929
    92
      RAISE_APPLICATION_ERROR(-20532, 'Cannot update an object in a module not in developement and without an active template');
asier@1929
    93
    END IF;
asier@1929
    94
  END IF;
asier@1929
    95
  
asier@1929
    96
  IF ((DELETING OR INSERTING) AND devModule='N') THEN
asier@1929
    97
    RAISE_APPLICATION_ERROR(-20533, 'Cannot insert/delete objects in a module not in development.');
asier@1929
    98
  END IF;
asier@6498
    99
  
asier@6498
   100
  --Check the only updated column is isFullyAudited. In this case maitin updated
asier@6498
   101
  --column as it was to prevent changes detection when trying to update database
asier@6500
   102
  IF (UPDATING) THEN
asier@6500
   103
    IF (COALESCE(:NEW.ISACTIVE             ,'.') = COALESCE(:OLD.ISACTIVE             ,'.') AND                                                                                                                                                                            
asier@6498
   104
      COALESCE(:NEW.NAME                 ,'.') = COALESCE(:OLD.NAME                 ,'.') AND                                                                                                                                                                            
asier@6498
   105
      COALESCE(:NEW.DESCRIPTION          ,'.') = COALESCE(:OLD.DESCRIPTION          ,'.') AND                                                                                                                                                                            
asier@6498
   106
      COALESCE(:NEW.HELP                 ,'.') = COALESCE(:OLD.HELP                 ,'.') AND                                                                                                                                                                            
asier@6498
   107
      COALESCE(:NEW.TABLENAME            ,'.') = COALESCE(:OLD.TABLENAME            ,'.') AND                                                                                                                                                                            
asier@6498
   108
      COALESCE(:NEW.CLASSNAME            ,'.') = COALESCE(:OLD.CLASSNAME            ,'.') AND                                                                                                                                                                            
asier@6498
   109
      COALESCE(:NEW.ISVIEW               ,'.') = COALESCE(:OLD.ISVIEW               ,'.') AND                                                                                                                                                                            
asier@6498
   110
      COALESCE(:NEW.ACCESSLEVEL          ,'.') = COALESCE(:OLD.ACCESSLEVEL          ,'.') AND                                                                                                                                                                            
asier@6498
   111
      COALESCE(:NEW.AD_WINDOW_ID         ,'.') = COALESCE(:OLD.AD_WINDOW_ID         ,'.') AND                                                                                                                                                                            
asier@6498
   112
      COALESCE(:NEW.ISSECURITYENABLED    ,'.') = COALESCE(:OLD.ISSECURITYENABLED    ,'.') AND                                                                                                                                                                            
asier@6498
   113
      COALESCE(:NEW.ISDELETEABLE         ,'.') = COALESCE(:OLD.ISDELETEABLE         ,'.') AND                                                                                                                                                                            
asier@6498
   114
      COALESCE(:NEW.ISHIGHVOLUME         ,'.') = COALESCE(:OLD.ISHIGHVOLUME         ,'.') AND                                                                                                                                                                            
asier@6498
   115
      COALESCE(:NEW.IMPORTTABLE          ,'.') = COALESCE(:OLD.IMPORTTABLE          ,'.') AND                                                                                                                                                                            
asier@6498
   116
      COALESCE(:NEW.ISCHANGELOG          ,'.') = COALESCE(:OLD.ISCHANGELOG          ,'.') AND                                                                                                                                                                            
asier@6498
   117
      COALESCE(:NEW.PO_WINDOW_ID         ,'.') = COALESCE(:OLD.PO_WINDOW_ID         ,'.') AND                                                                                                                                                                            
asier@6498
   118
      COALESCE(:NEW.ISDEFAULTACCT        ,'.') = COALESCE(:OLD.ISDEFAULTACCT        ,'.') AND                                                                                                                                                                            
asier@6498
   119
      COALESCE(:NEW.SQL_RECORD_IDENTIFIER,'.') = COALESCE(:OLD.SQL_RECORD_IDENTIFIER,'.') AND                                                                                                                                                                            
asier@6498
   120
      COALESCE(:NEW.DEVELOPMENTSTATUS    ,'.') = COALESCE(:OLD.DEVELOPMENTSTATUS    ,'.') AND                                                                                                                                                                            
asier@6498
   121
      COALESCE(:NEW.AD_PACKAGE_ID        ,'.') = COALESCE(:OLD.AD_PACKAGE_ID        ,'.') AND                                                                                                                                                                            
asier@6498
   122
      COALESCE(:NEW.TREETYPE             ,'.') = COALESCE(:OLD.TREETYPE             ,'.') AND                                                                                                                                                                            
asier@6498
   123
      COALESCE(:NEW.ACCTDATE_COLUMN_ID   ,'.') = COALESCE(:OLD.ACCTDATE_COLUMN_ID   ,'.') AND                                                                                                                                                                            
asier@6498
   124
      COALESCE(:NEW.ACCTCLASSNAME        ,'.') = COALESCE(:OLD.ACCTCLASSNAME        ,'.') AND
asier@6498
   125
      :NEW.ISFULLYAUDITED != :OLD.ISFULLYAUDITED) THEN
asier@6498
   126
         :NEW.UPDATED := :OLD.UPDATED;
asier@6500
   127
    END IF;
asier@6498
   128
  END IF;
asier@1929
   129
END AD_TABLE_MOD_TRG
asier@1929
   130
]]></body>
asier@1929
   131
    </trigger>
asier@1929
   132
  </database>