From decd4b5a9521390a240f8f00272a5ae75b3bd0d1 Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 30 Nov 2021 15:13:20 +0100 Subject: [PATCH] separate sql procedures --- ...onent2.sql => 00-sale_recalcComponent.sql} | 8 ++++--- .../01-sale_calculateComponent.sql | 23 +++++++++++++++++++ .../back/methods/sale/recalculatePrice.js | 2 +- 3 files changed, 29 insertions(+), 4 deletions(-) rename db/changes/10390-constitution/{00-sale_calculateComponent2.sql => 00-sale_recalcComponent.sql} (93%) create mode 100644 db/changes/10390-constitution/01-sale_calculateComponent.sql diff --git a/db/changes/10390-constitution/00-sale_calculateComponent2.sql b/db/changes/10390-constitution/00-sale_recalcComponent.sql similarity index 93% rename from db/changes/10390-constitution/00-sale_calculateComponent2.sql rename to db/changes/10390-constitution/00-sale_recalcComponent.sql index 72a6b9fc1d..c281154701 100644 --- a/db/changes/10390-constitution/00-sale_calculateComponent2.sql +++ b/db/changes/10390-constitution/00-sale_recalcComponent.sql @@ -1,8 +1,8 @@ -DROP PROCEDURE IF EXISTS `vn`.`sale_calculateComponentSalix`; +DROP PROCEDURE IF EXISTS `vn`.`sale_recalcComponent`; DELIMITER $$ $$ -CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`sale_calculateComponentSalix`() +CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`sale_recalcComponent`(vOption INT) proc: BEGIN /** * Actualiza los componentes @@ -103,7 +103,9 @@ proc: BEGIN (PRIMARY KEY (saleFk)) ENGINE = MEMORY SELECT vSale saleFk,vWarehouseFk warehouseFk; - SET vOption = IF(vIsEditable, 1, 6); + IF vOption IS NULL THEN + SET vOption = IF(vIsEditable, 1, 6); + END IF; CALL ticketComponentUpdateSale(vOption); CALL catalog_componentPurge(); diff --git a/db/changes/10390-constitution/01-sale_calculateComponent.sql b/db/changes/10390-constitution/01-sale_calculateComponent.sql new file mode 100644 index 0000000000..97a154362c --- /dev/null +++ b/db/changes/10390-constitution/01-sale_calculateComponent.sql @@ -0,0 +1,23 @@ +DROP PROCEDURE IF EXISTS `vn`.`sale_calculateComponent`; + +DELIMITER $$ +$$ +CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`sale_calculateComponent`(vSale INT, vOption INT) +proc: BEGIN +/** + * Crea tabla temporal para vn.sale_recalcComponent() para recalcular los componentes + * + * @param vSale Id de la venta + * @param vOption indica en que componente pone el descuadre, NULL en casos habituales + */ + DROP TEMPORARY TABLE IF EXISTS tmp.recalculateSales; + CREATE TEMPORARY TABLE tmp.recalculateSales + SELECT s.id + FROM sale s + WHERE s.id = vSale; + + CALL vn.sale_recalcComponent(vOption); + + DROP TEMPORARY TABLE tmp.recalculateSales; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/modules/ticket/back/methods/sale/recalculatePrice.js b/modules/ticket/back/methods/sale/recalculatePrice.js index 7b8a0e1571..7a92ba08b3 100644 --- a/modules/ticket/back/methods/sale/recalculatePrice.js +++ b/modules/ticket/back/methods/sale/recalculatePrice.js @@ -57,7 +57,7 @@ module.exports = Self => { SELECT s.id FROM sale s WHERE s.id IN (${paramsString}); - CALL vn.sale_calculateComponentSalix(); + CALL vn.sale_recalcComponent(null); DROP TEMPORARY TABLE tmp.recalculateSales;`; const recalculation = await Self.rawSql(query, salesIds, myOptions);