From 5db8ae53acb4c2e751acacc1576e78111886f84d Mon Sep 17 00:00:00 2001 From: sergiodt Date: Thu, 5 Dec 2024 12:39:20 +0100 Subject: [PATCH 1/4] feat: refs #8188 refs#8188 orderPicking --- back/models/production-config.json | 3 + db/dump/fixtures.before.sql | 3 +- .../11377-pinkCarnation/00-firstScript.sql | 4 + .../item-shelving/getItemsByReviewOrder.js | 79 +++++++++++ .../specs/getItemsByReviewOrder.spec.js | 123 ++++++++++++++++++ modules/item/back/models/item-shelving.js | 1 + 6 files changed, 212 insertions(+), 1 deletion(-) create mode 100644 db/versions/11377-pinkCarnation/00-firstScript.sql create mode 100644 modules/item/back/methods/item-shelving/getItemsByReviewOrder.js create mode 100644 modules/item/back/methods/item-shelving/specs/getItemsByReviewOrder.spec.js diff --git a/back/models/production-config.json b/back/models/production-config.json index 2fc6d71ff..048264e8c 100644 --- a/back/models/production-config.json +++ b/back/models/production-config.json @@ -20,6 +20,9 @@ }, "backupPrinterNotificationDelay": { "type": "string" + }, + "itemOrderReviewHours": { + "type": "number" } } } \ No newline at end of file diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index eb3ae97ef..663705ff5 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -3772,7 +3772,8 @@ VALUES (999992, 18, 50, '2023-09-21', NULL, 1, NULL, 103, NULL), (1000000, 18, 25, '2023-09-21', 25, 500, NULL, 103, NULL), (999996, 19, 5, '2023-09-27', 1, 5, NULL, 103, NULL), - (999997, 21, 10, '2023-09-27', 5, 100, NULL, 103, NULL); + (999997, 21, 10, '2023-09-27', 5, 100, NULL, 103, NULL), + (1000000, 16, 25, '2023-08-21',25, 500, NULL, NULL, NULL); -- Previous for Bolas de madera INSERT IGNORE INTO vn.sectorCollection diff --git a/db/versions/11377-pinkCarnation/00-firstScript.sql b/db/versions/11377-pinkCarnation/00-firstScript.sql new file mode 100644 index 000000000..0082a744d --- /dev/null +++ b/db/versions/11377-pinkCarnation/00-firstScript.sql @@ -0,0 +1,4 @@ +-- Place your SQL code here + + +ALTER TABLE vn.productionConfig ADD itemOrderReviewHours int(11) DEFAULT 24 NULL COMMENT 'Horas que se tienen cuen cuenta para comprobar orden en el almacén, null para desactivar revisión'; diff --git a/modules/item/back/methods/item-shelving/getItemsByReviewOrder.js b/modules/item/back/methods/item-shelving/getItemsByReviewOrder.js new file mode 100644 index 000000000..96a3c9969 --- /dev/null +++ b/modules/item/back/methods/item-shelving/getItemsByReviewOrder.js @@ -0,0 +1,79 @@ +module.exports = Self => { + const models = require('vn-loopback/server/server').models; + Self.remoteMethod('getItemsByReviewOrder', { + description: + 'Get list items if they are ordered by pickingOrder and their created regarding where they will be parked', + accessType: 'READ', + accepts: [{ + arg: 'shelving', + type: 'string', + required: true, + description: 'Shelving code' + }, + { + arg: 'parking', + type: 'string', + required: true, + description: 'Parking code' + }, + { + arg: 'itemFk', + type: 'number', + description: 'Item id' + }, + ], + returns: { + type: 'Array', + root: true + }, + http: { + path: `/getItemsByReviewOrder`, + verb: 'GET' + } + }); + + Self.getItemsByReviewOrder = async(shelving, parking, itemFk, options) => { + const myOptions = {}; + if (typeof options == 'object') + Object.assign(myOptions, options); + + const config = await models.ProductionConfig.findOne(); + const hoursToCompare = config['itemOrderReviewHours']; + if (!hoursToCompare) return []; + + const parkingItem = await models.Parking.findOne({where: {code: parking}}, myOptions); + if (!parkingItem) return []; + const pickingOrderToCompare = parkingItem['pickingOrder']; + + const result = await Self.rawSql(` + WITH currentItemShelving AS( + SELECT is2.created + INTERVAL ? HOUR created, is2.itemFk, sh.code + FROM vn.itemShelving is2 + JOIN vn.shelving sh ON sh.id = is2.shelvingFk + LEFT JOIN vn.parking p ON p.id = sh.parkingFk + LEFT JOIN vn.sector s ON s.id = p.sectorFk + WHERE sh.code = ? AND (? IS NULL OR is2.itemFk = ?) + ) + ,itemShelvings AS ( + SELECT is2.itemFk, is2.created, sh.code, p.pickingOrder,p.code parkingFk + FROM vn.itemShelving is2 + JOIN currentItemShelving ai ON is2.itemfk = ai.itemFk + JOIN vn.shelving sh ON sh.id = is2.shelvingFk AND ai.code <> sh.code + JOIN vn.parking p ON p.id = sh.parkingFk + JOIN vn.sector s ON s.id = p.sectorFk) + ,parkingDestiny AS ( + SELECT ? pickingOrder) + SELECT ish.*, + CASE + WHEN ish.pickingOrder < d.pickingOrder AND aish.created < ish.created THEN "new" + WHEN ish.pickingOrder > d.pickingOrder AND aish.created > ish.created THEN "old" + END AS itemCreated + FROM itemShelvings ish + JOIN parkingDestiny d + JOIN currentItemShelving aish + WHERE ish.pickingOrder < d.pickingOrder AND aish.created < ish.created OR + ish.pickingOrder > d.pickingOrder AND aish.created > ish.created;`, + [hoursToCompare, shelving, itemFk, itemFk, pickingOrderToCompare], myOptions); + return result; + }; +}; diff --git a/modules/item/back/methods/item-shelving/specs/getItemsByReviewOrder.spec.js b/modules/item/back/methods/item-shelving/specs/getItemsByReviewOrder.spec.js new file mode 100644 index 000000000..c16e155c9 --- /dev/null +++ b/modules/item/back/methods/item-shelving/specs/getItemsByReviewOrder.spec.js @@ -0,0 +1,123 @@ + +const {models} = require('vn-loopback/server/server'); + +describe('itemShelving getItemsByReviewOrder()', () => { + fit('should return empty because hoursToReview = 0', async() => { + const shelving = 'NBB'; + const parking = '700-01'; + + const tx = await models.Sector.beginTransaction({}); + const myOptions = {transaction: tx}; + + try { + const config = await models.ProductionConfig.findOne(); + await config.updateAttributes({ + itemOrderReviewHours: null, + }); + + const result = await models.ItemShelving.getItemsByReviewOrder(shelving, parking, myOptions); + + expect(result.length).toEqual(0); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + fit('should return an item because you are trying parking a shelving and there is an older item', async() => { + const shelving = 'NBB'; + const parking = 'K-26-2'; + const itemFk = 1000000; + + const tx = await models.Sector.beginTransaction({}); + const myOptions = {transaction: tx}; + + try { + const config = await models.ProductionConfig.findOne(); + await config.updateAttributes({ + itemOrderReviewHours: 24, + }); + + const result = await models.ItemShelving.getItemsByReviewOrder(shelving, parking, itemFk, myOptions); + + expect(result.length).toEqual(1); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + fit('should return an item because you are trying parking a shelving and there is an newer item', async() => { + const shelving = 'NBB'; + const parking = 'K-26-2'; + const itemFk = 1000000; + + const tx = await models.Sector.beginTransaction({}); + const myOptions = {transaction: tx}; + + try { + const config = await models.ProductionConfig.findOne(); + await config.updateAttributes({ + itemOrderReviewHours: 24, + }); + + const result = await models.ItemShelving.getItemsByReviewOrder(shelving, parking, itemFk, myOptions); + + expect(result.length).toEqual(1); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + fit('should return a item list because you are trying parking a shelving and there is an newer item', async() => { + const shelving = 'NCC'; + const parking = 'K-26-2'; + const itemFk = 1000000; + + const tx = await models.Sector.beginTransaction({}); + const myOptions = {transaction: tx}; + + try { + const config = await models.ProductionConfig.findOne(); + await config.updateAttributes({ + itemOrderReviewHours: 24, + }); + + const result = await models.ItemShelving.getItemsByReviewOrder(shelving, parking, itemFk, myOptions); + + expect(result.length).toEqual(2); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + fit('should return empty list because all order is correct', async() => { + const shelving = 'NCC'; + const parking = 'A-01-1'; + const itemFk = 1000000; + + const tx = await models.Sector.beginTransaction({}); + const myOptions = {transaction: tx}; + + try { + const config = await models.ProductionConfig.findOne(); + await config.updateAttributes({ + itemOrderReviewHours: 24, + }); + + const result = await models.ItemShelving.getItemsByReviewOrder(shelving, parking, itemFk, myOptions); + + expect(result.length).toEqual(0); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); diff --git a/modules/item/back/models/item-shelving.js b/modules/item/back/models/item-shelving.js index be72dac37..34e18f23f 100644 --- a/modules/item/back/models/item-shelving.js +++ b/modules/item/back/models/item-shelving.js @@ -5,4 +5,5 @@ module.exports = Self => { require('../methods/item-shelving/getAlternative')(Self); require('../methods/item-shelving/updateFromSale')(Self); require('../methods/item-shelving/getListItemNewer')(Self); + require('../methods/item-shelving/getItemsByReviewOrder')(Self); }; -- 2.40.1 From d17566107e92e99ba16b6f2eeb9b748290695c21 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Thu, 5 Dec 2024 12:42:17 +0100 Subject: [PATCH 2/4] feat: refs #8188 refs#8188 orderPicking --- .../item-shelving/specs/getItemsByReviewOrder.spec.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/item/back/methods/item-shelving/specs/getItemsByReviewOrder.spec.js b/modules/item/back/methods/item-shelving/specs/getItemsByReviewOrder.spec.js index c16e155c9..8f368b57c 100644 --- a/modules/item/back/methods/item-shelving/specs/getItemsByReviewOrder.spec.js +++ b/modules/item/back/methods/item-shelving/specs/getItemsByReviewOrder.spec.js @@ -2,7 +2,7 @@ const {models} = require('vn-loopback/server/server'); describe('itemShelving getItemsByReviewOrder()', () => { - fit('should return empty because hoursToReview = 0', async() => { + it('should return empty because hoursToReview = 0', async() => { const shelving = 'NBB'; const parking = '700-01'; @@ -25,7 +25,7 @@ describe('itemShelving getItemsByReviewOrder()', () => { } }); - fit('should return an item because you are trying parking a shelving and there is an older item', async() => { + it('should return an item because you are trying parking a shelving and there is an older item', async() => { const shelving = 'NBB'; const parking = 'K-26-2'; const itemFk = 1000000; @@ -49,7 +49,7 @@ describe('itemShelving getItemsByReviewOrder()', () => { } }); - fit('should return an item because you are trying parking a shelving and there is an newer item', async() => { + it('should return an item because you are trying parking a shelving and there is an newer item', async() => { const shelving = 'NBB'; const parking = 'K-26-2'; const itemFk = 1000000; @@ -73,7 +73,7 @@ describe('itemShelving getItemsByReviewOrder()', () => { } }); - fit('should return a item list because you are trying parking a shelving and there is an newer item', async() => { + it('should return a item list because you are trying parking a shelving and there is an newer item', async() => { const shelving = 'NCC'; const parking = 'K-26-2'; const itemFk = 1000000; @@ -97,7 +97,7 @@ describe('itemShelving getItemsByReviewOrder()', () => { } }); - fit('should return empty list because all order is correct', async() => { + it('should return empty list because all order is correct', async() => { const shelving = 'NCC'; const parking = 'A-01-1'; const itemFk = 1000000; -- 2.40.1 From f8e5b76a6f4b79cb3cd75ce77e57e58983458596 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Thu, 5 Dec 2024 13:56:06 +0100 Subject: [PATCH 3/4] feat: refs #8188 refs#8188 orderPicking --- db/versions/11377-pinkCarnation/00-firstScript.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/db/versions/11377-pinkCarnation/00-firstScript.sql b/db/versions/11377-pinkCarnation/00-firstScript.sql index 0082a744d..4511c1b7e 100644 --- a/db/versions/11377-pinkCarnation/00-firstScript.sql +++ b/db/versions/11377-pinkCarnation/00-firstScript.sql @@ -1,4 +1,5 @@ -- Place your SQL code here -ALTER TABLE vn.productionConfig ADD itemOrderReviewHours int(11) DEFAULT 24 NULL COMMENT 'Horas que se tienen cuen cuenta para comprobar orden en el almacén, null para desactivar revisión'; +ALTER TABLE vn.productionConfig ADD itemOrderReviewHours int(11) DEFAULT 24 NULL +COMMENT 'Horas que no se tienen en cuenta para comprobar orden en el almacén, null para desactivar revisión'; -- 2.40.1 From 22e9a9104ab61083cbf60440534934b3fbb23fcb Mon Sep 17 00:00:00 2001 From: sergiodt Date: Mon, 9 Dec 2024 13:20:55 +0100 Subject: [PATCH 4/4] feat: refs #8188 refs#8188 orderPicking --- .../item-shelving/getItemsByReviewOrder.js | 66 +++++++++++-------- 1 file changed, 38 insertions(+), 28 deletions(-) diff --git a/modules/item/back/methods/item-shelving/getItemsByReviewOrder.js b/modules/item/back/methods/item-shelving/getItemsByReviewOrder.js index 96a3c9969..7a960a8c8 100644 --- a/modules/item/back/methods/item-shelving/getItemsByReviewOrder.js +++ b/modules/item/back/methods/item-shelving/getItemsByReviewOrder.js @@ -46,34 +46,44 @@ module.exports = Self => { const pickingOrderToCompare = parkingItem['pickingOrder']; const result = await Self.rawSql(` - WITH currentItemShelving AS( - SELECT is2.created + INTERVAL ? HOUR created, is2.itemFk, sh.code - FROM vn.itemShelving is2 - JOIN vn.shelving sh ON sh.id = is2.shelvingFk - LEFT JOIN vn.parking p ON p.id = sh.parkingFk - LEFT JOIN vn.sector s ON s.id = p.sectorFk - WHERE sh.code = ? AND (? IS NULL OR is2.itemFk = ?) - ) - ,itemShelvings AS ( - SELECT is2.itemFk, is2.created, sh.code, p.pickingOrder,p.code parkingFk - FROM vn.itemShelving is2 - JOIN currentItemShelving ai ON is2.itemfk = ai.itemFk - JOIN vn.shelving sh ON sh.id = is2.shelvingFk AND ai.code <> sh.code - JOIN vn.parking p ON p.id = sh.parkingFk - JOIN vn.sector s ON s.id = p.sectorFk) - ,parkingDestiny AS ( - SELECT ? pickingOrder) - SELECT ish.*, - CASE - WHEN ish.pickingOrder < d.pickingOrder AND aish.created < ish.created THEN "new" - WHEN ish.pickingOrder > d.pickingOrder AND aish.created > ish.created THEN "old" - END AS itemCreated - FROM itemShelvings ish - JOIN parkingDestiny d - JOIN currentItemShelving aish - WHERE ish.pickingOrder < d.pickingOrder AND aish.created < ish.created OR - ish.pickingOrder > d.pickingOrder AND aish.created > ish.created;`, - [hoursToCompare, shelving, itemFk, itemFk, pickingOrderToCompare], myOptions); + WITH currentItemShelving AS ( + SELECT is2.created, is2.itemFk, sh.code + FROM vn.itemShelving is2 + JOIN vn.shelving sh ON sh.id = is2.shelvingFk + LEFT JOIN vn.parking p ON p.id = sh.parkingFk + LEFT JOIN vn.sector s ON s.id = p.sectorFk + WHERE sh.code = ? AND (? IS NULL OR is2.itemFk = ?) + ), + itemShelvings AS ( + SELECT is2.itemFk, is2.created, sh.code, p.pickingOrder, p.code AS parkingFk + FROM vn.itemShelving is2 + JOIN currentItemShelving ai ON is2.itemFk = ai.itemFk + JOIN vn.shelving sh ON sh.id = is2.shelvingFk AND ai.code <> sh.code + JOIN vn.parking p ON p.id = sh.parkingFk + JOIN vn.sector s ON s.id = p.sectorFk + ), + parkingDestiny AS ( + SELECT ? AS pickingOrder + ) + SELECT ish.*, + CASE + WHEN ish.pickingOrder < d.pickingOrder AND aish.created < ish.created + AND ABS(TIMESTAMPDIFF(HOUR, aish.created, ish.created)) > ? THEN "old" + WHEN ish.pickingOrder > d.pickingOrder AND aish.created > ish.created + AND ABS(TIMESTAMPDIFF(HOUR, aish.created, ish.created)) > ? THEN "new" + END AS itemCreated + FROM itemShelvings ish + JOIN parkingDestiny d ON d.pickingOrder IS NOT NULL + JOIN currentItemShelving aish ON ish.itemFk = aish.itemFk + WHERE ABS(TIMESTAMPDIFF(HOUR, aish.created, ish.created)) > ? + AND ( + (ish.pickingOrder < d.pickingOrder AND aish.created < ish.created) + OR + (ish.pickingOrder > d.pickingOrder AND aish.created > ish.created) + ); + `, + [shelving, itemFk, itemFk, pickingOrderToCompare, + hoursToCompare, hoursToCompare, hoursToCompare, hoursToCompare], myOptions); return result; }; }; -- 2.40.1