Merge pull request 'fix: refs #7931 Merge available fix into master' (!2936) from test into master
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #2936
Reviewed-by: Pako Natek <pako@verdnatura.es>
This commit is contained in:
Juan Ferrer 2024-09-09 10:20:42 +00:00
commit d2ead9d936
5 changed files with 69 additions and 7 deletions

View File

@ -1,5 +1,10 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `cache`.`available_refresh`(OUT `vCalc` INT, IN `vRefresh` INT, IN `vWarehouse` INT, IN `vDated` DATE) CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `cache`.`available_refresh`(
OUT `vCalc` INT,
`vRefresh` INT,
`vWarehouse` INT,
`vDated` DATE
)
proc: BEGIN proc: BEGIN
DECLARE vStartDate DATE; DECLARE vStartDate DATE;
DECLARE vReserveDate DATETIME; DECLARE vReserveDate DATETIME;

View File

@ -0,0 +1,31 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `cache`.`available_updateItem`(
`vItem` INT,
`vWarehouse` INT,
`vDated` DATE,
`vQuantity` INT
)
BEGIN
/**
* Immediately deduct/add an amount from the available cache (if exists).
*
* @param vItem The item id
* @param vWarehouse The warehouse id
* @param vDated Available cache date
* @param vQuantity The amount to be deducted from the cache
*/
DECLARE vCalc INT;
SELECT id INTO vCalc
FROM cache_calc
WHERE cacheName = 'available'
AND params = CONCAT_WS('/', vWarehouse, vDated);
IF vCalc IS NOT NULL THEN
UPDATE available
SET available = available - vQuantity
WHERE calc_id = vCalc
AND item_id = vItem;
END IF;
END$$
DELIMITER ;

View File

@ -47,11 +47,15 @@ BEGIN
FROM tmp.zoneGetShipped FROM tmp.zoneGetShipped
WHERE warehouseFk = vWarehouse; WHERE warehouseFk = vWarehouse;
SELECT IFNULL(available, 0) INTO vAvailable SELECT available INTO vAvailable
FROM tmp.ticketLot FROM tmp.ticketLot
WHERE warehouseFk = vWarehouse WHERE warehouseFk = vWarehouse
AND itemFk = vItem; AND itemFk = vItem;
IF vAvailable IS NULL THEN
SET vAvailable = 0;
END IF;
IF vAmount > vAvailable THEN IF vAmount > vAvailable THEN
CALL util.throw ('ORDER_ROW_UNAVAILABLE'); CALL util.throw ('ORDER_ROW_UNAVAILABLE');
END IF; END IF;
@ -102,6 +106,8 @@ BEGIN
amount = vAdd, amount = vAdd,
price = vPrice; price = vPrice;
CALL cache.available_updateItem(vItem, vWarehouse, vShipment, vAdd);
SET vRow = LAST_INSERT_ID(); SET vRow = LAST_INSERT_ID();
INSERT INTO orderRowComponent (rowFk, componentFk, price) INSERT INTO orderRowComponent (rowFk, componentFk, price)

View File

@ -0,0 +1,19 @@
INSERT INTO hedera.message (code,description)
VALUES ('ORDER_ROW_UNAVAILABLE','The ordered quantity exceeds the available');
INSERT INTO hedera.message (code,description)
VALUES ('AMOUNT_NOT_MATCH_GROUPING','The quantity ordered does not match the grouping');
INSERT INTO hedera.messageI18n (code,lang,description)
VALUES ('ORDER_ROW_UNAVAILABLE','es','La cantidad pedida excede el disponible');
INSERT INTO hedera.messageI18n (code,lang,description)
VALUES ('AMOUNT_NOT_MATCH_GROUPING','es','La cantidad pedida no coincide con el agrupado');
INSERT INTO hedera.messageI18n (code,lang,description)
VALUES ('ORDER_ROW_UNAVAILABLE','fr','La quantité demandée dépasse ce qui est disponible');
INSERT INTO hedera.messageI18n (code,lang,description)
VALUES ('AMOUNT_NOT_MATCH_GROUPING','fr','La quantité commandée ne correspond pas au regroupement');
INSERT INTO hedera.messageI18n (code,lang,description)
VALUES ('ORDER_ROW_UNAVAILABLE','pt','A quantidade de entrega excede a disponibilidade');
INSERT INTO hedera.messageI18n (code,lang,description)
VALUES ('AMOUNT_NOT_MATCH_GROUPING','pt','A quantidade solicitada não corresponde ao agrupamento');

View File

@ -1,7 +1,7 @@
const models = require('vn-loopback/server/server').models; const models = require('vn-loopback/server/server').models;
describe('item getVisibleAvailable()', () => { describe('item getVisibleAvailable()', () => {
it('should check available visible for today', async() => { it('should check available visible for tomorrow', async() => {
const tx = await models.Item.beginTransaction({}); const tx = await models.Item.beginTransaction({});
const options = {transaction: tx}; const options = {transaction: tx};
@ -9,6 +9,7 @@ describe('item getVisibleAvailable()', () => {
const itemFk = 1; const itemFk = 1;
const warehouseFk = 1; const warehouseFk = 1;
const dated = Date.vnNew(); const dated = Date.vnNew();
dated.setDate(dated.getDate() + 1);
const result = await models.Item.getVisibleAvailable(itemFk, warehouseFk, dated, options); const result = await models.Item.getVisibleAvailable(itemFk, warehouseFk, dated, options);