Merge pull request 'fix: refs #7028 fix confirm deny' (!3290) from 7028-itemRequestConfDeny into dev
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
Reviewed-on: #3290 Reviewed-by: Alex Moreno <alexm@verdnatura.es>
This commit is contained in:
commit
f9434871d8
|
@ -54,9 +54,17 @@ module.exports = Self => {
|
|||
throw new UserError(`That item doesn't exists`);
|
||||
|
||||
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);
|
||||
|
||||
const itemStock = await models.Item.getVisibleAvailable(
|
||||
ctx.args.itemFk,
|
||||
request.ticket().warehouseFk,
|
||||
|
@ -89,19 +97,19 @@ module.exports = Self => {
|
|||
const query = `CALL vn.sale_calculateComponent(?, NULL)`;
|
||||
await Self.rawSql(query, [sale.id], myOptions);
|
||||
|
||||
const url = await Self.app.models.Url.getUrl();
|
||||
const requesterId = request.requesterFk;
|
||||
|
||||
const message = $t('Bought units from buy request', {
|
||||
quantity: sale.quantity,
|
||||
concept: sale.concept,
|
||||
itemId: sale.itemFk,
|
||||
ticketId: sale.ticketFk,
|
||||
url: `${url}ticket/${sale.ticketFk}/summary`,
|
||||
urlItem: `${url}item/${sale.itemFk}/summary`
|
||||
});
|
||||
await models.Chat.sendCheckingPresence(ctx, requesterId, message, myOptions);
|
||||
|
||||
const salesPerson = request.ticket().client().salesPersonFk;
|
||||
if (salesPerson) {
|
||||
const url = await Self.app.models.Url.getUrl();
|
||||
const message = $t('Bought units from buy request', {
|
||||
quantity: sale.quantity,
|
||||
concept: sale.concept,
|
||||
itemId: sale.itemFk,
|
||||
ticketId: sale.ticketFk,
|
||||
url: `${url}ticket/${sale.ticketFk}/summary`,
|
||||
urlItem: `${url}item/${sale.itemFk}/summary`
|
||||
});
|
||||
await models.Chat.sendCheckingPresence(ctx, salesPerson, message, myOptions);
|
||||
}
|
||||
if (tx) await tx.commit();
|
||||
|
||||
return sale;
|
||||
|
|
|
@ -1,18 +1,22 @@
|
|||
const UserError = require('vn-loopback/util/user-error');
|
||||
module.exports = Self => {
|
||||
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',
|
||||
accepts: [{
|
||||
arg: 'id',
|
||||
type: 'number',
|
||||
required: true,
|
||||
description: 'The request ID',
|
||||
}, {
|
||||
arg: 'observation',
|
||||
type: 'String',
|
||||
required: true,
|
||||
description: 'The request observation',
|
||||
}],
|
||||
accepts: [
|
||||
{
|
||||
arg: 'id',
|
||||
type: 'number',
|
||||
required: true,
|
||||
description: 'The request ID',
|
||||
},
|
||||
{
|
||||
arg: 'observation',
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: 'The request observation',
|
||||
}
|
||||
],
|
||||
returns: {
|
||||
type: 'number',
|
||||
root: true
|
||||
|
@ -29,7 +33,7 @@ module.exports = Self => {
|
|||
const myOptions = {};
|
||||
let tx;
|
||||
|
||||
if (typeof options == 'object')
|
||||
if (typeof options === 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
if (!myOptions.transaction) {
|
||||
|
@ -39,7 +43,7 @@ module.exports = Self => {
|
|||
|
||||
try {
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
const worker = await Self.app.models.Worker.findOne({where: {id: userId}}, myOptions);
|
||||
const worker = await models.Worker.findById(userId, {fields: ['id']}, myOptions);
|
||||
|
||||
const params = {
|
||||
isOk: false,
|
||||
|
@ -47,19 +51,32 @@ module.exports = Self => {
|
|||
response: ctx.args.observation,
|
||||
};
|
||||
|
||||
const request = await Self.app.models.TicketRequest.findById(ctx.args.id, null, myOptions);
|
||||
await request.updateAttributes(params, myOptions);
|
||||
const request = await models.TicketRequest.findById(ctx.args.id, {
|
||||
include: {
|
||||
relation: 'ticket',
|
||||
scope: {
|
||||
include: {
|
||||
relation: 'client',
|
||||
scope: {
|
||||
fields: ['id', 'name', 'salesPersonFk']
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, myOptions);
|
||||
|
||||
const url = await Self.app.models.Url.getUrl();
|
||||
const requesterId = request.requesterFk;
|
||||
const salesPerson = request.ticket().client().salesPersonFk;
|
||||
if (salesPerson) {
|
||||
const url = await models.Url.getUrl();
|
||||
const message = $t('Deny buy request', {
|
||||
ticketId: request.ticketFk,
|
||||
url: `${url}ticket/${request.ticketFk}/request/index`,
|
||||
observation: params.response
|
||||
});
|
||||
|
||||
const message = $t('Deny buy request', {
|
||||
ticketId: request.ticketFk,
|
||||
url: `${url}ticket/${request.ticketFk}/request/index`,
|
||||
observation: params.response
|
||||
});
|
||||
|
||||
await models.Chat.sendCheckingPresence(ctx, requesterId, message, myOptions);
|
||||
await models.Chat.sendCheckingPresence(ctx, salesPerson, message, myOptions);
|
||||
await request.updateAttributes(params, myOptions);
|
||||
}
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
||||
|
|
Loading…
Reference in New Issue