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',
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();

View File

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

View File

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