Merge branch 'master' into test
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Guillermo Bonet 2024-07-08 07:54:42 +02:00
commit 5213fd4feb
3 changed files with 55 additions and 65 deletions

View File

@ -40,8 +40,7 @@ proc: BEGIN
(PRIMARY KEY (itemFk))
ENGINE = MEMORY
SELECT itemFk,
SUM(quantity) quantity,
SUM(quantity) visible
SUM(quantity) quantity
FROM (
SELECT s.itemFk, - s.quantity quantity
FROM sale s
@ -75,56 +74,59 @@ proc: BEGIN
) sub
GROUP BY itemFk;
-- Cálculo del visible
UPDATE tItemInventoryCalc iic
JOIN (
SELECT itemFk, SUM(quantity) visible
FROM (
SELECT s.itemFk, s.quantity
FROM sale s
JOIN ticket t ON t.id = s.ticketFk
JOIN warehouse w ON w.id = t.warehouseFk
WHERE t.shipped >= vDate
AND t.shipped < vDateTomorrow
AND (NOT isPicked AND NOT t.isLabeled AND t.refFk IS NULL)
AND IFNULL(vWarehouseFk, t.warehouseFk) = t.warehouseFk
AND w.isComparative
UNION ALL
SELECT b.itemFk, - b.quantity
FROM buy b
JOIN entry e ON e.id = b.entryFk
JOIN travel t ON t.id = e.travelFk
JOIN warehouse w ON w.id = t.warehouseInFk
WHERE t.landed = vDate
AND NOT t.isReceived
AND NOT e.isExcludedFromAvailable
AND NOT e.isRaid
AND IFNULL(vWarehouseFk, t.warehouseInFk) = t.warehouseInFk
AND w.isComparative
UNION ALL
SELECT b.itemFk, b.quantity
FROM buy b
JOIN entry e ON e.id = b.entryFk
JOIN travel t ON t.id = e.travelFk
JOIN warehouse w ON w.id = t.warehouseOutFk
WHERE t.shipped = vDate
AND NOT t.isReceived
AND NOT e.isExcludedFromAvailable
AND NOT e.isRaid
AND IFNULL(vWarehouseFk, t.warehouseOutFk) = t.warehouseOutFk
AND w.isComparative
) sub2
GROUP BY itemFk
) sub ON sub.itemFk = iic.itemFk
SET iic.visible = iic.visible + sub.visible;
UPDATE tmp.itemInventory ai
JOIN tItemInventoryCalc iic ON iic.itemFk = ai.id
SET ai.inventory = iic.quantity,
ai.visible = iic.visible,
ai.visible = iic.quantity,
ai.avalaible = iic.quantity,
ai.sd = iic.quantity;
-- Cálculo del visible
CREATE OR REPLACE TEMPORARY TABLE tItemVisibleCalc
(PRIMARY KEY (itemFk))
ENGINE = MEMORY
SELECT itemFk, SUM(quantity) visible
FROM (
SELECT s.itemFk, s.quantity
FROM sale s
JOIN ticket t ON t.id = s.ticketFk
JOIN warehouse w ON w.id = t.warehouseFk
WHERE t.shipped >= vDate
AND t.shipped < vDateTomorrow
AND (NOT isPicked AND NOT t.isLabeled AND t.refFk IS NULL)
AND IFNULL(vWarehouseFk, t.warehouseFk) = t.warehouseFk
AND w.isComparative
UNION ALL
SELECT b.itemFk, - b.quantity
FROM buy b
JOIN entry e ON e.id = b.entryFk
JOIN travel t ON t.id = e.travelFk
JOIN warehouse w ON w.id = t.warehouseInFk
WHERE t.landed = vDate
AND NOT t.isReceived
AND NOT e.isExcludedFromAvailable
AND NOT e.isRaid
AND IFNULL(vWarehouseFk, t.warehouseInFk) = t.warehouseInFk
AND w.isComparative
UNION ALL
SELECT b.itemFk, b.quantity
FROM buy b
JOIN entry e ON e.id = b.entryFk
JOIN travel t ON t.id = e.travelFk
JOIN warehouse w ON w.id = t.warehouseOutFk
WHERE t.shipped = vDate
AND NOT t.isReceived
AND NOT e.isExcludedFromAvailable
AND NOT e.isRaid
AND IFNULL(vWarehouseFk, t.warehouseOutFk) = t.warehouseOutFk
AND w.isComparative
) sub2
GROUP BY itemFk;
UPDATE tmp.itemInventory ai
JOIN tItemVisibleCalc ivc ON ivc.itemFk = ai.id
SET ai.visible = ai.visible + ivc.visible;
-- Calculo del disponible
CREATE OR REPLACE TEMPORARY TABLE tmp.itemCalc
(INDEX (itemFk, warehouseFk))
@ -195,6 +197,7 @@ proc: BEGIN
tmp.itemTravel,
tmp.itemCalc,
tItemInventoryCalc,
tItemVisibleCalc,
tmp.itemAtp;
END$$
DELIMITER ;

View File

@ -63,7 +63,7 @@ module.exports = Self => {
FROM tItemShelving ti
JOIN tItemInSector tis ON tis.itemFk = ti.itemFk
JOIN vn.productionConfig pc
WHERE ti.created > tis.created + INTERVAL pc.itemOlderReviewHours HOUR;`,
WHERE ti.created + INTERVAL pc.itemOlderReviewHours HOUR < tis.created ;`,
[shelvingFk, shelvingFk], myOptions);
return result;
};

View File

@ -3,29 +3,16 @@ const {models} = require('vn-loopback/server/server');
describe('itemShelving getListItemNewer()', () => {
it('should return true because there is an older item', async() => {
const shelving = 'NCC';
const parking = 'A-47-1';
const shelving = 'NBB';
const parking = '700-01';
const sectorCamHighCode = 'CAMARA SECTOR D';
const sectorCamCode = 'NAVE ALGEMESI';
const sectorCamCodeHighId = 1;
const sectorCamCodeId = 9991;
const sectorCamHighCode = 'FIRST';
const sectorCamCode = 'NS';
const tx = await models.Sector.beginTransaction({});
const myOptions = {transaction: tx};
try {
const sectorHighCam = await models.Sector.findById(sectorCamCodeHighId, null, myOptions);
await sectorHighCam.updateAttributes({
code: sectorCamHighCode
});
const sectorCam = await models.Sector.findById(sectorCamCodeId, null, myOptions);
await sectorCam.updateAttributes({
code: sectorCamCode
});
const config = await models.ProductionConfig.findOne();
await config.updateAttributes({
@ -35,7 +22,7 @@ describe('itemShelving getListItemNewer()', () => {
const result = await models.ItemShelving.getListItemNewer(shelving, parking, myOptions);
expect(result.length).toEqual(2);
expect(result.length).toEqual(3);
await tx.rollback();
} catch (e) {
await tx.rollback();