Merge pull request 'feat: refs #7615 setDeleted' (!2719) from 7615-ticketRefundSetDeleted into dev
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #2719
Reviewed-by: Alex Moreno <alexm@verdnatura.es>
This commit is contained in:
Robert Ferrús 2024-09-05 06:14:42 +00:00
commit 34d0cb76e8
5 changed files with 53 additions and 21 deletions

View File

@ -150,7 +150,7 @@
"Receipt's bank was not found": "Receipt's bank was not found",
"This receipt was not compensated": "This receipt was not compensated",
"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º %d",
"Tickets with associated refunds": "Tickets with associated refunds can't be deleted. This ticket is associated with refund Nº %s",
"It is not possible to modify tracked sales": "It is not possible to modify tracked sales",
"It is not possible to modify sales that their articles are from Floramondo": "It is not possible to modify sales that their articles are from Floramondo",
"It is not possible to modify cloned sales": "It is not possible to modify cloned sales",

View File

@ -272,7 +272,7 @@
"Invoice date can't be less than max date": "La fecha de factura no puede ser inferior a la fecha límite",
"Warehouse inventory not set": "El almacén inventario no está establecido",
"This locker has already been assigned": "Esta taquilla ya ha sido asignada",
"Tickets with associated refunds": "No se pueden borrar tickets con abonos asociados. Este ticket está asociado al abono Nº %d",
"Tickets with associated refunds": "No se pueden borrar tickets con abonos asociados. Este ticket está asociado al abono Nº %s",
"Not exist this branch": "La rama no existe",
"This ticket cannot be signed because it has not been boxed": "Este ticket no puede firmarse porque no ha sido encajado",
"Collection does not exist": "La colección no existe",

View File

@ -272,7 +272,7 @@
"Invoice date can't be less than max date": "La date de la facture ne peut pas être inférieure à la date limite",
"Warehouse inventory not set": "L'inventaire de l'entrepôt n'est pas établi",
"This locker has already been assigned": "Ce casier a déjà été assigné",
"Tickets with associated refunds": "Vous ne pouvez pas supprimer des tickets avec des remboursements associés. Ce ticket est associé au remboursement Nº %d",
"Tickets with associated refunds": "Vous ne pouvez pas supprimer des tickets avec des remboursements associés. Ce ticket est associé au remboursement Nº %s",
"Not exist this branch": "La branche n'existe pas",
"This ticket cannot be signed because it has not been boxed": "Ce ticket ne peut pas être signé car il n'a pas été emballé",
"Collection does not exist": "La collection n'existe pas",

View File

@ -43,11 +43,22 @@ module.exports = Self => {
// Check if ticket has refunds
const ticketRefunds = await models.TicketRefund.find({
where: {originalTicketFk: id},
fields: ['id']}
, myOptions);
if (ticketRefunds.length > 0)
throw new UserError('Tickets with associated refunds', 'TICKET_REFUND', ticketRefunds[0].id);
include: [
{relation: 'refundTicket'}
],
where: {originalTicketFk: id}
}, myOptions);
const allDeleted = ticketRefunds.every(refund => refund.refundTicket().isDeleted);
if (ticketRefunds?.length && !allDeleted) {
const notDeleted = [];
for (const refund of ticketRefunds)
if (!refund.refundTicket().isDeleted) notDeleted.push(refund.refundTicket().id);
throw new UserError('Tickets with associated refunds', 'TICKET_REFUND',
notDeleted.join(', '));
}
// Check if has sales with shelving
const canDeleteTicketWithPartPrepared =

View File

@ -76,6 +76,7 @@ describe('ticket setDeleted()', () => {
}
});
describe('ticket with refund setDeleted()', () => {
it('should show error trying to delete a ticket with a refund', async() => {
const tx = await models.Ticket.beginTransaction({});
let error;
@ -93,4 +94,24 @@ describe('ticket setDeleted()', () => {
expect(error.message).toContain('Tickets with associated refunds');
});
it('should delete a ticket with a refund if ticket refund is deleted', async() => {
const tx = await models.Ticket.beginTransaction({});
try {
const options = {transaction: tx};
const ticketId = 8;
const ticketRefundId = 24;
await models.Ticket.updateAll({id: ticketRefundId}, {isDeleted: true}, options);
await models.Ticket.setDeleted(ctx, ticketId, options);
await tx.rollback();
} catch (e) {
await tx.rollback();
error = e;
}
expect(error.message).not.toContain('Tickets with associated refunds');
});
});
});