Merge pull request 'fixes #5677 Fallo portainer Ticket/SaveSign' (!1556) from 5677-fallo-saveSign into dev
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
Reviewed-on: #1556 Reviewed-by: Javi Gallego <jgallego@verdnatura.es>
This commit is contained in:
commit
12aa9dee41
|
@ -290,5 +290,7 @@
|
|||
"isTaxDataChecked": "Datos comprobados",
|
||||
"comercialId": "Id comercial",
|
||||
"comercialName": "Comercial",
|
||||
"Invalid NIF for VIES": "Invalid NIF for VIES"
|
||||
}
|
||||
"Invalid NIF for VIES": "Invalid NIF for VIES",
|
||||
"Ticket does not exist": "Este ticket no existe",
|
||||
"Ticket is already signed": "Este ticket ya ha sido firmado"
|
||||
}
|
||||
|
|
|
@ -29,8 +29,7 @@ module.exports = Self => {
|
|||
}
|
||||
});
|
||||
|
||||
Self.saveSign = async(ctx, options) => {
|
||||
const args = Object.assign({}, ctx.args);
|
||||
Self.saveSign = async(ctx, tickets, location, signedTime, options) => {
|
||||
const models = Self.app.models;
|
||||
const myOptions = {};
|
||||
let tx;
|
||||
|
@ -48,9 +47,9 @@ module.exports = Self => {
|
|||
async function setLocation(ticketId) {
|
||||
await models.Delivery.create({
|
||||
ticketFk: ticketId,
|
||||
longitude: args.location.Longitude,
|
||||
latitude: args.location.Latitude,
|
||||
dated: args.signedTime || new Date()
|
||||
longitude: location.Longitude,
|
||||
latitude: location.Latitude,
|
||||
dated: signedTime || new Date()
|
||||
}, myOptions);
|
||||
}
|
||||
|
||||
|
@ -107,9 +106,9 @@ module.exports = Self => {
|
|||
}
|
||||
|
||||
try {
|
||||
for (let i = 0; i < args.tickets.length; i++) {
|
||||
for (const ticketId of tickets) {
|
||||
const ticketState = await models.TicketState.findOne(
|
||||
{where: {ticketFk: args.tickets[i]},
|
||||
{where: {ticketFk: ticketId},
|
||||
fields: ['alertLevel']
|
||||
}, myOptions);
|
||||
|
||||
|
@ -117,16 +116,19 @@ module.exports = Self => {
|
|||
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');
|
||||
else if (!await gestDocExists(args.tickets[i])) {
|
||||
if (args.location) setLocation(args.tickets[i]);
|
||||
if (!gestDocCreated) await createGestDoc(args.tickets[i]);
|
||||
await models.TicketDms.create({ticketFk: args.tickets[i], dmsFk: dms[0].id}, myOptions);
|
||||
const ticket = await models.Ticket.findById(args.tickets[i], null, myOptions);
|
||||
await ticket.updateAttribute('isSigned', true, myOptions);
|
||||
await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [args.tickets[i], 'DELIVERED'], myOptions);
|
||||
}
|
||||
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();
|
||||
|
|
Loading…
Reference in New Issue