7152-devToTest_2414 #2228
|
@ -25,7 +25,7 @@ module.exports = Self => {
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
const filterItemShelvings = {
|
const filterItemShelvings = {
|
||||||
fields: ['id', 'visible', 'itemFk', 'packing', 'grouping', 'isChecked', 'shelvingFk'],
|
fields: ['id', 'visible', 'itemFk', 'shelvingFk'],
|
||||||
where: {shelvingFk},
|
where: {shelvingFk},
|
||||||
include: [
|
include: [
|
||||||
{
|
{
|
||||||
|
@ -34,47 +34,28 @@ module.exports = Self => {
|
||||||
fields: ['longName', 'name', 'size']
|
fields: ['longName', 'name', 'size']
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
|
||||||
relation: 'shelving',
|
|
||||||
|
|
||||||
scope: {
|
|
||||||
include: {
|
|
||||||
fields: ['id', 'name', 'code'],
|
|
||||||
relation: 'parking',
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
},
|
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
let itemShelvings = await models.ItemShelving.find(filterItemShelvings, myOptions);
|
let itemShelvings = await models.ItemShelving.find(filterItemShelvings, myOptions);
|
||||||
|
const [alternatives] = await models.ItemShelving.rawSql(
|
||||||
const [alternatives] = await models.ItemShelving.rawSql('CALL vn.itemShelving_getAlternatives(?)', [shelvingFk]);
|
'CALL vn.itemShelving_getAlternatives(?)', [shelvingFk]
|
||||||
|
);
|
||||||
|
|
||||||
if (itemShelvings) {
|
if (itemShelvings) {
|
||||||
itemShelvings = itemShelvings.map(itemShelving => {
|
return itemShelvings.map(itemShelving => {
|
||||||
const item = itemShelving.item();
|
const item = itemShelving.item();
|
||||||
const shelving = itemShelving.shelving();
|
const carros = alternatives.filter(alternative => alternative.itemFk == itemShelving.itemFk);
|
||||||
const parking = shelving ? shelving.parking() : null;
|
|
||||||
|
|
||||||
const carros = alternatives.filter(el => el.itemFk == itemShelving.itemFk);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: itemShelving.id,
|
id: itemShelving.id,
|
||||||
itemFk: itemShelving.itemFk,
|
itemFk: itemShelving.itemFk,
|
||||||
longName: item ? item.longName || `${item.name} ${item.size}` : '',
|
longName: item ? item.longName || `${item.name} ${item.size}` : '',
|
||||||
quantity: itemShelving.visible,
|
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
|
carros
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return itemShelvings;
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const {models} = require('vn-loopback/server/server');
|
const {models} = require('vn-loopback/server/server');
|
||||||
|
|
||||||
describe('itemShelving return()', () => {
|
fdescribe('itemShelving return()', () => {
|
||||||
beforeAll(async() => {
|
beforeAll(async() => {
|
||||||
ctx = {
|
ctx = {
|
||||||
accessToken: {userId: 9},
|
accessToken: {userId: 9},
|
||||||
|
@ -11,9 +11,22 @@ describe('itemShelving return()', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return a list of items and alternative locations', async() => {
|
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();
|
expect(itemShelvings[0].itemFk).toEqual(999997);
|
||||||
// WIP
|
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);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue