Merge branch '6682-notHolidays' of https://gitea.verdnatura.es/verdnatura/salix into 6682-notHolidays
gitea/salix/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Carlos Satorres 2024-05-07 14:59:25 +02:00
commit 371df19194
6 changed files with 35 additions and 32 deletions

View File

@ -1,7 +1,7 @@
DELIMITER $$ 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) 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 BEGIN
/** /**
* Añade registro o lo actualiza si ya existe. * 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 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 vPacking el packing del producto, NULL para coger el de la ultima compra
* @param vWarehouseFk indica el sector * @param vWarehouseFk indica el sector
* *
**/ **/
DECLARE vItemFk INT; DECLARE vItemFk INT;
SELECT barcodeToItem(vBarcode) INTO vItemFk; SELECT barcodeToItem(vBarcode) INTO vItemFk;
SET vPacking = COALESCE(vPacking, GREATEST(vn.itemPacking(vBarcode,vWarehouseFk), 1)); SET vPacking = COALESCE(vPacking, GREATEST(vn.itemPacking(vBarcode,vWarehouseFk), 1));
SET vQuantity = vQuantity * vPacking; SET vQuantity = vQuantity * vPacking;
IF (SELECT COUNT(*) FROM shelving WHERE code = vShelvingFk COLLATE utf8_unicode_ci) = 0 THEN IF (SELECT COUNT(*) FROM itemShelving
WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk
INSERT IGNORE INTO parking(code) VALUES(vShelvingFk); AND itemFk = vItemFk
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
AND packing = vPacking) = 1 THEN AND packing = vPacking) = 1 THEN
UPDATE itemShelving UPDATE itemShelving
SET visible = visible+vQuantity 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 ELSE
CALL cache.last_buy_refresh(FALSE); CALL cache.last_buy_refresh(FALSE);

View File

@ -0,0 +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 '%-%');

View File

@ -0,0 +1 @@
ALTER TABLE vn.entryType ADD isInformal TINYINT DEFAULT 0 NOT NULL;

View File

@ -0,0 +1,3 @@
UPDATE vn.entryType
SET description='Interna', code='internal'
WHERE code='supplies'

View File

@ -0,0 +1,3 @@
UPDATE vn.entryType
SET isInformal = TRUE
WHERE code IN ('inventory', 'life', 'regularization', 'internal')

View File

@ -1,18 +1,17 @@
const { models } = require('vn-loopback/server/server'); const {models} = require('vn-loopback/server/server');
const LoopBackContext = require('loopback-context'); const LoopBackContext = require('loopback-context');
// #6276
describe('ItemShelving upsertItem()', () => { describe('ItemShelving upsertItem()', () => {
const warehouseFk = 1; const warehouseFk = 1;
let ctx; let ctx;
let options; let options;
let tx; let tx;
beforeEach(async () => { beforeEach(async() => {
ctx = { ctx = {
req: { req: {
accessToken: { userId: 9 }, accessToken: {userId: 9},
headers: { origin: 'http://localhost' } headers: {origin: 'http://localhost'}
}, },
args: {} args: {}
}; };
@ -21,35 +20,35 @@ describe('ItemShelving upsertItem()', () => {
active: ctx.req active: ctx.req
}); });
options = { transaction: tx }; options = {transaction: tx};
tx = await models.ItemShelving.beginTransaction({}); tx = await models.ItemShelving.beginTransaction({});
options.transaction = tx; options.transaction = tx;
}); });
afterEach(async () => { afterEach(async() => {
await tx.rollback(); await tx.rollback();
}); });
it('should add two new records', async () => { it('should add two new records', async() => {
const shelvingFk = 'ZPP'; const shelvingFk = 'GVC';
const items = [1, 1, 1, 2]; const items = [1, 1, 1, 2];
await models.ItemShelving.upsertItem(ctx, shelvingFk, items, warehouseFk, options); 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); expect(itemShelvings.length).toEqual(2);
}); });
it('should update the visible items', async () => { it('should update the visible items', async() => {
const shelvingFk = 'GVC'; const shelvingFk = 'GVC';
const items = [2, 2]; const items = [2, 2];
const { visible: visibleItemsBefore } = await models.ItemShelving.findOne({ const {visible: visibleItemsBefore} = await models.ItemShelving.findOne({
where: { shelvingFk, itemFk: items[0] } where: {shelvingFk, itemFk: items[0]}
}, options); }, options);
await models.ItemShelving.upsertItem(ctx, shelvingFk, items, warehouseFk, options); await models.ItemShelving.upsertItem(ctx, shelvingFk, items, warehouseFk, options);
const { visible: visibleItemsAfter } = await models.ItemShelving.findOne({ const {visible: visibleItemsAfter} = await models.ItemShelving.findOne({
where: { shelvingFk, itemFk: items[0] } where: {shelvingFk, itemFk: items[0]}
}, options); }, options);
expect(visibleItemsAfter).toEqual(visibleItemsBefore + 2); expect(visibleItemsAfter).toEqual(visibleItemsBefore + 2);