From 62bd2ae03bfb7ebd54bdf725a6455ccdfb0e0fff Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 2 Oct 2024 11:27:09 +0200 Subject: [PATCH] refactor: refs #6824 Throw for no delete itemShelving with itemShelvingSale --- .../vn/triggers/itemShelving_beforeDelete.sql | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/db/routines/vn/triggers/itemShelving_beforeDelete.sql b/db/routines/vn/triggers/itemShelving_beforeDelete.sql index 89737a841..8313e3ed9 100644 --- a/db/routines/vn/triggers/itemShelving_beforeDelete.sql +++ b/db/routines/vn/triggers/itemShelving_beforeDelete.sql @@ -2,14 +2,26 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`itemShelving_beforeDelete` BEFORE DELETE ON `itemShelving` FOR EACH ROW -INSERT INTO vn.itemShelvingLog(itemShelvingFk, - workerFk, - accion, - shelvingFk, - itemFk) - VALUES( OLD.id, - account.myUser_getId(), - 'ELIMINADO', - OLD.shelvingFk, - OLD.itemFk)$$ +BEGIN + DECLARE vItemShelvingSaleExists BOOL; + + SELECT COUNT(*) INTO vItemShelvingSaleExists + FROM itemShelvingSale + WHERE itemShelvingFk = OLD.id; + + IF vItemShelvingSaleExists AND @canDeleteItemShelvingSale IS NULL THEN + CALL util.throw('Cannot delete item shelving with item shelving sale'); + END IF; + + INSERT INTO vn.itemShelvingLog(itemShelvingFk, + workerFk, + accion, + shelvingFk, + itemFk) + VALUES( OLD.id, + account.myUser_getId(), + 'ELIMINADO', + OLD.shelvingFk, + OLD.itemFk); +END$$ DELIMITER ;