fix(saveSign): refs #4131 remove call state on saveSign
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Pablo Natek 2023-10-27 18:07:17 +02:00
parent 65a1d052dc
commit 14753212bb
1 changed files with 33 additions and 35 deletions

View File

@ -44,40 +44,6 @@ module.exports = Self => {
myOptions.transaction = tx;
}
try {
for (const ticketId of tickets) {
const ticketState = await models.TicketState.findOne(
{where: {ticketFk: ticketId},
fields: ['alertLevel']
}, myOptions);
const packedAlertLevel = await models.AlertLevel.findOne({where: {code: 'PACKED'},
fields: ['id']
}, myOptions);
if (!ticketState)
throw new UserError('Ticket does not exist');
if (ticketState.alertLevel < packedAlertLevel.id)
throw new UserError('This ticket cannot be signed because it has not been boxed');
if (await gestDocExists(ticketId))
throw new UserError('Ticket is already signed');
if (location) setLocation(ticketId);
if (!gestDocCreated) await createGestDoc(ticketId);
await models.TicketDms.create({ticketFk: ticketId, dmsFk: dms[0].id}, myOptions);
const ticket = await models.Ticket.findById(ticketId, null, myOptions);
await ticket.updateAttribute('isSigned', true, myOptions);
const params = {ticketFk: ticketId, code: 'DELIVERED'};
await models.Ticket.state(ctx, params, options);
}
if (tx) await tx.commit();
return;
} catch (e) {
if (tx) await tx.rollback();
throw e;
}
async function setLocation(ticketId) {
await models.Delivery.create({
ticketFk: ticketId,
@ -137,9 +103,41 @@ module.exports = Self => {
description: `Firma del cliente - Ruta ${ticket.route().id}`,
hasFile: false
};
dms = await models.Dms.uploadFile(ctxUploadFile, myOptions);
gestDocCreated = true;
}
try {
for (const ticketId of tickets) {
const ticketState = await models.TicketState.findOne(
{where: {ticketFk: ticketId},
fields: ['alertLevel']
}, myOptions);
const packedAlertLevel = await models.AlertLevel.findOne({where: {code: 'PACKED'},
fields: ['id']
}, myOptions);
if (!ticketState)
throw new UserError('Ticket does not exist');
if (ticketState.alertLevel < packedAlertLevel.id)
throw new UserError('This ticket cannot be signed because it has not been boxed');
if (await gestDocExists(ticketId))
throw new UserError('Ticket is already signed');
if (location) setLocation(ticketId);
if (!gestDocCreated) await createGestDoc(ticketId);
await models.TicketDms.create({ticketFk: ticketId, dmsFk: dms[0].id}, myOptions);
const ticket = await models.Ticket.findById(ticketId, null, myOptions);
await ticket.updateAttribute('isSigned', true, myOptions);
await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [ticketId, 'DELIVERED'], myOptions);
}
if (tx) await tx.commit();
return;
} catch (e) {
if (tx) await tx.rollback();
throw e;
}
};
};