8144-devToTest_2448 #3216

Merged
alexm merged 256 commits from 8144-devToTest_2448 into test 2024-11-19 07:36:04 +00:00
3 changed files with 26 additions and 9 deletions
Showing only changes of commit 755312b981 - Show all commits

View File

@ -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();

View File

@ -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);

View File

@ -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]}