This commit is contained in:
parent
9d5ef3eeb0
commit
755312b981
|
@ -3,7 +3,7 @@ module.exports = Self => {
|
|||
description: 'Returns a list of items and possible alternative locations',
|
||||
accessType: 'READ',
|
||||
accepts: [{
|
||||
arg: 'shelvingFk',
|
||||
arg: 'shelvingCode',
|
||||
type: 'string',
|
||||
required: true,
|
||||
}],
|
||||
|
@ -17,13 +17,21 @@ module.exports = Self => {
|
|||
}
|
||||
});
|
||||
|
||||
Self.getAlternative = async(shelvingFk, options) => {
|
||||
Self.getAlternative = async(shelvingCode, options) => {
|
||||
const models = Self.app.models;
|
||||
const myOptions = {};
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
const shelving = await models.Shelving.findOne({
|
||||
where: {
|
||||
code: shelvingCode
|
||||
}
|
||||
});
|
||||
|
||||
if (!shelving) return [];
|
||||
const {id: shelvingFk} = shelving;
|
||||
const filterItemShelvings = {
|
||||
fields: ['id', 'visible', 'itemFk', 'shelvingFk'],
|
||||
where: {shelvingFk},
|
||||
|
@ -42,7 +50,7 @@ module.exports = Self => {
|
|||
|
||||
if (itemShelvings) {
|
||||
const [alternatives] = await models.ItemShelving.rawSql('CALL vn.itemShelving_getAlternatives(?)',
|
||||
[shelvingFk], myOptions
|
||||
[shelvingCode], myOptions
|
||||
);
|
||||
return itemShelvings.map(itemShelving => {
|
||||
const item = itemShelving.item();
|
||||
|
|
|
@ -5,7 +5,7 @@ describe('itemShelving updateFromSale()', () => {
|
|||
const tx = await models.ItemBarcode.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
const saleFk = 2;
|
||||
const filter = {where: {itemFk: 4, shelvingFk: 'HEJ'}
|
||||
const filter = {where: {itemFk: 4, shelvingFk: 12}
|
||||
};
|
||||
try {
|
||||
const {visible: visibleBefore} = await models.ItemShelving.findOne(filter, options);
|
||||
|
|
|
@ -18,22 +18,31 @@ describe('ItemShelving upsertItem()', () => {
|
|||
});
|
||||
|
||||
it('should add two new records', async() => {
|
||||
const shelvingFk = 'GVC';
|
||||
const shelvingCode = 'GVC';
|
||||
const items = [1, 1, 1, 2];
|
||||
|
||||
await models.ItemShelving.upsertItem(ctx, shelvingFk, items, warehouseFk, options);
|
||||
const {id: shelvingFk} = await models.Shelving.findOne({
|
||||
where: {
|
||||
code: shelvingCode
|
||||
}
|
||||
});
|
||||
await models.ItemShelving.upsertItem(ctx, shelvingCode, items, warehouseFk, options);
|
||||
const itemShelvings = await models.ItemShelving.find({where: {shelvingFk}}, options);
|
||||
|
||||
expect(itemShelvings.length).toEqual(2);
|
||||
});
|
||||
|
||||
it('should update the visible items', async() => {
|
||||
const shelvingFk = 'GVC';
|
||||
const shelvingCode = 'GVC';
|
||||
const items = [2, 2];
|
||||
const {id: shelvingFk} = await models.Shelving.findOne({
|
||||
where: {
|
||||
code: shelvingCode
|
||||
}
|
||||
});
|
||||
const {visible: visibleItemsBefore} = await models.ItemShelving.findOne({
|
||||
where: {shelvingFk, itemFk: items[0]}
|
||||
}, options);
|
||||
await models.ItemShelving.upsertItem(ctx, shelvingFk, items, warehouseFk, options);
|
||||
await models.ItemShelving.upsertItem(ctx, shelvingCode, items, warehouseFk, options);
|
||||
|
||||
const {visible: visibleItemsAfter} = await models.ItemShelving.findOne({
|
||||
where: {shelvingFk, itemFk: items[0]}
|
||||
|
|
Loading…
Reference in New Issue