From eaf27629222e5f3771a3fa1f721df9e3fb59314e Mon Sep 17 00:00:00 2001 From: jgallego Date: Tue, 23 Apr 2024 07:57:37 +0200 Subject: [PATCH 1/3] feat: #6382 chekCodeFormat --- db/versions/11008-orangeCarnation/00-alter.sql | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 db/versions/11008-orangeCarnation/00-alter.sql diff --git a/db/versions/11008-orangeCarnation/00-alter.sql b/db/versions/11008-orangeCarnation/00-alter.sql new file mode 100644 index 000000000..fc434a852 --- /dev/null +++ b/db/versions/11008-orangeCarnation/00-alter.sql @@ -0,0 +1,4 @@ +ALTER TABLE vn.parking +ADD CONSTRAINT chkParkingCodeFormat CHECK (CHAR_LENGTH(code) > 4 AND code LIKE '%-%'); +ALTER TABLE vn.shelving +ADD CONSTRAINT chkShelvingCodeFormat CHECK (CHAR_LENGTH(code) <= 4 AND code NOT LIKE '%-%'); From 7d3870e4a19a7cfcbb0e6534b01649cedb4dbd47 Mon Sep 17 00:00:00 2001 From: jgallego Date: Thu, 25 Apr 2024 14:28:47 +0200 Subject: [PATCH 2/3] feat: refs#6382 test fixed --- .../vn/procedures/itemShelving_add.sql | 24 +++++---------- .../11008-orangeCarnation/00-alter.sql | 3 ++ .../item-shelving/specs/upsertItem.spec.js | 29 +++++++++---------- 3 files changed, 24 insertions(+), 32 deletions(-) diff --git a/db/routines/vn/procedures/itemShelving_add.sql b/db/routines/vn/procedures/itemShelving_add.sql index d4c31f09e..0dc7f3098 100644 --- a/db/routines/vn/procedures/itemShelving_add.sql +++ b/db/routines/vn/procedures/itemShelving_add.sql @@ -1,7 +1,7 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelving_add`(IN vShelvingFk VARCHAR(8), IN vBarcode VARCHAR(22), IN vQuantity INT, IN vPackagingFk VARCHAR(10), IN vGrouping INT, IN vPacking INT, IN vWarehouseFk INT) BEGIN - + /** * AƱade registro o lo actualiza si ya existe. @@ -13,34 +13,24 @@ BEGIN * @param vGrouping el grouping del producto en itemShelving, NULL para coger el de la ultima compra * @param vPacking el packing del producto, NULL para coger el de la ultima compra * @param vWarehouseFk indica el sector - * + * **/ DECLARE vItemFk INT; SELECT barcodeToItem(vBarcode) INTO vItemFk; - + SET vPacking = COALESCE(vPacking, GREATEST(vn.itemPacking(vBarcode,vWarehouseFk), 1)); SET vQuantity = vQuantity * vPacking; - IF (SELECT COUNT(*) FROM shelving WHERE code = vShelvingFk COLLATE utf8_unicode_ci) = 0 THEN - - INSERT IGNORE INTO parking(code) VALUES(vShelvingFk); - INSERT INTO shelving(code, parkingFk) - SELECT vShelvingFk, id - FROM parking - WHERE `code` = vShelvingFk COLLATE utf8_unicode_ci; - - END IF; - - IF (SELECT COUNT(*) FROM itemShelving - WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk - AND itemFk = vItemFk + IF (SELECT COUNT(*) FROM itemShelving + WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk + AND itemFk = vItemFk AND packing = vPacking) = 1 THEN UPDATE itemShelving SET visible = visible+vQuantity - WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk AND itemFk = vItemFk AND packing = vPacking; + WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk AND itemFk = vItemFk AND packing = vPacking; ELSE CALL cache.last_buy_refresh(FALSE); diff --git a/db/versions/11008-orangeCarnation/00-alter.sql b/db/versions/11008-orangeCarnation/00-alter.sql index fc434a852..951e2d916 100644 --- a/db/versions/11008-orangeCarnation/00-alter.sql +++ b/db/versions/11008-orangeCarnation/00-alter.sql @@ -1,4 +1,7 @@ ALTER TABLE vn.parking ADD CONSTRAINT chkParkingCodeFormat CHECK (CHAR_LENGTH(code) > 4 AND code LIKE '%-%'); + +ALTER TABLE vn.parking MODIFY COLUMN sectorFk int(11) NOT NULL; + ALTER TABLE vn.shelving ADD CONSTRAINT chkShelvingCodeFormat CHECK (CHAR_LENGTH(code) <= 4 AND code NOT LIKE '%-%'); diff --git a/modules/item/back/methods/item-shelving/specs/upsertItem.spec.js b/modules/item/back/methods/item-shelving/specs/upsertItem.spec.js index 8615b7b86..2dd43224c 100644 --- a/modules/item/back/methods/item-shelving/specs/upsertItem.spec.js +++ b/modules/item/back/methods/item-shelving/specs/upsertItem.spec.js @@ -1,18 +1,17 @@ -const { models } = require('vn-loopback/server/server'); +const {models} = require('vn-loopback/server/server'); const LoopBackContext = require('loopback-context'); -// #6276 describe('ItemShelving upsertItem()', () => { const warehouseFk = 1; let ctx; let options; let tx; - beforeEach(async () => { + beforeEach(async() => { ctx = { req: { - accessToken: { userId: 9 }, - headers: { origin: 'http://localhost' } + accessToken: {userId: 9}, + headers: {origin: 'http://localhost'} }, args: {} }; @@ -21,35 +20,35 @@ describe('ItemShelving upsertItem()', () => { active: ctx.req }); - options = { transaction: tx }; + options = {transaction: tx}; tx = await models.ItemShelving.beginTransaction({}); options.transaction = tx; }); - afterEach(async () => { + afterEach(async() => { await tx.rollback(); }); - it('should add two new records', async () => { - const shelvingFk = 'ZPP'; + it('should add two new records', async() => { + const shelvingFk = 'GVC'; const items = [1, 1, 1, 2]; await models.ItemShelving.upsertItem(ctx, shelvingFk, items, warehouseFk, options); - const itemShelvings = await models.ItemShelving.find({ where: { shelvingFk } }, options); + const itemShelvings = await models.ItemShelving.find({where: {shelvingFk}}, options); expect(itemShelvings.length).toEqual(2); }); - it('should update the visible items', async () => { + it('should update the visible items', async() => { const shelvingFk = 'GVC'; const items = [2, 2]; - const { visible: visibleItemsBefore } = await models.ItemShelving.findOne({ - where: { shelvingFk, itemFk: items[0] } + const {visible: visibleItemsBefore} = await models.ItemShelving.findOne({ + where: {shelvingFk, itemFk: items[0]} }, options); await models.ItemShelving.upsertItem(ctx, shelvingFk, items, warehouseFk, options); - const { visible: visibleItemsAfter } = await models.ItemShelving.findOne({ - where: { shelvingFk, itemFk: items[0] } + const {visible: visibleItemsAfter} = await models.ItemShelving.findOne({ + where: {shelvingFk, itemFk: items[0]} }, options); expect(visibleItemsAfter).toEqual(visibleItemsBefore + 2); From 432b6963058885d2df7148e967877debd3bc487c Mon Sep 17 00:00:00 2001 From: jgallego Date: Fri, 3 May 2024 14:57:09 +0200 Subject: [PATCH 3/3] feat: create isInformal --- db/versions/11026-brownAralia/00-entryAlter.sql | 1 + db/versions/11026-brownAralia/01-entryUpdate.sql | 3 +++ db/versions/11026-brownAralia/02-entryInternal.sql | 3 +++ 3 files changed, 7 insertions(+) create mode 100644 db/versions/11026-brownAralia/00-entryAlter.sql create mode 100644 db/versions/11026-brownAralia/01-entryUpdate.sql create mode 100644 db/versions/11026-brownAralia/02-entryInternal.sql diff --git a/db/versions/11026-brownAralia/00-entryAlter.sql b/db/versions/11026-brownAralia/00-entryAlter.sql new file mode 100644 index 000000000..26b3f727e --- /dev/null +++ b/db/versions/11026-brownAralia/00-entryAlter.sql @@ -0,0 +1 @@ +ALTER TABLE vn.entryType ADD isInformal TINYINT DEFAULT 0 NOT NULL; diff --git a/db/versions/11026-brownAralia/01-entryUpdate.sql b/db/versions/11026-brownAralia/01-entryUpdate.sql new file mode 100644 index 000000000..5454db45f --- /dev/null +++ b/db/versions/11026-brownAralia/01-entryUpdate.sql @@ -0,0 +1,3 @@ +UPDATE vn.entryType + SET description='Interna', code='internal' + WHERE code='supplies' diff --git a/db/versions/11026-brownAralia/02-entryInternal.sql b/db/versions/11026-brownAralia/02-entryInternal.sql new file mode 100644 index 000000000..77f0133e5 --- /dev/null +++ b/db/versions/11026-brownAralia/02-entryInternal.sql @@ -0,0 +1,3 @@ +UPDATE vn.entryType + SET isInformal = TRUE + WHERE code IN ('inventory', 'life', 'regularization', 'internal')