Merge pull request '6861_reservas_hotFix' (!2749) from 6861_reservas_hotFix into master
gitea/salix/pipeline/head This commit looks good Details
gitea/salix/pipeline/pr-test This commit looks good Details

Reviewed-on: #2749
Reviewed-by: Carlos Andrés <carlosap@verdnatura.es>
This commit is contained in:
Sergio De la torre 2024-07-17 15:05:18 +00:00
commit 15c5fefc92
9 changed files with 52 additions and 19 deletions

View File

@ -3,7 +3,8 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`collection_addWithR
vItemFk INT,
vQuantity INT,
vTicketFk INT,
vSaleGroupFk INT
vSaleGroupFk INT,
vSectorFk INT
)
BEGIN
/**
@ -67,7 +68,7 @@ BEGIN
SELECT LAST_INSERT_ID() INTO vSaleFk;
CALL sale_calculateComponent(vSaleFk, NULL);
CALL itemShelvingSale_addBySale(vSaleFk);
CALL itemShelvingSale_addBySale(vSaleFk, vSectorFk);
IF NOT EXISTS (SELECT TRUE FROM itemShelvingSale WHERE saleFk = vSaleFk LIMIT 1) THEN
SET vHasThrow = TRUE;

View File

@ -44,7 +44,7 @@ BEGIN
LEAVE l;
END IF;
CALL itemShelvingSale_addBySale(vSaleFk);
CALL itemShelvingSale_addBySale(vSaleFk, NULL);
END LOOP;
CLOSE vSales;
END$$

View File

@ -1,6 +1,7 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_addBySale`(
vSaleFk INT
vSaleFk INT,
vSectorFk INT
)
proc: BEGIN
/**
@ -8,6 +9,7 @@ proc: BEGIN
*
* @param vSaleFk Id de sale
* @param vItemShelvingSaleFk Id de reserva
* @param vSectorFk Id del sector del operator
*/
DECLARE vLastPickingOrder INT;
DECLARE vDone INT DEFAULT FALSE;
@ -30,6 +32,7 @@ proc: BEGIN
JOIN productionConfig pc
WHERE s.id = vSaleFk
AND NOT sc.isHideForPickers
AND (sc.id = vSectorFk OR vSectorFk IS NULL)
ORDER BY s.id,
p.pickingOrder >= vLastPickingOrder,
sh.priority DESC,

View File

@ -10,6 +10,7 @@ BEGIN
*/
DECLARE vDone BOOL DEFAULT FALSE;
DECLARE vSaleFk INT;
DECLARE vSectorFk INT;
DECLARE vSales CURSOR FOR
SELECT s.id
FROM sectorCollectionSaleGroup sc
@ -25,6 +26,10 @@ BEGIN
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
SELECT sectorFk INTO vSectorFk
FROM operator
WHERE workerFk = account.myUser_getId();
OPEN vSales;
l: LOOP
SET vDone = FALSE;
@ -34,7 +39,7 @@ BEGIN
LEAVE l;
END IF;
CALL itemShelvingSale_addBySale(vSaleFk);
CALL itemShelvingSale_addBySale(vSaleFk, vSectorFk);
END LOOP;
CLOSE vSales;
END$$

View File

@ -6,6 +6,7 @@ proc: BEGIN
*/
DECLARE vDone BOOL;
DECLARE vSaleFk INT;
DECLARE vSectorFk INT;
DECLARE vSales CURSOR FOR
SELECT DISTINCT saleFk FROM tSale;
@ -26,24 +27,25 @@ proc: BEGIN
CREATE OR REPLACE TEMPORARY TABLE tSale
ENGINE = MEMORY
SELECT id, saleFk FROM itemShelvingSaleReserve;
SELECT id, saleFk, sectorFk FROM itemShelvingSaleReserve;
OPEN vSales;
myLoop: LOOP
SET vDone = FALSE;
FETCH vSales INTO vSaleFk;
FETCH vSales INTO vSaleFk, vSectorFk;
IF vDone THEN
LEAVE myLoop;
END IF;
CALL itemShelvingSale_addBySale (vSaleFk);
CALL itemShelvingSale_addBySale (vSaleFk, vSectorFk);
END LOOP;
CLOSE vSales;
DELETE iss FROM itemShelvingSaleReserve iss JOIN tSale s ON s.id = iss.id;
DELETE iss FROM itemShelvingSaleReserve iss
JOIN tSale s ON s.id = iss.id AND s.sectorFk = iss.sectorFk;
DROP TEMPORARY TABLE tSale;

View File

