src-db/database/model/triggers/M_INVENTORYLINE2_TRG.xml
author David Miguelez <david.miguelez@openbravo.com>
Fri, 17 Jan 2020 15:02:42 +0100
changeset 36961 16059e5842d1
parent 33170 68d09ac13f38
permissions -rw-r--r--
Related to ISSUE-42840: Code Review Changes:
* Do not use Boolean.TRUE, keep old comparison as the code
is more redable
adrian@94
     1
<?xml version="1.0"?>
adrian@94
     2
  <database name="TRIGGER M_INVENTORYLINE2_TRG">
adrian@94
     3
    <trigger name="M_INVENTORYLINE2_TRG" table="M_INVENTORYLINE" fires="before" insert="true" update="true" delete="false" foreach="row">
gorkaion@239
     4
      <body><![CDATA[
gorkaion@239
     5
adrian@170
     6
adrian@94
     7
adrian@94
     8
adrian@94
     9
/*************************************************************************
adrian@94
    10
* The contents of this file are subject to the Openbravo  Public  License
priya@9072
    11
* Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
adrian@94
    12
* Version 1.1  with a permitted attribution clause; you may not  use this
adrian@94
    13
* file except in compliance with the License. You  may  obtain  a copy of
adrian@94
    14
* the License at http://www.openbravo.com/legal/license.html
adrian@94
    15
* Software distributed under the License  is  distributed  on  an "AS IS"
adrian@94
    16
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
adrian@94
    17
* License for the specific  language  governing  rights  and  limitations
adrian@94
    18
* under the License.
adrian@94
    19
* The Original Code is Openbravo ERP.
ggi@6701
    20
* The Initial Developer of the Original Code is Openbravo SLU
david@33170
    21
* All portions are Copyright (C) 2001-2017 Openbravo SLU
adrian@94
    22
* All Rights Reserved.
adrian@94
    23
* Contributor(s):  ______________________________________.
adrian@94
    24
************************************************************************/
david@33170
    25
  v_productname m_product.name%TYPE;
gorkaion@20941
    26
  v_isgeneric   CHAR(1);
asier@2084
    27
        
asier@2078
    28
BEGIN
asier@2084
    29
    
asier@2084
    30
    IF AD_isTriggerEnabled()='N' THEN RETURN;
asier@2078
    31
    END IF;
asier@2078
    32
asier@2078
    33
 IF(UPDATING)
juanpablo@1605
    34
    THEN  IF NOT((COALESCE(:OLD.M_Product_Uom_ID, '0') <> COALESCE(:NEW.M_Product_Uom_ID, '0')
gorkaion@239
    35
    OR COALESCE(:OLD.QuantityOrderBook, 0) <> COALESCE(:NEW.QuantityOrderBook, 0)))
adrian@94
    36
    THEN  RETURN;
adrian@94
    37
    END IF;
adrian@94
    38
   END IF;
adrian@94
    39
 IF(UPDATING OR INSERTING) THEN
adrian@94
    40
  IF(:NEW.M_Product_Uom_ID IS NOT NULL AND :NEW.QuantityOrderBook IS NULL) THEN
adrian@94
    41
    :NEW.QuantityOrderBook:=0;
adrian@94
    42
  ELSIF(:NEW.M_Product_Uom_ID IS NULL AND :NEW.QuantityOrderBook IS NOT NULL) THEN
adrian@94
    43
    :NEW.QuantityOrderBook:=NULL;
adrian@94
    44
  END IF;
adrian@94
    45
 END IF;
gorkaion@20972
    46
  IF (INSERTING OR UPDATING) THEN
gorkaion@20941
    47
    IF (:NEW.m_product_id IS NOT NULL) THEN
david@33170
    48
      SELECT isgeneric, name INTO v_isgeneric, v_productname
gorkaion@20941
    49
      FROM m_product
gorkaion@20941
    50
      WHERE m_product_id = :NEW.m_product_id;
gorkaion@20941
    51
      IF (v_isgeneric = 'Y') THEN
david@33170
    52
        RAISE_APPLICATION_ERROR(-20000, '@CannotUseGenericProduct@ ' || v_productname);
gorkaion@20941
    53
      END IF;
gorkaion@20941
    54
    END IF;
gorkaion@20941
    55
  END IF;END M_INVENTORYLINE2_TRG
gorkaion@239
    56
]]></body>
adrian@94
    57
    </trigger>
adrian@94
    58
  </database>