#6276 createNewWarehouse methods migrated from silex to salix #1850

Merged
jorgep merged 158 commits from 6276-createNewWarehouse into dev 2024-03-06 11:32:11 +00:00
2 changed files with 23 additions and 29 deletions
Showing only changes of commit c0398d17bf - Show all commits

View File

@ -25,7 +25,7 @@ module.exports = Self => {
Object.assign(myOptions, options);
const filterItemShelvings = {
fields: ['id', 'visible', 'itemFk', 'packing', 'grouping', 'isChecked', 'shelvingFk'],
fields: ['id', 'visible', 'itemFk', 'shelvingFk'],
where: {shelvingFk},
include: [
{
@ -34,47 +34,28 @@ module.exports = Self => {
fields: ['longName', 'name', 'size']
}
},
{
relation: 'shelving',
scope: {
include: {
fields: ['id', 'name', 'code'],
relation: 'parking',
}
}
},
]
};
let itemShelvings = await models.ItemShelving.find(filterItemShelvings, myOptions);
const [alternatives] = await models.ItemShelving.rawSql('CALL vn.itemShelving_getAlternatives(?)', [shelvingFk]);
const [alternatives] = await models.ItemShelving.rawSql(
jorgep marked this conversation as resolved Outdated

si eso se usa en el if, porque no lo mueves dentro, así en los casos que no haya itemShelvings no es necesario ejecutarlo?

si eso se usa en el if, porque no lo mueves dentro, así en los casos que no haya itemShelvings no es necesario ejecutarlo?
'CALL vn.itemShelving_getAlternatives(?)', [shelvingFk]
jorgep marked this conversation as resolved Outdated
Outdated
Review

En salix para poder loggear los cambios en CALLs hace falta que el myOptions tenga el userId

En salix para poder loggear los cambios en CALLs hace falta que el myOptions tenga el userId
);
if (itemShelvings) {
itemShelvings = itemShelvings.map(itemShelving => {
return itemShelvings.map(itemShelving => {
const item = itemShelving.item();
const shelving = itemShelving.shelving();
const parking = shelving ? shelving.parking() : null;
const carros = alternatives.filter(el => el.itemFk == itemShelving.itemFk);
const carros = alternatives.filter(alternative => alternative.itemFk == itemShelving.itemFk);
return {
id: itemShelving.id,
itemFk: itemShelving.itemFk,
longName: item ? item.longName || `${item.name} ${item.size}` : '',
quantity: itemShelving.visible,
stickers: Math.ceil(itemShelving.visible / itemShelving.packing),
packing: itemShelving.packing,
grouping: itemShelving.grouping,
code: parking ? parking.code : '',
priority: shelving ? shelving.priority : 0,
isChecked: itemShelving.isChecked,
carros
};
});
}
return itemShelvings;
};
};

View File

@ -1,6 +1,6 @@
const {models} = require('vn-loopback/server/server');
describe('itemShelving return()', () => {
fdescribe('itemShelving return()', () => {
beforeAll(async() => {
ctx = {
accessToken: {userId: 9},
@ -11,9 +11,22 @@ describe('itemShelving return()', () => {
});
it('should return a list of items and alternative locations', async() => {
const itemShelvings = await models.itemShelving.return('HEJ');
const itemShelvings = await models.ItemShelving.return('PCC');
expect(itemShelvings).toBeDefined();
// WIP
expect(itemShelvings[0].itemFk).toEqual(999997);
expect(itemShelvings[0].quantity).toEqual(10);
expect(itemShelvings[0].carros.length).toEqual(1);
});
it('should return a list of items without alternatives', async() => {
const itemShelvings = await models.ItemShelving.return('HEJ');
expect(itemShelvings[0].carros.length).toEqual(0);
});
it('should return an empty list', async() => {
const itemShelvings = await models.ItemShelving.return('ZZP');
expect(itemShelvings.length).toEqual(0);
});
});