#6321 - Negative tickets #1945

Open
jsegarra wants to merge 93 commits from 6321_negative_tickets into dev
2 changed files with 54 additions and 0 deletions
Showing only changes of commit befc128950 - Show all commits

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`