fix: refs #7931 Immediately discount order lines from available #2925
|
@ -1,5 +1,10 @@
|
|||
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
|
||||
DECLARE vStartDate DATE;
|
||||
DECLARE vReserveDate DATETIME;
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `cache`.`available_updateItem`(
|
||||
`vItem` INT,
|
||||
`vWarehouse` INT,
|
||||
`vDated` DATE,
|
||||
`vQuantity` INT
|
||||
)
|
||||
juan marked this conversation as resolved
|
||||
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;
|
||||
|
||||
juan marked this conversation as resolved
carlosap
commented
per evitar els negatius ,es pot ficar una funció GREATEST(0, available - vQuantity) per evitar els negatius ,es pot ficar una funció GREATEST(0, available - vQuantity)
juan
commented
No lo veo, el procedimiento también puede que se utilice para sumar algo a la cache, ademas de esa forma se estan actualizando los parámetros de entrada de forma oculta para el "llamante" del procedimiento. No lo veo, el procedimiento también puede que se utilice para sumar algo a la cache, ademas de esa forma se estan actualizando los parámetros de entrada de forma oculta para el "llamante" del procedimiento.
|
||||
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 ;
|
|
@ -1,8 +1,8 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `hedera`.`order_addItem`(
|
||||
vSelf INT,
|
||||
vWarehouse INT,
|
||||
vItem INT,
|
||||
vWarehouse INT,
|
||||
vItem INT,
|
||||
vAmount INT)
|
||||
BEGIN
|
||||
/**
|
||||
|
@ -37,7 +37,7 @@ BEGIN
|
|||
ROLLBACK;
|
||||
RESIGNAL;
|
||||
END;
|
||||
|
||||
|
||||
CALL order_calcCatalogFromItem(vSelf, vItem);
|
||||
START TRANSACTION;
|
||||
|
||||
|
@ -102,6 +102,8 @@ BEGIN
|
|||
amount = vAdd,
|
||||
price = vPrice;
|
||||
|
||||
CALL cache.available_updateItem(vItem, vWarehouse, vShipment, vAdd);
|
||||
|
||||
SET vRow = LAST_INSERT_ID();
|
||||
|
||||
INSERT INTO orderRowComponent (rowFk, componentFk, price)
|
||||
|
@ -121,6 +123,6 @@ BEGIN
|
|||
END IF;
|
||||
|
||||
COMMIT;
|
||||
CALL vn.ticketCalculatePurge;
|
||||
CALL vn.ticketCalculatePurge;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
|
||||
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 options = {transaction: tx};
|
||||
|
||||
|
@ -9,6 +9,7 @@ describe('item getVisibleAvailable()', () => {
|
|||
const itemFk = 1;
|
||||
const warehouseFk = 1;
|
||||
const dated = Date.vnNew();
|
||||
dated.setDate(dated.getDate() + 1);
|
||||
|
||||
const result = await models.Item.getVisibleAvailable(itemFk, warehouseFk, dated, options);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
comentaris
Comentarios añadidos