8524-devToTest #3415

Merged
alexm merged 343 commits from 8524-devToTest into test 2025-02-04 13:42:16 +00:00
3 changed files with 36 additions and 12 deletions
Showing only changes of commit 02d77324b1 - Show all commits

View File

@ -1,7 +1,7 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_transfer`( CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_transfer`(
vOriginalEntry INT, vOriginalEntry INT,
OUT vNewEntry INT OUT vNewEntryFk INT
) )
BEGIN BEGIN
/** /**
@ -10,7 +10,6 @@ BEGIN
* @param vOriginalEntry entrada que se quiera adelantar * @param vOriginalEntry entrada que se quiera adelantar
* @param vNewEntry nueva entrada creada * @param vNewEntry nueva entrada creada
*/ */
DECLARE vNewEntryFk INT;
DECLARE vTravelFk INT; DECLARE vTravelFk INT;
DECLARE vWarehouseFk INT; DECLARE vWarehouseFk INT;
DECLARE vWarehouseInFk INT; DECLARE vWarehouseInFk INT;
@ -97,7 +96,7 @@ BEGIN
WHERE e.id = vOriginalEntry; WHERE e.id = vOriginalEntry;
-- Actualizar la nueva entrada con lo que no está ubicado HOY, descontando lo vendido HOY de esas ubicaciones -- Actualizar la nueva entrada con lo que no está ubicado HOY, descontando lo vendido HOY de esas ubicaciones
CREATE OR REPLACE TEMPORARY TABLE tBuy CREATE OR REPLACE TEMPORARY TABLE buys
WITH tBuy AS ( WITH tBuy AS (
SELECT b.itemFk, SUM(b.quantity) totalQuantity SELECT b.itemFk, SUM(b.quantity) totalQuantity
FROM vn.buy b FROM vn.buy b
@ -105,7 +104,7 @@ BEGIN
GROUP BY b.itemFk GROUP BY b.itemFk
), ),
itemShelvings AS ( itemShelvings AS (
SELECT ish.itemFk, SUM(visible) visible SELECT ish.itemFk, SUM(ish.visible) visible
FROM vn.itemShelving ish FROM vn.itemShelving ish
JOIN vn.shelving sh ON sh.id = ish.shelvingFk JOIN vn.shelving sh ON sh.id = ish.shelvingFk
JOIN vn.parking p ON p.id = sh.parkingFk JOIN vn.parking p ON p.id = sh.parkingFk
@ -140,20 +139,15 @@ BEGIN
OR iss.itemFk IS NULL; OR iss.itemFk IS NULL;
UPDATE buy b UPDATE buy b
JOIN tBuy tmp ON tmp.itemFk = b.itemFk JOIN buys tmp ON tmp.itemFk = b.itemFk
SET b.quantity = tmp.totalQuantity - tmp.visible - tmp.sold SET b.quantity = tmp.totalQuantity - tmp.visible - tmp.sold
WHERE b.entryFk = vNewEntryFk; WHERE b.entryFk = vNewEntryFk;
-- Limpia la nueva entrada -- Limpia la nueva entrada
DELETE b DELETE FROM buy WHERE entryFk = vNewEntryFk AND quantity = 0;
FROM buy b
WHERE b.entryFk = vNewEntryFk
AND b.quantity = 0;
COMMIT; COMMIT;
SET vNewEntry = vNewEntryFk;
CALL cache.visible_refresh(@c,TRUE,vWarehouseFk); CALL cache.visible_refresh(@c,TRUE,vWarehouseFk);
CALL cache.available_refresh(@c, TRUE, vWarehouseFk, util.VN_CURDATE()); CALL cache.available_refresh(@c, TRUE, vWarehouseFk, util.VN_CURDATE());
END$$ END$$

View File

@ -0,0 +1,30 @@
const transfer = require('../transfer');
const models = require('vn-loopback/server/server').models;
describe('Transfer merchandise from one entry to the next day()', () => {
const ctx = {req: {accessToken: {userId: 18}}};
it('should Transfer buys not located', async() => {
const id = 3;
const item = 8;
const buy = 6;
const originalEntry = 4;
const tx = await models.ItemShelving.beginTransaction({});
const options = {transaction: tx};
try {
const currentItemShelving = await models.ItemShelving.findOne({where: {id}}, options);
await currentItemShelving.updateAttributes({itemFk: item, buyFk: buy}, options);
const result = await models.Entry.transfer(ctx, originalEntry, options);
const buys = await models.Buy.find({where: {entryFk: result[0].newEntryFk}}, options);
expect(buys.length).toEqual(3);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});

View File

@ -1,6 +1,6 @@
module.exports = Self => { module.exports = Self => {
Self.remoteMethodCtx('transfer', { Self.remoteMethodCtx('transfer', {
description: 'Trasladar la mercancia de una entrada al dia siguiente', description: 'Transfer merchandise from one entry to the next day',
accepts: [ accepts: [
{ {
arg: 'id', arg: 'id',