add method to check if the ticket has refunds
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Pau 2023-01-31 14:26:57 +01:00
parent 5e9cf65c1b
commit 5c0354bc17
1 changed files with 17 additions and 0 deletions

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;
}
};