add method to check if the ticket has refunds
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
5e9cf65c1b
commit
5c0354bc17
|
@ -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