refs #6276 itemShelving_updateFromSale
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Jorge Penadés 2023-12-01 11:43:07 +01:00
parent d2769f4c21
commit 7e57640758
2 changed files with 52 additions and 0 deletions

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/getInventory')(Self);
require('../methods/item-shelving/makeMulti')(Self); require('../methods/item-shelving/makeMulti')(Self);
require('../methods/item-shelving/return')(Self); require('../methods/item-shelving/return')(Self);
require('../methods/item-shelving/updateFromSale')(Self);
}; };