8144-devToTest_2448 #3216
|
@ -3,7 +3,7 @@ module.exports = Self => {
|
||||||
description: 'Returns a list of items and possible alternative locations',
|
description: 'Returns a list of items and possible alternative locations',
|
||||||
accessType: 'READ',
|
accessType: 'READ',
|
||||||
accepts: [{
|
accepts: [{
|
||||||
arg: 'shelvingFk',
|
arg: 'shelvingCode',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
required: true,
|
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 models = Self.app.models;
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
|
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
const shelving = await models.Shelving.findOne({
|
||||||
|
where: {
|
||||||
|
code: shelvingCode
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!shelving) return [];
|
||||||
|
const {id: shelvingFk} = shelving;
|
||||||
const filterItemShelvings = {
|
const filterItemShelvings = {
|
||||||
fields: ['id', 'visible', 'itemFk', 'shelvingFk'],
|
fields: ['id', 'visible', 'itemFk', 'shelvingFk'],
|
||||||
where: {shelvingFk},
|
where: {shelvingFk},
|
||||||
|
@ -42,7 +50,7 @@ module.exports = Self => {
|
||||||
|
|
||||||
if (itemShelvings) {
|
if (itemShelvings) {
|
||||||
const [alternatives] = await models.ItemShelving.rawSql('CALL vn.itemShelving_getAlternatives(?)',
|
const [alternatives] = await models.ItemShelving.rawSql('CALL vn.itemShelving_getAlternatives(?)',
|
||||||
[shelvingFk], myOptions
|
[shelvingCode], myOptions
|
||||||
);
|
);
|
||||||
return itemShelvings.map(itemShelving => {
|
return itemShelvings.map(itemShelving => {
|
||||||
const item = itemShelving.item();
|
const item = itemShelving.item();
|
||||||
|
|
|
@ -5,7 +5,7 @@ describe('itemShelving updateFromSale()', () => {
|
||||||
const tx = await models.ItemBarcode.beginTransaction({});
|
const tx = await models.ItemBarcode.beginTransaction({});
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
const saleFk = 2;
|
const saleFk = 2;
|
||||||
const filter = {where: {itemFk: 4, shelvingFk: 'HEJ'}
|
const filter = {where: {itemFk: 4, shelvingFk: 12}
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
const {visible: visibleBefore} = await models.ItemShelving.findOne(filter, options);
|
const {visible: visibleBefore} = await models.ItemShelving.findOne(filter, options);
|
||||||
|
|
|
@ -18,22 +18,31 @@ describe('ItemShelving upsertItem()', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should add two new records', async() => {
|
it('should add two new records', async() => {
|
||||||
const shelvingFk = 'GVC';
|
const shelvingCode = 'GVC';
|
||||||
const items = [1, 1, 1, 2];
|
const items = [1, 1, 1, 2];
|
||||||
|
const {id: shelvingFk} = await models.Shelving.findOne({
|
||||||
await models.ItemShelving.upsertItem(ctx, shelvingFk, items, warehouseFk, options);
|
where: {
|
||||||
|
code: shelvingCode
|
||||||
|
}
|
||||||
|
});
|
||||||
|
await models.ItemShelving.upsertItem(ctx, shelvingCode, 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 shelvingCode = 'GVC';
|
||||||
const items = [2, 2];
|
const items = [2, 2];
|
||||||
|
const {id: shelvingFk} = await models.Shelving.findOne({
|
||||||
|
where: {
|
||||||
|
code: shelvingCode
|
||||||
|
}
|
||||||
|
});
|
||||||
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, shelvingCode, 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]}
|
||||||
|
|
Loading…
Reference in New Issue