feat: refs #7615 setDeleted #2719
|
@ -150,7 +150,7 @@
|
||||||
"Receipt's bank was not found": "Receipt's bank was not found",
|
"Receipt's bank was not found": "Receipt's bank was not found",
|
||||||
"This receipt was not compensated": "This receipt was not compensated",
|
"This receipt was not compensated": "This receipt was not compensated",
|
||||||
"Client's email was not found": "Client's email was not found",
|
"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 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 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",
|
"It is not possible to modify cloned sales": "It is not possible to modify cloned sales",
|
||||||
|
|
|
@ -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",
|
"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",
|
"Warehouse inventory not set": "El almacén inventario no está establecido",
|
||||||
"This locker has already been assigned": "Esta taquilla ya ha sido asignada",
|
"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",
|
"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",
|
"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",
|
"Collection does not exist": "La colección no existe",
|
||||||
|
|
|
@ -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",
|
"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",
|
"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é",
|
"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",
|
"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é",
|
"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",
|
"Collection does not exist": "La collection n'existe pas",
|
||||||
|
|
|
@ -43,11 +43,22 @@ module.exports = Self => {
|
||||||
|
|
||||||
// Check if ticket has refunds
|
// Check if ticket has refunds
|
||||||
const ticketRefunds = await models.TicketRefund.find({
|
const ticketRefunds = await models.TicketRefund.find({
|
||||||
where: {originalTicketFk: id},
|
include: [
|
||||||
fields: ['id']}
|
{relation: 'refundTicket'}
|
||||||
, myOptions);
|
],
|
||||||
if (ticketRefunds.length > 0)
|
where: {originalTicketFk: id}
|
||||||
throw new UserError('Tickets with associated refunds', 'TICKET_REFUND', ticketRefunds[0].id);
|
}, myOptions);
|
||||||
|
|
||||||
|
const allDeleted = ticketRefunds.every(refund => refund.refundTicket().isDeleted);
|
||||||
robert marked this conversation as resolved
|
|||||||
|
|
||||||
|
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
|
// Check if has sales with shelving
|
||||||
const canDeleteTicketWithPartPrepared =
|
const canDeleteTicketWithPartPrepared =
|
||||||
|
|
|
@ -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() => {
|
it('should show error trying to delete a ticket with a refund', async() => {
|
||||||
const tx = await models.Ticket.beginTransaction({});
|
const tx = await models.Ticket.beginTransaction({});
|
||||||
let error;
|
let error;
|
||||||
|
@ -93,4 +94,24 @@ describe('ticket setDeleted()', () => {
|
||||||
|
|
||||||
expect(error.message).toContain('Tickets with associated refunds');
|
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');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Li clavaria un test de back