8524-devToTest #3415
|
@ -1,7 +1,7 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_transfer`(
|
||||
vOriginalEntry INT,
|
||||
OUT vNewEntry INT
|
||||
OUT vNewEntryFk INT
|
||||
)
|
||||
BEGIN
|
||||
/**
|
||||
|
@ -10,7 +10,6 @@ BEGIN
|
|||
* @param vOriginalEntry entrada que se quiera adelantar
|
||||
* @param vNewEntry nueva entrada creada
|
||||
*/
|
||||
DECLARE vNewEntryFk INT;
|
||||
DECLARE vTravelFk INT;
|
||||
DECLARE vWarehouseFk INT;
|
||||
DECLARE vWarehouseInFk INT;
|
||||
|
@ -97,7 +96,7 @@ BEGIN
|
|||
WHERE e.id = vOriginalEntry;
|
||||
|
||||
-- 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 (
|
||||
SELECT b.itemFk, SUM(b.quantity) totalQuantity
|
||||
FROM vn.buy b
|
||||
|
@ -105,7 +104,7 @@ BEGIN
|
|||
GROUP BY b.itemFk
|
||||
),
|
||||
itemShelvings AS (
|
||||
SELECT ish.itemFk, SUM(visible) visible
|
||||
SELECT ish.itemFk, SUM(ish.visible) visible
|
||||
FROM vn.itemShelving ish
|
||||
JOIN vn.shelving sh ON sh.id = ish.shelvingFk
|
||||
JOIN vn.parking p ON p.id = sh.parkingFk
|
||||
|
@ -140,20 +139,15 @@ BEGIN
|
|||
OR iss.itemFk IS NULL;
|
||||
|
||||
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
|
||||
WHERE b.entryFk = vNewEntryFk;
|
||||
|
||||
-- Limpia la nueva entrada
|
||||
DELETE b
|
||||
FROM buy b
|
||||
WHERE b.entryFk = vNewEntryFk
|
||||
AND b.quantity = 0;
|
||||
DELETE FROM buy WHERE entryFk = vNewEntryFk AND quantity = 0;
|
||||
|
||||
COMMIT;
|
||||
|
||||
SET vNewEntry = vNewEntryFk;
|
||||
|
||||
CALL cache.visible_refresh(@c,TRUE,vWarehouseFk);
|
||||
CALL cache.available_refresh(@c, TRUE, vWarehouseFk, util.VN_CURDATE());
|
||||
END$$
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
});
|
||||
});
|
|
@ -1,6 +1,6 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('transfer', {
|
||||
description: 'Trasladar la mercancia de una entrada al dia siguiente',
|
||||
description: 'Transfer merchandise from one entry to the next day',
|
||||
accepts: [
|
||||
{
|
||||
arg: 'id',
|
||||
|
|
Loading…
Reference in New Issue