7152-devToTest_2414 #2228

Merged
alexm merged 636 commits from 7152-devToTest_2414 into test 2024-03-28 08:26:34 +00:00
2 changed files with 52 additions and 0 deletions
Showing only changes of commit 7e57640758 - Show all commits

View File

@ -0,0 +1,51 @@
module.exports = Self => {
Self.remoteMethod('updateFromSale', {
description: 'Returns a list of items and possible alternative locations',
accessType: 'WRITE',
accepts: [{
arg: 'saleFk',
type: 'number',
required: true,
}],
http: {
path: `/updateFromSale`,
verb: 'POST'
}
});
Self.updateFromSale = async(saleFk, options) => {
const models = Self.app.models;
const myOptions = {};
let tx;
if (typeof options == 'object')
Object.assign(myOptions, options);
if (!myOptions.transaction) {
tx = await Self.beginTransaction({});
myOptions.transaction = tx;
}
try {
const itemShelvingSale = await models.ItemShelvingSale.findOne({
where: {saleFk}
}, myOptions);
const itemShelving = await models.ItemShelving.findOne({
where: {
id: itemShelvingSale.ItemShelvingFk
}
});
const quantity = itemShelving.visible + itemShelvingSale.quantity;
await itemShelving.updateAttributes(
{visible: quantity},
myOptions
);
if (tx) await tx.commit();
} catch (e) {
if (tx) await tx.rollback();
throw e;
}
};
};

View File

@ -3,4 +3,5 @@ module.exports = Self => {
require('../methods/item-shelving/getInventory')(Self);
require('../methods/item-shelving/makeMulti')(Self);
require('../methods/item-shelving/return')(Self);
require('../methods/item-shelving/updateFromSale')(Self);
};