From 5c0354bc1755f4ba61831f99aa1c0c752643035c Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Tue, 31 Jan 2023 14:26:57 +0100 Subject: [PATCH 1/7] add method to check if the ticket has refunds --- .../ticket/back/methods/ticket/setDeleted.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/modules/ticket/back/methods/ticket/setDeleted.js b/modules/ticket/back/methods/ticket/setDeleted.js index cec8096a6..28488ade6 100644 --- a/modules/ticket/back/methods/ticket/setDeleted.js +++ b/modules/ticket/back/methods/ticket/setDeleted.js @@ -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; + } }; -- 2.40.1 From e9dca9211ce9de3dc4e71ab9684c14e1ee88354c Mon Sep 17 00:00:00 2001 From: alexandre Date: Tue, 28 Feb 2023 13:42:18 +0100 Subject: [PATCH 2/7] refs #5149 checked if ticket has refunds, added translations --- loopback/locale/en.json | 3 ++- loopback/locale/es.json | 3 ++- .../ticket/back/methods/ticket/setDeleted.js | 27 +++++++------------ 3 files changed, 13 insertions(+), 20 deletions(-) diff --git a/loopback/locale/en.json b/loopback/locale/en.json index a406b55a5..ecaee91fa 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -147,5 +147,6 @@ "The sales of the receiver ticket can't be modified": "The sales of the receiver ticket can't be modified", "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" + "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º {{id}}" } diff --git a/loopback/locale/es.json b/loopback/locale/es.json index d65054f37..28a2e866d 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -259,5 +259,6 @@ "Try again": "Vuelve a intentarlo", "Aplicación bloqueada por el usuario 9": "Aplicación bloqueada por el usuario 9", "Failed to upload file": "Error al subir archivo", - "The DOCUWARE PDF document does not exists": "The DOCUWARE PDF document does not exists" + "The DOCUWARE PDF document does not exists": "The DOCUWARE PDF document does not exists", + "Tickets with associated refunds": "No se pueden borrar tickets con abonos asociados. Este ticket está asociado al abono Nº {{id}}" } diff --git a/modules/ticket/back/methods/ticket/setDeleted.js b/modules/ticket/back/methods/ticket/setDeleted.js index 28488ade6..6ebc37d6e 100644 --- a/modules/ticket/back/methods/ticket/setDeleted.js +++ b/modules/ticket/back/methods/ticket/setDeleted.js @@ -42,10 +42,13 @@ 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 ticket has refunds + const ticketRefunds = await models.TicketRefund.find({ + where: {originalTicketFk: id}, + fields: ['id']} + , myOptions); + if (ticketRefunds.length > 0) + throw new UserError($t('Tickets with associated refunds', {id: ticketRefunds[0].id})); // Check if has sales with shelving const isSalesAssistant = await models.Account.hasRole(userId, 'salesAssistant', myOptions); @@ -139,12 +142,12 @@ module.exports = Self => { await models.TicketCollection.destroyById(ticketCollection.id, myOptions); await Self.rawSql(` - DELETE sc + DELETE sc FROM vn.saleGroup sg JOIN vn.sectorCollectionSaleGroup scsg ON scsg.saleGroupFk = sg.id JOIN vn.sectorCollection sc ON sc.id = scsg.sectorCollectionFk JOIN vn.saleGroupDetail sgd ON sgd.saleGroupFk = sg.id - JOIN vn.sale s ON s.id = sgd.saleFk + JOIN vn.sale s ON s.id = sgd.saleFk WHERE s.ticketFk = ?;`, [ticket.id], myOptions); if (tx) await tx.commit(); @@ -155,16 +158,4 @@ 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; - } }; -- 2.40.1 From b2bf7f2727405fa3164c0d22120fce7a2df5dace Mon Sep 17 00:00:00 2001 From: alexandre Date: Tue, 28 Feb 2023 14:29:31 +0100 Subject: [PATCH 3/7] refs #5149 fixing e2e --- db/dump/fixtures.sql | 3 ++ e2e/helpers/selectors.js | 4 +-- e2e/paths/05-ticket/21_future.spec.js | 15 ++++++++-- .../methods/ticket/specs/setDeleted.spec.js | 28 +++++++++++++++++++ 4 files changed, 45 insertions(+), 5 deletions(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 218fcb9ca..3384ec5e5 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2773,3 +2773,6 @@ INSERT INTO `vn`.`workerConfig` (`id`, `businessUpdated`, `roleFk`) VALUES (1, NULL, 1); +INSERT INTO `vn`.`ticketRefund`(`refundTicketFk`, `originalTicketFk`) + VALUES + (1, 30); diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index a1412f431..2603dbef3 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -759,8 +759,8 @@ export default { tableButtonSearch: 'vn-button[vn-tooltip="Search"]', moveButton: 'vn-button[vn-tooltip="Future tickets"]', acceptButton: '.vn-confirm.shown button[response="accept"]', - firstCheck: 'tbody > tr:nth-child(1) > td > vn-check', - multiCheck: 'vn-multi-check', + secondCheck: 'tbody > tr:nth-child(2) > td > vn-check', + thirdCheck: 'tbody > tr:nth-child(3) > td > vn-check', tableId: 'vn-textfield[name="id"]', tableFutureId: 'vn-textfield[name="futureId"]', tableLiters: 'vn-textfield[name="liters"]', diff --git a/e2e/paths/05-ticket/21_future.spec.js b/e2e/paths/05-ticket/21_future.spec.js index 34ae3d688..a4a27587b 100644 --- a/e2e/paths/05-ticket/21_future.spec.js +++ b/e2e/paths/05-ticket/21_future.spec.js @@ -152,13 +152,22 @@ describe('Ticket Future path', () => { await page.waitForNumberOfElements(selectors.ticketFuture.table, 4); }); - it('should check the three last tickets and move to the future', async() => { - await page.waitToClick(selectors.ticketFuture.multiCheck); - await page.waitToClick(selectors.ticketFuture.firstCheck); + it('should check the two tickets and move to the future', async() => { + await page.waitToClick(selectors.ticketFuture.secondCheck); + await page.waitToClick(selectors.ticketFuture.thirdCheck); await page.waitToClick(selectors.ticketFuture.moveButton); await page.waitToClick(selectors.ticketFuture.acceptButton); const message = await page.waitForSnackbar(); expect(message.text).toContain('Tickets moved successfully!'); }); + + it('should show error trying to delete a ticket with a refund', async() => { + await page.waitToClick(selectors.ticketFuture.secondCheck); + await page.waitToClick(selectors.ticketFuture.moveButton); + await page.waitToClick(selectors.ticketFuture.acceptButton); + const message = await page.waitForSnackbar(); + + expect(message.text).toContain('Tickets with associated refunds can\'t be deleted'); + }); }); diff --git a/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js b/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js index 1c17d4d0b..133e8022e 100644 --- a/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js +++ b/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js @@ -101,4 +101,32 @@ describe('ticket setDeleted()', () => { throw e; } }); + + it('should show error trying to delete a ticket with a refund', async() => { + const tx = await models.Ticket.beginTransaction({}); + let error; + try { + const options = {transaction: tx}; + + const ctx = { + req: { + accessToken: {userId: 9}, + headers: {origin: 'http://localhost:5000'}, + } + }; + ctx.req.__ = value => { + return value; + }; + + const ticketId = 30; + await models.Ticket.setDeleted(ctx, ticketId, options); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + error = e; + } + + expect(error.message).toContain('Tickets with associated refunds'); + }); }); -- 2.40.1 From 6eab4bbe9475b3b13391686979f6eacbb3a3f6a7 Mon Sep 17 00:00:00 2001 From: alexandre Date: Wed, 1 Mar 2023 08:15:58 +0100 Subject: [PATCH 4/7] refs #5149 fixing tests --- db/dump/fixtures.sql | 2 +- e2e/helpers/selectors.js | 6 ++++-- e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js | 12 ++++++++++++ e2e/paths/05-ticket/21_future.spec.js | 15 +++------------ 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 3384ec5e5..81fadf18c 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2775,4 +2775,4 @@ INSERT INTO `vn`.`workerConfig` (`id`, `businessUpdated`, `roleFk`) INSERT INTO `vn`.`ticketRefund`(`refundTicketFk`, `originalTicketFk`) VALUES - (1, 30); + (1, 31); diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index 2603dbef3..4ed2d5719 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -22,6 +22,7 @@ export default { userConfigSecondAutocomplete: '#localBank', userConfigThirdAutocomplete: '#localCompany', acceptButton: '.vn-confirm.shown button[response=accept]', + cancelButton: '.vn-confirm.shown input[response=cancel]', searchButton: 'vn-searchbar vn-icon[icon="search"]' }, moduleIndex: { @@ -759,8 +760,8 @@ export default { tableButtonSearch: 'vn-button[vn-tooltip="Search"]', moveButton: 'vn-button[vn-tooltip="Future tickets"]', acceptButton: '.vn-confirm.shown button[response="accept"]', - secondCheck: 'tbody > tr:nth-child(2) > td > vn-check', - thirdCheck: 'tbody > tr:nth-child(3) > td > vn-check', + firstCheck: 'tbody > tr:nth-child(1) > td > vn-check', + multiCheck: 'vn-multi-check', tableId: 'vn-textfield[name="id"]', tableFutureId: 'vn-textfield[name="futureId"]', tableLiters: 'vn-textfield[name="liters"]', @@ -784,6 +785,7 @@ export default { tableButtonSearch: 'vn-button[vn-tooltip="Search"]', moveButton: 'vn-button[vn-tooltip="Advance tickets"]', acceptButton: '.vn-confirm.shown button[response="accept"]', + firstCheck: 'tbody > tr:nth-child(1) > td > vn-check', multiCheck: 'vn-multi-check', tableId: 'vn-textfield[name="id"]', tableFutureId: 'vn-textfield[name="futureId"]', diff --git a/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js b/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js index 9d6fddbe6..ec27be496 100644 --- a/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js +++ b/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js @@ -226,9 +226,21 @@ describe('Ticket Edit sale path', () => { await page.waitToClick(selectors.ticketSales.firstSaleCheckbox); await page.waitToClick(selectors.ticketSales.moreMenu); await page.waitToClick(selectors.ticketSales.moreMenuRefund); + await page.waitForSnackbar(); await page.waitForState('ticket.card.sale'); }); + it('should show error trying to delete a ticket with a refund', async() => { + await page.accessToSearchResult('16'); + await page.waitToClick(selectors.ticketDescriptor.moreMenu); + await page.waitToClick(selectors.ticketDescriptor.moreMenuDeleteTicket); + await page.waitToClick(selectors.globalItems.acceptButton); + const message = await page.waitForSnackbar(); + + expect(message.text).toContain('Tickets with associated refunds can\'t be deleted'); + await page.waitToClick(selectors.globalItems.cancelButton); + }); + it('should select the third sale and create a claim of it', async() => { await page.accessToSearchResult('16'); await page.accessToSection('ticket.card.sale'); diff --git a/e2e/paths/05-ticket/21_future.spec.js b/e2e/paths/05-ticket/21_future.spec.js index a4a27587b..34ae3d688 100644 --- a/e2e/paths/05-ticket/21_future.spec.js +++ b/e2e/paths/05-ticket/21_future.spec.js @@ -152,22 +152,13 @@ describe('Ticket Future path', () => { await page.waitForNumberOfElements(selectors.ticketFuture.table, 4); }); - it('should check the two tickets and move to the future', async() => { - await page.waitToClick(selectors.ticketFuture.secondCheck); - await page.waitToClick(selectors.ticketFuture.thirdCheck); + it('should check the three last tickets and move to the future', async() => { + await page.waitToClick(selectors.ticketFuture.multiCheck); + await page.waitToClick(selectors.ticketFuture.firstCheck); await page.waitToClick(selectors.ticketFuture.moveButton); await page.waitToClick(selectors.ticketFuture.acceptButton); const message = await page.waitForSnackbar(); expect(message.text).toContain('Tickets moved successfully!'); }); - - it('should show error trying to delete a ticket with a refund', async() => { - await page.waitToClick(selectors.ticketFuture.secondCheck); - await page.waitToClick(selectors.ticketFuture.moveButton); - await page.waitToClick(selectors.ticketFuture.acceptButton); - const message = await page.waitForSnackbar(); - - expect(message.text).toContain('Tickets with associated refunds can\'t be deleted'); - }); }); -- 2.40.1 From fb940fff52408a9103cfaccd47ea1ca171890c1e Mon Sep 17 00:00:00 2001 From: alexandre Date: Wed, 1 Mar 2023 08:31:45 +0100 Subject: [PATCH 5/7] . --- e2e/helpers/selectors.js | 1 - 1 file changed, 1 deletion(-) diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index 24565f7b8..9840696c2 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -785,7 +785,6 @@ export default { moveButton: 'vn-button[vn-tooltip="Advance tickets"]', acceptButton: '.vn-confirm.shown button[response="accept"]', firstCheck: 'tbody > tr:nth-child(1) > td > vn-check', - multiCheck: 'vn-multi-check', tableId: 'vn-textfield[name="id"]', tableFutureId: 'vn-textfield[name="futureId"]', tableLiters: 'vn-textfield[name="liters"]', -- 2.40.1 From 915c598c0c30a25286f4bfbc7502bc6df917755e Mon Sep 17 00:00:00 2001 From: alexandre Date: Wed, 1 Mar 2023 09:04:53 +0100 Subject: [PATCH 6/7] fixed tests --- db/dump/fixtures.sql | 2 +- modules/ticket/back/methods/ticket/specs/setDeleted.spec.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 403523319..5af9b9eeb 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2789,7 +2789,7 @@ INSERT INTO `vn`.`workerConfig` (`id`, `businessUpdated`, `roleFk`) INSERT INTO `vn`.`ticketRefund`(`refundTicketFk`, `originalTicketFk`) VALUES - (1, 31); + (1, 12); INSERT INTO `vn`.`deviceProductionModels` (`code`) VALUES diff --git a/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js b/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js index 133e8022e..b2e70697a 100644 --- a/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js +++ b/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js @@ -118,7 +118,7 @@ describe('ticket setDeleted()', () => { return value; }; - const ticketId = 30; + const ticketId = 12; await models.Ticket.setDeleted(ctx, ticketId, options); await tx.rollback(); -- 2.40.1 From 314c5c27eb3c9568f36ad7cb4286f02ab97e2247 Mon Sep 17 00:00:00 2001 From: alexandre Date: Wed, 1 Mar 2023 09:09:05 +0100 Subject: [PATCH 7/7] refs #5149 changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3388ceb73..b1f258ad9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - (Trabajador -> PDA) Nueva sección ### Changed -- +- (Ticket -> Borrar ticket) Restringido el borrado de tickets con abono ### Fixed - -- 2.40.1