Merge pull request 'refactor: refs #7817 itemShelving_addList change' (!2882) from 7817-isChecked into dev
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #2882
Reviewed-by: Javi Gallego <jgallego@verdnatura.es>
This commit is contained in:
Javi Gallego 2024-10-03 05:34:44 +00:00
commit 5f695f63b3
3 changed files with 33 additions and 19 deletions

View File

@ -1,16 +1,22 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemShelving_addList`(vShelvingFk VARCHAR(3), vList TEXT, vIsChecking BOOL, vWarehouseFk INT) CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemShelving_addList`(
vShelvingFk VARCHAR(3),
vList TEXT,
vIsChecking BOOL,
vWarehouseFk INT
)
BEGIN BEGIN
/* Recorre cada elemento en la colección vList. /**
* Recorre cada elemento en la colección vList.
* Si el parámetro isChecking = FALSE, llama a itemShelving_add. * Si el parámetro isChecking = FALSE, llama a itemShelving_add.
* *
* Cuando es TRUE sólo inserta los elementos de la colección que no están ya en * Cuando es TRUE sólo inserta los elementos de la colección que no están ya en
* ese shelving, actualizando los valores del campo vn.itemShelving.isChecked * ese shelving, actualizando los valores del campo itemShelving.isChecked
* *
* param vShelvingFk Identificador de vn.shelving * @param vShelvingFk Identificador de shelving
* param vList JSON array con esta estructura: '[value1, value2, ...]' * @param vList JSON array con esta estructura: '[value1, value2, ...]'
* param vIsChecking Define si hay que añadir o comprobar los items * @param vIsChecking Define si hay que añadir o comprobar los items
* param vWarehouseFk Identificador de vn.warehouse * @param vWarehouseFk Identificador de warehouse
*/ */
DECLARE vListLength INT DEFAULT JSON_LENGTH(vList); DECLARE vListLength INT DEFAULT JSON_LENGTH(vList);
DECLARE vCounter INT DEFAULT 0; DECLARE vCounter INT DEFAULT 0;
@ -26,20 +32,21 @@ BEGIN
IF vIsChecking THEN IF vIsChecking THEN
SELECT barcodeToItem(vBarcode) INTO vItemFk; SELECT barcodeToItem(vBarcode) INTO vItemFk;
SELECT COUNT(*) INTO vIsChecked SELECT IF(COUNT(*), TRUE, FALSE) INTO vIsChecked
FROM vn.itemShelving FROM itemShelving
WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk
AND itemFk = vItemFk; AND itemFk = vItemFk;
END IF; END IF;
IF NOT (vIsChecking AND vIsChecked) THEN IF NOT vIsChecking OR NOT vIsChecked THEN
CALL vn.itemShelving_add(vShelvingFk, vBarcode, 1, NULL, NULL, NULL, vWarehouseFk); CALL itemShelving_add(vShelvingFk, vBarcode, 1, NULL, NULL, NULL, vWarehouseFk);
END IF; END IF;
UPDATE vn.itemShelving UPDATE itemShelving
SET isChecked = vIsChecked SET isChecked = vIsChecked
WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk
AND itemFk = vItemFk AND isChecked IS NULL; AND itemFk = vItemFk
AND isChecked IS NULL;
SET vCounter = vCounter + 1; SET vCounter = vCounter + 1;
END WHILE; END WHILE;

View File

@ -0,0 +1,7 @@
UPDATE vn.itemShelving
SET isChecked = TRUE
WHERE isChecked;
UPDATE vn.itemShelving
SET isChecked = FALSE
WHERE NOT isChecked;

View File

@ -1,6 +1,6 @@
const {models} = require('vn-loopback/server/server'); const {models} = require('vn-loopback/server/server');
describe('item lastEntriesFilter()', () => { describe('item lastEntriesFilter()', () => {
it('should return two entry for the given item', async() => { it('should return one entry for the given item', async() => {
const minDate = Date.vnNew(); const minDate = Date.vnNew();
minDate.setHours(0, 0, 0, 0); minDate.setHours(0, 0, 0, 0);
const maxDate = Date.vnNew(); const maxDate = Date.vnNew();
@ -13,7 +13,7 @@ describe('item lastEntriesFilter()', () => {
const filter = {where: {itemFk: 1, landed: {between: [minDate, maxDate]}}}; const filter = {where: {itemFk: 1, landed: {between: [minDate, maxDate]}}};
const result = await models.Item.lastEntriesFilter(filter, options); const result = await models.Item.lastEntriesFilter(filter, options);
expect(result.length).toEqual(2); expect(result.length).toEqual(1);
await tx.rollback(); await tx.rollback();
} catch (e) { } catch (e) {
@ -22,7 +22,7 @@ describe('item lastEntriesFilter()', () => {
} }
}); });
it('should return six entries for the given item', async() => { it('should return five entries for the given item', async() => {
const minDate = Date.vnNew(); const minDate = Date.vnNew();
minDate.setHours(0, 0, 0, 0); minDate.setHours(0, 0, 0, 0);
minDate.setMonth(minDate.getMonth() - 2, 1); minDate.setMonth(minDate.getMonth() - 2, 1);
@ -37,7 +37,7 @@ describe('item lastEntriesFilter()', () => {
const filter = {where: {itemFk: 1, landed: {between: [minDate, maxDate]}}}; const filter = {where: {itemFk: 1, landed: {between: [minDate, maxDate]}}};
const result = await models.Item.lastEntriesFilter(filter, options); const result = await models.Item.lastEntriesFilter(filter, options);
expect(result.length).toEqual(6); expect(result.length).toEqual(5);
await tx.rollback(); await tx.rollback();
} catch (e) { } catch (e) {