From 8cc88453c4bef6503f0250fa82a358d46b0e2c9b Mon Sep 17 00:00:00 2001 From: Pako Date: Mon, 3 Mar 2025 13:29:20 +0100 Subject: [PATCH] fix(travel): new trigger for travel and new version to update it stockRefresh and entryIn also updated Refs: #8048 --- db/routines/cache/procedures/stock_refresh.sql | 13 +++++++++---- db/routines/vn/triggers/travel_beforeInsert.sql | 2 +- db/routines/vn/triggers/travel_beforeUpdate.sql | 5 +++-- db/routines/vn/views/itemEntryIn.sql | 2 +- db/versions/11470-blackCamellia/00-firstScript.sql | 4 ++++ db/versions/11470-blackCamellia/01-alterTable.sql | 2 ++ 6 files changed, 20 insertions(+), 8 deletions(-) create mode 100644 db/versions/11470-blackCamellia/00-firstScript.sql create mode 100644 db/versions/11470-blackCamellia/01-alterTable.sql diff --git a/db/routines/cache/procedures/stock_refresh.sql b/db/routines/cache/procedures/stock_refresh.sql index 5ddc6c20e1..ed69e63e5f 100644 --- a/db/routines/cache/procedures/stock_refresh.sql +++ b/db/routines/cache/procedures/stock_refresh.sql @@ -1,8 +1,9 @@ DELIMITER $$ +$$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `cache`.`stock_refresh`(v_refresh BOOL) proc: BEGIN /** - * Crea o actualiza la cache con el disponible hasta el dí­a de + * Crea o actualiza la cache con el disponible hasta el día de * ayer. Esta cache es usada como base para otros procedimientos * como el cálculo del visible o del ATP. * @@ -36,15 +37,19 @@ proc: BEGIN ( SELECT itemFk AS item_id, warehouseFk AS warehouse_id, quantity AS amount FROM vn.itemTicketOut - WHERE shipped >= v_date_inv AND shipped < vCURDATE + WHERE shipped >= v_date_inv + AND shipped < vCURDATE UNION ALL SELECT itemFk ASitem_id, warehouseInFk AS warehouse_id, quantity AS amount FROM vn.itemEntryIn - WHERE landed >= v_date_inv AND landed < vCURDATE AND isVirtualStock is FALSE + WHERE availabled >= v_date_inv + AND availabled < vCURDATE + AND isVirtualStock is FALSE UNION ALL SELECT itemFk AS item_id ,warehouseOutFk AS warehouse_id, quantity AS amount FROM vn.itemEntryOut - WHERE shipped >= v_date_inv AND shipped < vCURDATE + WHERE shipped >= v_date_inv + AND shipped < vCURDATE ) t GROUP BY item_id, warehouse_id HAVING amount != 0; diff --git a/db/routines/vn/triggers/travel_beforeInsert.sql b/db/routines/vn/triggers/travel_beforeInsert.sql index 2cae96cd98..4997cc5fc8 100644 --- a/db/routines/vn/triggers/travel_beforeInsert.sql +++ b/db/routines/vn/triggers/travel_beforeInsert.sql @@ -18,7 +18,7 @@ BEGIN END IF; IF NEW.availabled < NEW.landed THEN - CALL util.throw('The travel availabled cannot be earlier than landed'); + SET NEW.availabled = NEW.landed; END IF; END$$ DELIMITER ; diff --git a/db/routines/vn/triggers/travel_beforeUpdate.sql b/db/routines/vn/triggers/travel_beforeUpdate.sql index 093dee082b..6efad4a658 100644 --- a/db/routines/vn/triggers/travel_beforeUpdate.sql +++ b/db/routines/vn/triggers/travel_beforeUpdate.sql @@ -40,9 +40,10 @@ BEGIN IF (NOT(NEW.awbFk <=> OLD.awbFk)) AND NEW.awbFk IS NOT NULL THEN CALL travel_throwAwb(NEW.id); END IF; - + IF NEW.availabled < NEW.landed THEN - CALL util.throw('The travel availabled cannot be earlier than landed'); + SET NEW.availabled = NEW.landed; END IF; + END$$ DELIMITER ; diff --git a/db/routines/vn/views/itemEntryIn.sql b/db/routines/vn/views/itemEntryIn.sql index 5be558a43c..158056b306 100644 --- a/db/routines/vn/views/itemEntryIn.sql +++ b/db/routines/vn/views/itemEntryIn.sql @@ -8,7 +8,7 @@ AS SELECT `t`.`warehouseInFk` AS `warehouseInFk`, `t`.`isReceived` AS `isReceived`, `t`.`isRaid` AS `isVirtualStock`, `e`.`id` AS `entryFk`, - `t`.`availabled` + `t`.`availabled` AS `availabled` FROM ( ( `vn`.`buy` `b` diff --git a/db/versions/11470-blackCamellia/00-firstScript.sql b/db/versions/11470-blackCamellia/00-firstScript.sql new file mode 100644 index 0000000000..f33cfe1194 --- /dev/null +++ b/db/versions/11470-blackCamellia/00-firstScript.sql @@ -0,0 +1,4 @@ +-- Place your SQL code here +UPDATE vn.travel + SET availabled = landed + WHERE availabled IS NULL; \ No newline at end of file diff --git a/db/versions/11470-blackCamellia/01-alterTable.sql b/db/versions/11470-blackCamellia/01-alterTable.sql new file mode 100644 index 0000000000..08ca5a7dcf --- /dev/null +++ b/db/versions/11470-blackCamellia/01-alterTable.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.travel MODIFY COLUMN availabled datetime NOT NULL +COMMENT 'Indicates the moment in time when the goods become available for picking'; \ No newline at end of file