fixes #5149 ticket.descriptor-menu Eliminar ticket, debe comprobar que no existe un abono #1348
|
@ -147,5 +147,6 @@
|
||||||
"The sales of the receiver ticket can't be modified": "The sales of the receiver ticket can't be modified",
|
"The sales of the receiver ticket can't be modified": "The sales of the receiver ticket can't be modified",
|
||||||
"Receipt's bank was not found": "Receipt's bank was not found",
|
"Receipt's bank was not found": "Receipt's bank was not found",
|
||||||
"This receipt was not compensated": "This receipt was not compensated",
|
"This receipt was not compensated": "This receipt was not compensated",
|
||||||
"Client's email was not found": "Client's email was not found"
|
"Client's email was not found": "Client's email was not found",
|
||||||
|
"Tickets with associated refunds": "Tickets with associated refunds can't be deleted. This ticket is associated with refund Nº {{id}}"
|
||||||
}
|
}
|
||||||
|
|
|
@ -259,5 +259,6 @@
|
||||||
"Try again": "Vuelve a intentarlo",
|
"Try again": "Vuelve a intentarlo",
|
||||||
"Aplicación bloqueada por el usuario 9": "Aplicación bloqueada por el usuario 9",
|
"Aplicación bloqueada por el usuario 9": "Aplicación bloqueada por el usuario 9",
|
||||||
"Failed to upload file": "Error al subir archivo",
|
"Failed to upload file": "Error al subir archivo",
|
||||||
"The DOCUWARE PDF document does not exists": "The DOCUWARE PDF document does not exists"
|
"The DOCUWARE PDF document does not exists": "The DOCUWARE PDF document does not exists",
|
||||||
|
"Tickets with associated refunds": "No se pueden borrar tickets con abonos asociados. Este ticket está asociado al abono Nº {{id}}"
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,10 +42,13 @@ module.exports = Self => {
|
||||||
if (!isEditable)
|
if (!isEditable)
|
||||||
throw new UserError(`The sales of this ticket can't be modified`);
|
throw new UserError(`The sales of this ticket can't be modified`);
|
||||||
|
|
||||||
const hasRefunds = await checkRefunds(id, myOptions);
|
// Check if ticket has refunds
|
||||||
|
const ticketRefunds = await models.TicketRefund.find({
|
||||||
if (hasRefunds)
|
where: {originalTicketFk: id},
|
||||||
throw new UserError(`You must delete the refund id %d first`, 'DELETE_REFUND_FIRST', hasRefunds);
|
fields: ['id']}
|
||||||
|
, myOptions);
|
||||||
|
if (ticketRefunds.length > 0)
|
||||||
|
throw new UserError($t('Tickets with associated refunds', {id: ticketRefunds[0].id}));
|
||||||
|
|
||||||
// Check if has sales with shelving
|
// Check if has sales with shelving
|
||||||
const isSalesAssistant = await models.Account.hasRole(userId, 'salesAssistant', myOptions);
|
const isSalesAssistant = await models.Account.hasRole(userId, 'salesAssistant', myOptions);
|
||||||
|
@ -139,12 +142,12 @@ module.exports = Self => {
|
||||||
await models.TicketCollection.destroyById(ticketCollection.id, myOptions);
|
await models.TicketCollection.destroyById(ticketCollection.id, myOptions);
|
||||||
|
|
||||||
await Self.rawSql(`
|
await Self.rawSql(`
|
||||||
DELETE sc
|
DELETE sc
|
||||||
FROM vn.saleGroup sg
|
FROM vn.saleGroup sg
|
||||||
JOIN vn.sectorCollectionSaleGroup scsg ON scsg.saleGroupFk = sg.id
|
JOIN vn.sectorCollectionSaleGroup scsg ON scsg.saleGroupFk = sg.id
|
||||||
JOIN vn.sectorCollection sc ON sc.id = scsg.sectorCollectionFk
|
JOIN vn.sectorCollection sc ON sc.id = scsg.sectorCollectionFk
|
||||||
JOIN vn.saleGroupDetail sgd ON sgd.saleGroupFk = sg.id
|
JOIN vn.saleGroupDetail sgd ON sgd.saleGroupFk = sg.id
|
||||||
JOIN vn.sale s ON s.id = sgd.saleFk
|
JOIN vn.sale s ON s.id = sgd.saleFk
|
||||||
WHERE s.ticketFk = ?;`, [ticket.id], myOptions);
|
WHERE s.ticketFk = ?;`, [ticket.id], myOptions);
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
|
@ -155,16 +158,4 @@ module.exports = Self => {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
async function checkRefunds(id, options) {
|
|
||||||
const models = Self.app.models;
|
|
||||||
let refunds = await models.TicketRefund.find({
|
|
||||||
where: {ticketFk: id}
|
|
||||||
}, options);
|
|
||||||
|
|
||||||
if (refunds.length > 0)
|
|
||||||
return refunds[0].refundTicketFk;
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue