Merge pull request '8069-hotFix-oversTocking' (!3088) from 8069-hotFix-oversTocking into master
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
Reviewed-on: #3088 Reviewed-by: Javi Gallego <jgallego@verdnatura.es>
This commit is contained in:
commit
32c01f22d5
|
@ -0,0 +1,52 @@
|
||||||
|
DELIMITER $$
|
||||||
|
CREATE OR REPLACE DEFINER=`vn`@`localhost`
|
||||||
|
PROCEDURE `hedera`.`orderRow_updateOverstocking`(vOrderFk INT)
|
||||||
|
BEGIN
|
||||||
|
/**
|
||||||
|
* Set amount = 0 to avoid overbooking sales
|
||||||
|
*
|
||||||
|
* @param vOrderFk hedera.order.id
|
||||||
|
*/
|
||||||
|
DECLARE vCalcFk INT;
|
||||||
|
DECLARE vDone BOOL;
|
||||||
|
DECLARE vWarehouseFk INT;
|
||||||
|
|
||||||
|
DECLARE cWarehouses CURSOR FOR
|
||||||
|
SELECT DISTINCT warehouseFk
|
||||||
|
FROM orderRow
|
||||||
|
WHERE orderFk = vOrderFk
|
||||||
|
AND shipment = util.VN_CURDATE();
|
||||||
|
|
||||||
|
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
||||||
|
|
||||||
|
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
||||||
|
BEGIN
|
||||||
|
ROLLBACK;
|
||||||
|
RESIGNAL;
|
||||||
|
END;
|
||||||
|
|
||||||
|
OPEN cWarehouses;
|
||||||
|
checking: LOOP
|
||||||
|
SET vDone = FALSE;
|
||||||
|
|
||||||
|
FETCH cWarehouses INTO vWarehouseFk;
|
||||||
|
|
||||||
|
IF vDone THEN
|
||||||
|
LEAVE checking;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
CALL cache.available_refresh(vCalcFk, FALSE, vWarehouseFk, util.VN_CURDATE());
|
||||||
|
|
||||||
|
UPDATE orderRow r
|
||||||
|
JOIN `order` o ON o.id = r.orderFk
|
||||||
|
JOIN orderConfig oc
|
||||||
|
JOIN cache.available a ON a.calc_id = vCalcFk AND a.item_id = r.itemFk
|
||||||
|
SET r.amount = 0
|
||||||
|
WHERE ADDTIME(o.rowUpdated, oc.reserveTime) < util.VN_NOW()
|
||||||
|
AND a.available <= 0
|
||||||
|
AND r.warehouseFk = vWarehouseFk
|
||||||
|
AND r.orderFk = vOrderFk;
|
||||||
|
END LOOP;
|
||||||
|
CLOSE cWarehouses;
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
|
@ -13,6 +13,7 @@ BEGIN
|
||||||
*/
|
*/
|
||||||
DECLARE vHasRows BOOL;
|
DECLARE vHasRows BOOL;
|
||||||
DECLARE vDone BOOL;
|
DECLARE vDone BOOL;
|
||||||
|
DECLARE vHas0Amount BOOL;
|
||||||
DECLARE vWarehouseFk INT;
|
DECLARE vWarehouseFk INT;
|
||||||
DECLARE vShipment DATE;
|
DECLARE vShipment DATE;
|
||||||
DECLARE vShipmentDayEnd DATETIME;
|
DECLARE vShipmentDayEnd DATETIME;
|
||||||
|
@ -21,7 +22,6 @@ BEGIN
|
||||||
DECLARE vItemFk INT;
|
DECLARE vItemFk INT;
|
||||||
DECLARE vConcept VARCHAR(30);
|
DECLARE vConcept VARCHAR(30);
|
||||||
DECLARE vAmount INT;
|
DECLARE vAmount INT;
|
||||||
DECLARE vAvailable INT;
|
|
||||||
DECLARE vPrice DECIMAL(10,2);
|
DECLARE vPrice DECIMAL(10,2);
|
||||||
DECLARE vSaleFk INT;
|
DECLARE vSaleFk INT;
|
||||||
DECLARE vRowFk INT;
|
DECLARE vRowFk INT;
|
||||||
|
@ -31,7 +31,6 @@ BEGIN
|
||||||
DECLARE vClientFk INT;
|
DECLARE vClientFk INT;
|
||||||
DECLARE vCompanyFk INT;
|
DECLARE vCompanyFk INT;
|
||||||
DECLARE vAgencyModeFk INT;
|
DECLARE vAgencyModeFk INT;
|
||||||
DECLARE vCalcFk INT;
|
|
||||||
DECLARE vIsTaxDataChecked BOOL;
|
DECLARE vIsTaxDataChecked BOOL;
|
||||||
|
|
||||||
DECLARE vDates CURSOR FOR
|
DECLARE vDates CURSOR FOR
|
||||||
|
@ -97,6 +96,20 @@ BEGIN
|
||||||
SELECT employeeFk INTO vUserFk FROM orderConfig;
|
SELECT employeeFk INTO vUserFk FROM orderConfig;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
|
CALL orderRow_updateOverstocking(vSelf);
|
||||||
|
|
||||||
|
-- Check if any product has a quantity of 0
|
||||||
|
SELECT EXISTS (
|
||||||
|
SELECT id
|
||||||
|
FROM orderRow
|
||||||
|
WHERE orderFk = vSelf
|
||||||
|
AND amount = 0
|
||||||
|
) INTO vHas0Amount;
|
||||||
|
|
||||||
|
IF vHas0Amount THEN
|
||||||
|
CALL util.throw('Hay líneas vacías. Por favor, elimínelas');
|
||||||
|
END IF;
|
||||||
|
|
||||||
START TRANSACTION;
|
START TRANSACTION;
|
||||||
|
|
||||||
CALL order_checkEditable(vSelf);
|
CALL order_checkEditable(vSelf);
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
DELIMITER $$
|
||||||
|
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `hedera`.`orderRow_afterInsert`
|
||||||
|
AFTER INSERT ON `orderRow`
|
||||||
|
FOR EACH ROW
|
||||||
|
BEGIN
|
||||||
|
UPDATE `order`
|
||||||
|
SET rowUpdated = util.VN_NOW()
|
||||||
|
WHERE id = NEW.orderFk;
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
|
@ -0,0 +1,3 @@
|
||||||
|
-- Place your SQL code here
|
||||||
|
ALTER TABLE hedera.`order` ADD IF NOT EXISTS rowUpdated DATETIME NULL
|
||||||
|
COMMENT 'Timestamp for last updated record in orderRow table';
|
Loading…
Reference in New Issue