feat(salix): refs #6321 Sale_itemReplace

This commit is contained in:
Javier Segarra 2024-05-15 08:36:13 +02:00
parent 5c0b25bb30
commit befc128950
2 changed files with 54 additions and 0 deletions

View File

@ -0,0 +1,53 @@
const UserError = require('vn-loopback/util/user-error');
module.exports = Self => {
Self.remoteMethodCtx('replaceItem', {
description: 'Replace item from sale',
accessType: 'WRITE',
accepts: [{
arg: 'saleFk',
type: 'number',
required: true,
},
{
arg: 'newItemFk',
type: 'number',
required: true
},
{
arg: 'quantity',
type: 'number',
required: true
}
],
returns: {
type: 'object',
root: true
},
http: {
path: `/recalculatePrice`,
verb: 'POST'
}
});
Self.recalculatePrice = async(ctx, saleFk, itemFk, quantity, options) => {
const myOptions = {userId: ctx.req.accessToken.userId};
let tx;
if (typeof options == 'object')
Object.assign(myOptions, options);
if (!myOptions.transaction) {
tx = await Self.beginTransaction({});
myOptions.transaction = tx;
}
try {
const result = await Self.rawSql('CALL sale_replaceItem(?,?,?)', [saleFk, itemFk, quantity], myOptions);
return result;
} catch (e) {
if (tx) await tx.rollback();
throw e;
}
};
};

View File

@ -13,6 +13,7 @@ module.exports = Self => {
require('../methods/sale/usesMana')(Self);
require('../methods/sale/clone')(Self);
require('../methods/sale/getFromSectorCollection')(Self);
require('../methods/sale/replaceItem')(Self);
Self.validatesPresenceOf('concept', {
message: `Concept cannot be blank`