fix: refs #7028 fix confirm deny #3290
|
@ -54,9 +54,17 @@ module.exports = Self => {
|
||||||
throw new UserError(`That item doesn't exists`);
|
throw new UserError(`That item doesn't exists`);
|
||||||
|
|
||||||
const request = await models.TicketRequest.findById(ctx.args.id, {
|
const request = await models.TicketRequest.findById(ctx.args.id, {
|
||||||
include: {relation: 'ticket'}
|
include: {
|
||||||
|
relation: 'ticket',
|
||||||
|
scope: {
|
||||||
|
include: {
|
||||||
|
relation: 'client',
|
||||||
|
scope: {
|
||||||
|
fields: ['id', 'name', 'salesPersonFk']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}}
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
const itemStock = await models.Item.getVisibleAvailable(
|
const itemStock = await models.Item.getVisibleAvailable(
|
||||||
ctx.args.itemFk,
|
ctx.args.itemFk,
|
||||||
request.ticket().warehouseFk,
|
request.ticket().warehouseFk,
|
||||||
|
@ -89,9 +97,9 @@ module.exports = Self => {
|
||||||
const query = `CALL vn.sale_calculateComponent(?, NULL)`;
|
const query = `CALL vn.sale_calculateComponent(?, NULL)`;
|
||||||
await Self.rawSql(query, [sale.id], myOptions);
|
await Self.rawSql(query, [sale.id], myOptions);
|
||||||
|
|
||||||
|
const salesPerson = request.ticket().client().salesPersonFk;
|
||||||
|
|||||||
|
if (salesPerson) {
|
||||||
const url = await Self.app.models.Url.getUrl();
|
const url = await Self.app.models.Url.getUrl();
|
||||||
const requesterId = request.requesterFk;
|
|
||||||
|
|
||||||
const message = $t('Bought units from buy request', {
|
const message = $t('Bought units from buy request', {
|
||||||
quantity: sale.quantity,
|
quantity: sale.quantity,
|
||||||
concept: sale.concept,
|
concept: sale.concept,
|
||||||
|
@ -100,8 +108,8 @@ module.exports = Self => {
|
||||||
url: `${url}ticket/${sale.ticketFk}/summary`,
|
url: `${url}ticket/${sale.ticketFk}/summary`,
|
||||||
urlItem: `${url}item/${sale.itemFk}/summary`
|
urlItem: `${url}item/${sale.itemFk}/summary`
|
||||||
});
|
});
|
||||||
await models.Chat.sendCheckingPresence(ctx, requesterId, message, myOptions);
|
await models.Chat.sendCheckingPresence(ctx, salesPerson, message, myOptions);
|
||||||
|
}
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
return sale;
|
return sale;
|
||||||
|
|
|
@ -1,18 +1,22 @@
|
||||||
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('deny', {
|
Self.remoteMethodCtx('deny', {
|
||||||
description: 'sets a ticket request to denied and returns the changes',
|
description: 'Sets a ticket request to denied and returns the changes',
|
||||||
accessType: 'WRITE',
|
accessType: 'WRITE',
|
||||||
accepts: [{
|
accepts: [
|
||||||
|
{
|
||||||
arg: 'id',
|
arg: 'id',
|
||||||
type: 'number',
|
type: 'number',
|
||||||
required: true,
|
required: true,
|
||||||
description: 'The request ID',
|
description: 'The request ID',
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
arg: 'observation',
|
arg: 'observation',
|
||||||
type: 'String',
|
type: 'string',
|
||||||
required: true,
|
required: true,
|
||||||
description: 'The request observation',
|
description: 'The request observation',
|
||||||
}],
|
}
|
||||||
|
],
|
||||||
returns: {
|
returns: {
|
||||||
type: 'number',
|
type: 'number',
|
||||||
root: true
|
root: true
|
||||||
|
@ -29,7 +33,7 @@ module.exports = Self => {
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
let tx;
|
let tx;
|
||||||
|
|
||||||
if (typeof options == 'object')
|
if (typeof options === 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
if (!myOptions.transaction) {
|
if (!myOptions.transaction) {
|
||||||
|
@ -39,7 +43,7 @@ module.exports = Self => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const userId = ctx.req.accessToken.userId;
|
const userId = ctx.req.accessToken.userId;
|
||||||
carlossa marked this conversation as resolved
Outdated
alexm
commented
findById findById
|
|||||||
const worker = await Self.app.models.Worker.findOne({where: {id: userId}}, myOptions);
|
const worker = await models.Worker.findById(userId, {fields: ['id']}, myOptions);
|
||||||
carlossa marked this conversation as resolved
Outdated
alexm
commented
Traducir Traducir
alexm
commented
`(userId, {fields: ...}, myOptions);`
|
|||||||
|
|
||||||
const params = {
|
const params = {
|
||||||
isOk: false,
|
isOk: false,
|
||||||
|
@ -47,19 +51,32 @@ module.exports = Self => {
|
||||||
response: ctx.args.observation,
|
response: ctx.args.observation,
|
||||||
};
|
};
|
||||||
|
|
||||||
const request = await Self.app.models.TicketRequest.findById(ctx.args.id, null, myOptions);
|
const request = await models.TicketRequest.findById(ctx.args.id, {
|
||||||
await request.updateAttributes(params, myOptions);
|
include: {
|
||||||
|
relation: 'ticket',
|
||||||
const url = await Self.app.models.Url.getUrl();
|
scope: {
|
||||||
const requesterId = request.requesterFk;
|
include: {
|
||||||
|
relation: 'client',
|
||||||
|
scope: {
|
||||||
|
fields: ['id', 'name', 'salesPersonFk']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, myOptions);
|
||||||
|
|
||||||
|
const salesPerson = request.ticket().client().salesPersonFk;
|
||||||
alexm
commented
const salesPerson const salesPerson
|
|||||||
|
if (salesPerson) {
|
||||||
|
const url = await models.Url.getUrl();
|
||||||
const message = $t('Deny buy request', {
|
const message = $t('Deny buy request', {
|
||||||
ticketId: request.ticketFk,
|
ticketId: request.ticketFk,
|
||||||
url: `${url}ticket/${request.ticketFk}/request/index`,
|
url: `${url}ticket/${request.ticketFk}/request/index`,
|
||||||
observation: params.response
|
observation: params.response
|
||||||
});
|
});
|
||||||
|
|
||||||
await models.Chat.sendCheckingPresence(ctx, requesterId, message, myOptions);
|
await models.Chat.sendCheckingPresence(ctx, salesPerson, message, myOptions);
|
||||||
|
await request.updateAttributes(params, myOptions);
|
||||||
|
}
|
||||||
carlossa marked this conversation as resolved
Outdated
alexm
commented
, myOptions); , myOptions);
|
|||||||
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
const salesPerson