@ -1,13 +1,16 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_reallocate`(
vItemShelvingFk INT(10),
vItemFk INT(10)
vItemFk INT(10),
vSectorFk INT
)
BEGIN
/**
* Elimina reservas de un itemShelving e intenta reservar en otra ubicación
*
* @param vItemShelvingFk Id itemShelving
* @param vItemFk Id del artículo
* @param vSectorFk Id del sector
*/
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
@ -28,7 +31,7 @@ BEGIN
WHERE id = vItemShelvingFk
AND itemFk = vItemFk;
INSERT INTO itemShelvingSaleReserve (saleFk)
INSERT INTO itemShelvingSaleReserve (saleFk, vSectorFk)
SELECT DISTINCT iss.saleFk
FROM itemShelvingSale iss
JOIN itemShelving ish ON ish.id = iss.itemShelvingFk

View File

@ -2,7 +2,8 @@ DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_setQuantity`(
vItemShelvingSaleFk INT(10),
vQuantity DECIMAL(10,0),
vIsItemShelvingSaleEmpty BOOLEAN
vIsItemShelvingSaleEmpty BOOLEAN,
vSectorFk INT
)
BEGIN
/**
@ -14,6 +15,7 @@ BEGIN
* @param vQuantity Cantidad real que se ha cogido de la ubicación
* @param vIsItemShelvingSaleEmpty determina si la ubicación itemShelvingSale se ha
* quedado vacio tras el movimiento
* @param vSectorFk Id del sector
*/
DECLARE vSaleFk INT;
DECLARE vItemShelvingFk INT;
@ -72,7 +74,7 @@ BEGIN
SET visible = GREATEST(0, visible - vQuantity)
WHERE id = vItemShelvingFk;
SELECT SUM(IF(isPicked, 0, quantity)), SUM(quantity)
SELECT SUM(IF(isPicked OR id = vItemShelvingSaleFk, 0, quantity)), SUM(quantity)
INTO vRemainingQuantity, vTotalQuantity
FROM itemShelvingSale
WHERE saleFk = vSaleFk;
@ -96,9 +98,9 @@ BEGIN
COMMIT;
IF vIsItemShelvingSaleEmpty AND vQuantity <> vReservedQuantity THEN
INSERT INTO itemShelvingSaleReserve (saleFk)
INSERT INTO itemShelvingSaleReserve (saleFk, vSectorFk)
SELECT vSaleFk;
CALL itemShelvingSale_reallocate(vItemShelvingFk, vItemFk);
CALL itemShelvingSale_reallocate(vItemShelvingFk, vItemFk, vSectorFk);
END IF;
END$$
DELIMITER ;

View File

@ -0,0 +1,11 @@
-- Place your SQL code here
ALTER TABLE IF EXISTS vn.itemShelvingSaleReserve
ADD IF NOT EXISTS sectorFk int(11) NULL;
ALTER TABLE IF EXISTS vn.itemShelvingSaleReserve
DROP FOREIGN KEY IF EXISTS itemShelvingSaleReserve_sector_FK;
ALTER TABLE IF EXISTS vn.itemShelvingSaleReserve
ADD CONSTRAINT itemShelvingSaleReserve_sector_FK FOREIGN KEY (id)
REFERENCES vn.sector(id) ON DELETE RESTRICT ON UPDATE CASCADE;

View File

@ -1,6 +1,6 @@
module.exports = Self => {
Self.remoteMethodCtx('itemShelvingSaleSetQuantity', {
description: 'Set quanitity of a sale in itemShelvingSale',
description: 'Set quantity of a sale in itemShelvingSale',
accessType: 'WRITE',
accepts: [
{
@ -20,6 +20,12 @@ module.exports = Self => {
type: 'boolean',
required: true,
description: 'True if the shelvingFk is empty ',
},
{
arg: 'sectorFk',
type: 'number',
required: true,
description: 'Sector Id',
}
],
http: {
@ -28,14 +34,14 @@ module.exports = Self => {
}
});
Self.itemShelvingSaleSetQuantity = async(ctx, id, quantity, isItemShelvingSaleEmpty, options) => {
Self.itemShelvingSaleSetQuantity = async(ctx, id, quantity, isItemShelvingSaleEmpty, sectorFk, options) => {
const myOptions = {userId: ctx.req.accessToken.userId};
if (typeof options == 'object')
Object.assign(myOptions, options);
await Self.rawSql(`CALL vn.itemShelvingSale_setQuantity(?, ?, ? )`,
[id, quantity, isItemShelvingSaleEmpty],
await Self.rawSql(`CALL vn.itemShelvingSale_setQuantity(?, ?, ?, ?)`,
[id, quantity, isItemShelvingSaleEmpty, sectorFk],
myOptions);
};
};