From 380e0ef651dca7102a880af39c8f389bf94cb9b8 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 12 Feb 2024 08:44:54 +0100 Subject: [PATCH 1/6] refs #2687 fix: clone Travel as user action --- .../01-update_procedure_TravelCloneWithEntries.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/db/versions/10832-purpleAralia/01-update_procedure_TravelCloneWithEntries.sql b/db/versions/10832-purpleAralia/01-update_procedure_TravelCloneWithEntries.sql index b0c177b9a..59041a5b3 100644 --- a/db/versions/10832-purpleAralia/01-update_procedure_TravelCloneWithEntries.sql +++ b/db/versions/10832-purpleAralia/01-update_procedure_TravelCloneWithEntries.sql @@ -27,7 +27,7 @@ BEGIN DECLARE vEvaNotes VARCHAR(255); DECLARE vDone BOOL; DECLARE vAuxEntryFk INT; - DECLARE vTx BOOLEAN DEFAULT !@@in_transaction; + DECLARE vTx BOOLEAN DEFAULT @@in_transaction; DECLARE vRsEntry CURSOR FOR SELECT e.id FROM entry e @@ -41,8 +41,8 @@ BEGIN CALL util.tx_rollback(vTx); RESIGNAL; END; - - CALL util.tx_start(vTx); + + CALL util.tx_start(vTx); INSERT INTO travel (shipped, landed, warehouseInFk, warehouseOutFk, agencyModeFk, `ref`, isDelivered, isReceived, m3, cargoSupplierFk, kg,clonedFrom) SELECT vDateStart, vDateEnd, vWarehouseInFk, vWarehouseOutFk, vAgencyModeFk, vRef, isDelivered, isReceived, m3,cargoSupplierFk, kg,vTravelFk -- 2.40.1 From e79bdb4456d27a2f11805f863bd7521850086a17 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 12 Feb 2024 08:45:07 +0100 Subject: [PATCH 2/6] refs #2687 test: fix --- .../back/methods/travel/specs/cloneWithEntries.spec.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/travel/back/methods/travel/specs/cloneWithEntries.spec.js b/modules/travel/back/methods/travel/specs/cloneWithEntries.spec.js index 74ec10155..950da7bb1 100644 --- a/modules/travel/back/methods/travel/specs/cloneWithEntries.spec.js +++ b/modules/travel/back/methods/travel/specs/cloneWithEntries.spec.js @@ -27,7 +27,10 @@ describe('Travel cloneWithEntries()', () => { expect(newTravel.warehouseOutFk).toEqual(warehouseThree); expect(newTravel.agencyModeFk).toEqual(agencyModeOne); expect(travelEntries.length).toBeGreaterThan(0); - + await models.Entry.destroyAll({ + travelFk: newTravelId + }, options); + await models.Travel.destroyById(newTravelId, options); await tx.rollback(); const travelRemoved = await models.Travel.findById(newTravelId, options); -- 2.40.1 From b9a624d9cd8b863d1073800767a389d6d7595c1c Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 14 Feb 2024 08:45:50 +0100 Subject: [PATCH 3/6] refs #2687 feat: create util.procedures --- db/routines/util/procedures/tx_commit.sql | 15 +++++++++ db/routines/util/procedures/tx_rollback.sql | 15 +++++++++ db/routines/util/procedures/tx_start.sql | 17 ++++++++++ .../vn/procedures/travel_cloneWithEntries.sql | 32 +++++++++---------- modules/route/front/create/index.html | 1 + 5 files changed, 64 insertions(+), 16 deletions(-) create mode 100644 db/routines/util/procedures/tx_commit.sql create mode 100644 db/routines/util/procedures/tx_rollback.sql create mode 100644 db/routines/util/procedures/tx_start.sql diff --git a/db/routines/util/procedures/tx_commit.sql b/db/routines/util/procedures/tx_commit.sql new file mode 100644 index 000000000..11be92c2e --- /dev/null +++ b/db/routines/util/procedures/tx_commit.sql @@ -0,0 +1,15 @@ +DELIMITER $$ +$$ + +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`tx_commit`(IN tx BOOL) +BEGIN +/** + * Procedimiento para confirmar los cambios asociados a una transacción + * + * @param tx BOOL es true si existe transacción asociada +*/ + IF tx THEN + COMMIT; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/util/procedures/tx_rollback.sql b/db/routines/util/procedures/tx_rollback.sql new file mode 100644 index 000000000..b6ac2cd12 --- /dev/null +++ b/db/routines/util/procedures/tx_rollback.sql @@ -0,0 +1,15 @@ +DELIMITER $$ +$$ + +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`tx_rollback`(tx BOOL) +BEGIN +/** + * Procedimiento para deshacer los cambios asociados a una transacción + * + * @param tx BOOL es true si existe transacción asociada +*/ + IF tx THEN + ROLLBACK; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/util/procedures/tx_start.sql b/db/routines/util/procedures/tx_start.sql new file mode 100644 index 000000000..6e513790b --- /dev/null +++ b/db/routines/util/procedures/tx_start.sql @@ -0,0 +1,17 @@ + + +DELIMITER $$ +$$ + +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`tx_start`(tx BOOL) +BEGIN +/** + * Procedimiento para iniciar una transacción + * + * @param tx BOOL es true si existe transacción asociada +*/ + IF tx THEN + START TRANSACTION; + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/travel_cloneWithEntries.sql b/db/routines/vn/procedures/travel_cloneWithEntries.sql index 840152c44..7cf9ee5ef 100644 --- a/db/routines/vn/procedures/travel_cloneWithEntries.sql +++ b/db/routines/vn/procedures/travel_cloneWithEntries.sql @@ -1,21 +1,20 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`travel_cloneWithEntries`( - IN vTravelFk INT, - IN vDateStart DATE, + IN vTravelFk INT, + IN vDateStart DATE, IN vDateEnd DATE, IN vWarehouseOutFk INT, - IN vWarehouseInFk INT, - IN vRef VARCHAR(255), - IN vAgencyModeFk INT, + IN vWarehouseInFk INT, + IN vRef VARCHAR(255), + IN vAgencyModeFk INT, OUT vNewTravelFk INT) BEGIN /** * Clona un travel junto con sus entradas y compras - * * @param vTravelFk travel plantilla a clonar * @param vDateStart fecha del shipment del nuevo travel * @param vDateEnd fecha del landing del nuevo travel - * @param vWarehouseOutFk fecha del salida del nuevo travel + * @param vWarehouseOutFk warehouse del salida del nuevo travel * @param vWarehouseInFk warehouse de landing del nuevo travel * @param vRef referencia del nuevo travel * @param vAgencyModeFk del nuevo travel @@ -25,34 +24,35 @@ BEGIN DECLARE vEvaNotes VARCHAR(255); DECLARE vDone BOOL; DECLARE vAuxEntryFk INT; + DECLARE vTx BOOLEAN DEFAULT @@in_transaction; DECLARE vRsEntry CURSOR FOR SELECT e.id FROM entry e JOIN travel t ON t.id = e.travelFk WHERE e.travelFk = vTravelFk; - + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN - ROLLBACK; + BEGIN + CALL util.tx_rollback(vTx); RESIGNAL; END; - - START TRANSACTION; + + CALL util.tx_start(vTx); INSERT INTO travel (shipped, landed, warehouseInFk, warehouseOutFk, agencyModeFk, `ref`, isDelivered, isReceived, m3, cargoSupplierFk, kg,clonedFrom) SELECT vDateStart, vDateEnd, vWarehouseInFk, vWarehouseOutFk, vAgencyModeFk, vRef, isDelivered, isReceived, m3,cargoSupplierFk, kg,vTravelFk FROM travel WHERE id = vTravelFk; - + SET vNewTravelFk = LAST_INSERT_ID(); SET vDone = FALSE; SET @isModeInventory = TRUE; OPEN vRsEntry; - + l: LOOP SET vDone = FALSE; FETCH vRsEntry INTO vAuxEntryFk; @@ -62,7 +62,7 @@ BEGIN END IF; CALL entry_cloneHeader(vAuxEntryFk, vNewEntryFk, vNewTravelFk); - CALL entry_copyBuys(vAuxEntryFk, vNewEntryFk); + CALL entry_copyBuys(vAuxEntryFk, vNewEntryFk); SELECT evaNotes INTO vEvaNotes FROM entry @@ -76,6 +76,6 @@ BEGIN SET @isModeInventory = FALSE; CLOSE vRsEntry; - COMMIT; + CALL util.tx_commit(vTx); END$$ DELIMITER ; diff --git a/modules/route/front/create/index.html b/modules/route/front/create/index.html index de341220e..b76878f2e 100644 --- a/modules/route/front/create/index.html +++ b/modules/route/front/create/index.html @@ -22,6 +22,7 @@ label="Vehicle" ng-model="$ctrl.route.vehicleFk" url="Vehicles" + where="{warehouseFk: $ctrl.vnConfig.warehouseFk}" show-field="numberPlate"> Date: Wed, 14 Feb 2024 09:32:44 +0100 Subject: [PATCH 4/6] refs #2687 feat: comments --- db/routines/util/procedures/tx_commit.sql | 2 -- db/routines/util/procedures/tx_rollback.sql | 2 -- db/routines/util/procedures/tx_start.sql | 2 -- 3 files changed, 6 deletions(-) diff --git a/db/routines/util/procedures/tx_commit.sql b/db/routines/util/procedures/tx_commit.sql index 11be92c2e..121c3803b 100644 --- a/db/routines/util/procedures/tx_commit.sql +++ b/db/routines/util/procedures/tx_commit.sql @@ -1,6 +1,4 @@ DELIMITER $$ -$$ - CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`tx_commit`(IN tx BOOL) BEGIN /** diff --git a/db/routines/util/procedures/tx_rollback.sql b/db/routines/util/procedures/tx_rollback.sql index b6ac2cd12..b9e7224e1 100644 --- a/db/routines/util/procedures/tx_rollback.sql +++ b/db/routines/util/procedures/tx_rollback.sql @@ -1,6 +1,4 @@ DELIMITER $$ -$$ - CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`tx_rollback`(tx BOOL) BEGIN /** diff --git a/db/routines/util/procedures/tx_start.sql b/db/routines/util/procedures/tx_start.sql index 6e513790b..3cce946fa 100644 --- a/db/routines/util/procedures/tx_start.sql +++ b/db/routines/util/procedures/tx_start.sql @@ -1,8 +1,6 @@ DELIMITER $$ -$$ - CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`tx_start`(tx BOOL) BEGIN /** -- 2.40.1 From 3ff3c812ed2cd5ee4ec02b7f98d7cf49a09cd8b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Segarra=20Mart=C3=ADnez?= Date: Wed, 14 Feb 2024 20:15:34 +0100 Subject: [PATCH 5/6] refs #2687 fix: remove bad changes file --- modules/route/front/create/index.html | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/route/front/create/index.html b/modules/route/front/create/index.html index b76878f2e..de341220e 100644 --- a/modules/route/front/create/index.html +++ b/modules/route/front/create/index.html @@ -22,7 +22,6 @@ label="Vehicle" ng-model="$ctrl.route.vehicleFk" url="Vehicles" - where="{warehouseFk: $ctrl.vnConfig.warehouseFk}" show-field="numberPlate"> Date: Thu, 15 Feb 2024 07:49:57 +0100 Subject: [PATCH 6/6] refs #2687 feat: comments --- db/routines/util/procedures/tx_commit.sql | 8 ++++---- db/routines/util/procedures/tx_rollback.sql | 8 ++++---- db/routines/util/procedures/tx_start.sql | 10 ++++------ 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/db/routines/util/procedures/tx_commit.sql b/db/routines/util/procedures/tx_commit.sql index 121c3803b..fdf2f3ddb 100644 --- a/db/routines/util/procedures/tx_commit.sql +++ b/db/routines/util/procedures/tx_commit.sql @@ -1,12 +1,12 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`tx_commit`(IN tx BOOL) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`tx_commit`(isTx BOOL) BEGIN /** - * Procedimiento para confirmar los cambios asociados a una transacción + * Confirma los cambios asociados a una transacción. * - * @param tx BOOL es true si existe transacción asociada + * @param isTx es true si existe transacción asociada */ - IF tx THEN + IF isTx THEN COMMIT; END IF; END$$ diff --git a/db/routines/util/procedures/tx_rollback.sql b/db/routines/util/procedures/tx_rollback.sql index b9e7224e1..96571af2c 100644 --- a/db/routines/util/procedures/tx_rollback.sql +++ b/db/routines/util/procedures/tx_rollback.sql @@ -1,12 +1,12 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`tx_rollback`(tx BOOL) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`tx_rollback`(isTx BOOL) BEGIN /** - * Procedimiento para deshacer los cambios asociados a una transacción + * Deshace los cambios asociados a una transacción. * - * @param tx BOOL es true si existe transacción asociada + * @param isTx es true si existe transacción asociada */ - IF tx THEN + IF isTx THEN ROLLBACK; END IF; END$$ diff --git a/db/routines/util/procedures/tx_start.sql b/db/routines/util/procedures/tx_start.sql index 3cce946fa..9d9f16bb7 100644 --- a/db/routines/util/procedures/tx_start.sql +++ b/db/routines/util/procedures/tx_start.sql @@ -1,14 +1,12 @@ - - DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`tx_start`(tx BOOL) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`tx_start`(isTx BOOL) BEGIN /** - * Procedimiento para iniciar una transacción + * Inicia una transacción. * - * @param tx BOOL es true si existe transacción asociada + * @param isTx es true si existe transacción asociada */ - IF tx THEN + IF isTx THEN START TRANSACTION; END IF; END$$ -- 2.40.1