fixes #5149 ticket.descriptor-menu Eliminar ticket, debe comprobar que no existe un abono #1348
|
@ -42,6 +42,11 @@ 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);
|
||||||
|
|
||||||
|
if (hasRefunds)
|
||||||
|
throw new UserError(`You must delete the refund id %d first`, 'DELETE_REFUND_FIRST', hasRefunds);
|
||||||
|
|
||||||
// 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);
|
||||||
const sales = await models.Sale.find({
|
const sales = await models.Sale.find({
|
||||||
|
@ -150,4 +155,16 @@ 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