fixes #5149 ticket.descriptor-menu Eliminar ticket, debe comprobar que no existe un abono #1348

Merged
joan merged 8 commits from 5149-check-ticket.refund into dev 2023-03-02 06:30:18 +00:00
1 changed files with 17 additions and 0 deletions
Showing only changes of commit 5c0354bc17 - Show all commits

View File

@ -42,6 +42,11 @@ module.exports = Self => {
if (!isEditable)
throw new UserError(`The sales of this ticket can't be modified`);
const hasRefunds = await checkRefunds(id, myOptions);
if (hasRefunds)
throw new UserError(`You must delete the refund id %d first`, 'DELETE_REFUND_FIRST', hasRefunds);
// Check if has sales with shelving
const isSalesAssistant = await models.Account.hasRole(userId, 'salesAssistant', myOptions);
const sales = await models.Sale.find({
@ -150,4 +155,16 @@ module.exports = Self => {
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;
}
};