Commit a1cfccef authored by Iñigo Lerga Valencia's avatar Iñigo Lerga Valencia Committed by David Miguélez
Browse files

fixes BUG-44622:Condition relaxed in M_TRANSACTION_TRG trigger

When the stock of a product is negative (and the record is a
movementLine, sales inoutLine or productionLine) there is no need
to specify the attribute value of the product.
parent c24aba2e
......@@ -38,8 +38,11 @@
v_doDecrease BOOLEAN:= FALSE;
v_stockdiff NUMBER:= 0;
v_checkuom NUMBER:= 0;
v_stockCount NUMBER;
v_inventoryLineQtyCount M_INVENTORYLINE.QTYCOUNT%TYPE;
v_qtyOnHand M_STORAGE_DETAIL.QTYONHAND%TYPE;
v_preQtyOnHand M_STORAGE_DETAIL.PREQTYONHAND%TYPE;
v_hasZeroStockOrPending BOOLEAN:= FALSE;
v_issotrx M_INOUT.ISSOTRX%TYPE;
BEGIN
IF AD_isTriggerEnabled()='N' THEN RETURN;
END IF;
......@@ -74,28 +77,40 @@ BEGIN
RAISE_APPLICATION_ERROR(-20000, '@20111@') ;
END IF;
IF(v_attributeset_id IS NOT NULL AND (v_AttrSetValueType IS NULL OR v_AttrSetValueType <> 'F') AND v_IsOneAtSetValReq = 'Y' AND COALESCE(:NEW.M_ATTRIBUTESETINSTANCE_ID, '0') = '0' ) THEN
SELECT SD.QTYONHAND, SD.PREQTYONHAND
INTO v_qtyOnHand, v_preQtyOnHand
FROM M_STORAGE_DETAIL SD
WHERE SD.M_PRODUCT_ID = :NEW.M_PRODUCT_ID
AND SD.M_LOCATOR_ID = :NEW.M_LOCATOR_ID
AND SD.M_ATTRIBUTESETINSTANCE_ID = '0'
AND SD.C_UOM_ID = :NEW.C_UOM_ID;
IF(:NEW.M_INVENTORYLINE_ID IS NOT NULL) THEN
SELECT IL.QTYCOUNT INTO v_inventoryLineQtyCount
FROM M_INVENTORYLINE IL
WHERE IL.M_INVENTORYLINE_ID = :NEW.M_INVENTORYLINE_ID;
SELECT COUNT(1) INTO v_stockCount
FROM DUAL
WHERE EXISTS (SELECT 1
FROM M_STORAGE_DETAIL SD
WHERE SD.M_PRODUCT_ID = :NEW.M_PRODUCT_ID
AND SD.M_LOCATOR_ID = :NEW.M_LOCATOR_ID
AND SD.M_ATTRIBUTESETINSTANCE_ID = '0'
AND SD.C_UOM_ID = :NEW.C_UOM_ID
AND SD.QTYONHAND <> 0
AND SD.PREQTYONHAND <> 0);
IF(v_inventoryLineQtyCount <> 0 OR (v_inventoryLineQtyCount = 0 AND v_stockCount = 0)) THEN
v_hasZeroStockOrPending:= (v_qtyOnHand = 0 OR v_preQtyOnHand = 0);
IF(v_inventoryLineQtyCount <> 0 OR (v_inventoryLineQtyCount = 0 AND v_hasZeroStockOrPending)) THEN
RAISE_APPLICATION_ERROR(-20000, '@20112@' || ' - ' || v_Name) ;
END IF;
ELSIF (:NEW.M_INOUTLINE_ID IS NOT NULL) THEN
SELECT io.issotrx
INTO v_issotrx
FROM m_inout io
JOIN m_inoutline iol ON (iol.m_inout_id = io.m_inout_id)
WHERE iol.m_inoutline_id = :NEW.m_inoutline_id;
IF (v_issotrx = 'N' OR v_qtyOnHand >= 0) THEN
RAISE_APPLICATION_ERROR(-20000, '@20112@' || ' - ' || v_Name) ;
END IF;
ELSE
RAISE_APPLICATION_ERROR(-20000, '@20112@' || ' - ' || v_Name) ;
END IF;
IF ( v_qtyOnHand >= 0) THEN
RAISE_APPLICATION_ERROR(-20000, '@20112@' || ' - ' || v_Name) ;
END IF;
END IF;
END IF;
--Does not allow to change the attribute set value
-- for products which attribute set value type is Fixed
......@@ -137,27 +152,39 @@ BEGIN
END IF;
END IF;
IF(v_attributeset_id IS NOT NULL AND (v_AttrSetValueType IS NULL OR v_AttrSetValueType <> 'F') AND v_IsOneAtSetValReq = 'Y' AND COALESCE(:NEW.M_ATTRIBUTESETINSTANCE_ID, '0') = '0') THEN
SELECT SD.QTYONHAND, SD.PREQTYONHAND
INTO v_qtyOnHand, v_preQtyOnHand
FROM M_STORAGE_DETAIL SD
WHERE SD.M_PRODUCT_ID = :NEW.M_PRODUCT_ID
AND SD.M_LOCATOR_ID = :NEW.M_LOCATOR_ID
AND SD.M_ATTRIBUTESETINSTANCE_ID = '0'
AND SD.C_UOM_ID = :NEW.C_UOM_ID;
IF(:NEW.M_INVENTORYLINE_ID IS NOT NULL) THEN
SELECT IL.QTYCOUNT INTO v_inventoryLineQtyCount
FROM M_INVENTORYLINE IL
WHERE IL.M_INVENTORYLINE_ID = :NEW.M_INVENTORYLINE_ID;
SELECT COUNT(1) INTO v_stockCount
FROM DUAL
WHERE EXISTS (SELECT 1
FROM M_STORAGE_DETAIL SD
WHERE SD.M_PRODUCT_ID = :NEW.M_PRODUCT_ID
AND SD.M_LOCATOR_ID = :NEW.M_LOCATOR_ID
AND SD.M_ATTRIBUTESETINSTANCE_ID = '0'
AND SD.C_UOM_ID = :NEW.C_UOM_ID
AND SD.QTYONHAND <> 0
AND SD.PREQTYONHAND <> 0);
v_hasZeroStockOrPending:= (v_qtyOnHand = 0 OR v_preQtyOnHand = 0);
IF(v_inventoryLineQtyCount <> 0 OR (v_inventoryLineQtyCount = 0 AND v_hasZeroStockOrPending)) THEN
RAISE_APPLICATION_ERROR(-20000, '@20112@' || ' - ' || v_Name) ;
END IF;
ELSIF (:NEW.M_INOUTLINE_ID IS NOT NULL) THEN
SELECT io.issotrx
INTO v_issotrx
FROM m_inout io
JOIN m_inoutline iol ON (iol.m_inout_id = io.m_inout_id)
WHERE iol.m_inoutline_id = :NEW.m_inoutline_id;
IF(v_inventoryLineQtyCount <> 0 OR (v_inventoryLineQtyCount = 0 AND v_stockCount = 0)) THEN
IF (v_issotrx = 'N' OR v_qtyOnHand >= 0) THEN
RAISE_APPLICATION_ERROR(-20000, '@20112@' || ' - ' || v_Name) ;
END IF;
ELSE
RAISE_APPLICATION_ERROR(-20000, '@20112@' || ' - ' || v_Name) ;
IF ( v_qtyOnHand >= 0) THEN
RAISE_APPLICATION_ERROR(-20000, '@20112@' || ' - ' || v_Name) ;
END IF;
END IF;
END IF;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment