From 87b0d3e8d1b23e3fd2fb1571fd72df962660d793 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Mon, 15 Jul 2024 16:18:30 +0200 Subject: [PATCH 1/2] refs newStatePartial refs #7642 --- .../11154-greenBamboo/00-firstScript.sql | 2 ++ .../11154-greenBamboo/00-firstScript.vn.sql | 2 ++ .../ticket/back/methods/ticket/saveSign.js | 11 ++++++- .../methods/ticket/specs/saveSign.spec.js | 32 +++++++++++++++++++ 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 db/versions/11154-greenBamboo/00-firstScript.sql create mode 100644 db/versions/11154-greenBamboo/00-firstScript.vn.sql diff --git a/db/versions/11154-greenBamboo/00-firstScript.sql b/db/versions/11154-greenBamboo/00-firstScript.sql new file mode 100644 index 000000000..72a9389ec --- /dev/null +++ b/db/versions/11154-greenBamboo/00-firstScript.sql @@ -0,0 +1,2 @@ + +ALTER TABLE vn.ticketLastState MODIFY COLUMN name varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL; \ No newline at end of file diff --git a/db/versions/11154-greenBamboo/00-firstScript.vn.sql b/db/versions/11154-greenBamboo/00-firstScript.vn.sql new file mode 100644 index 000000000..374c9a031 --- /dev/null +++ b/db/versions/11154-greenBamboo/00-firstScript.vn.sql @@ -0,0 +1,2 @@ + +INSERT INTO vn.state ( name, `order`, alertLevel, code, sectorProdPriority, nextStateFk, isPreviousPreparable, isPicked, isPreparable, semaphore, isPrintable, isOK, graphCategory, isNotValidated, classColor) VALUES('Entregado en parte', 13, 3, 'PARTIAL_DELIVERED', NULL, 16, 0, 1, 0, 0, 0, 0, 0, 0, NULL); \ No newline at end of file diff --git a/modules/ticket/back/methods/ticket/saveSign.js b/modules/ticket/back/methods/ticket/saveSign.js index ed54a5074..a751bd93a 100644 --- a/modules/ticket/back/methods/ticket/saveSign.js +++ b/modules/ticket/back/methods/ticket/saveSign.js @@ -140,7 +140,16 @@ module.exports = Self => { await models.TicketDms.create({ticketFk: ticket.id, dmsFk: dms[0].id}, myOptions); await ticket.updateAttribute('isSigned', true, myOptions); - await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [ticketId, 'DELIVERED'], myOptions); + const [{stateCode}] = await Self.rawSql(` + SELECT + IF((SUM(CASE WHEN est.code = 'DELIVERED' THEN 1 ELSE 0 END) = COUNT(*)), + 'DELIVERED','PARTIAL_DELIVERED') stateCode + FROM vn.expedition e + JOIN vn.expeditionStateType est ON est.id = e.stateTypeFk + WHERE e.ticketFk = ?; + `, [ticketId], myOptions); + + await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [ticketId, stateCode], myOptions); if (ticket?.address()?.province()?.country()?.code != 'ES' && ticket.cmrFk) { await models.Ticket.saveCmr(ctx, [ticketId], myOptions); diff --git a/modules/ticket/back/methods/ticket/specs/saveSign.spec.js b/modules/ticket/back/methods/ticket/specs/saveSign.spec.js index 792e9e824..09d3e1eab 100644 --- a/modules/ticket/back/methods/ticket/specs/saveSign.spec.js +++ b/modules/ticket/back/methods/ticket/specs/saveSign.spec.js @@ -26,4 +26,36 @@ describe('Ticket saveSign()', () => { expect(error).toBeDefined(); }); + + fit('should change state for ticket', async() => { + const tx = await models.Ticket.beginTransaction({}); + const ticketWithPackedState = 7; + const ticketStateId = 16; + const ticketCode = 'PARTIAL_DELIVERED'; + spyOn(models.Dms, 'uploadFile').and.returnValue([{id: 1}]); + let ticketTrackingAfter; + + try { + const options = {transaction: tx}; + const tickets = [ticketWithPackedState]; + + const state = await models.State.findById(ticketStateId, null, options); + await state.updateAttributes({ + code: ticketCode, + name: ticketCode + }, options); + + await models.Ticket.saveSign(ctx, tickets, null, null, options); + ticketTrackingAfter = await models.TicketLastState.findOne({ + where: {ticketFk: ticketWithPackedState} + }, options); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + + expect(ticketTrackingAfter.name).toBe('PARTIAL_DELIVERED'); + }); }); -- 2.40.1 From dc5903421b2bb1c57187b2253772f99b96c328d1 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Mon, 15 Jul 2024 16:21:19 +0200 Subject: [PATCH 2/2] refs newStatePartial refs #7642 --- modules/ticket/back/methods/ticket/specs/saveSign.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ticket/back/methods/ticket/specs/saveSign.spec.js b/modules/ticket/back/methods/ticket/specs/saveSign.spec.js index 09d3e1eab..53ab42364 100644 --- a/modules/ticket/back/methods/ticket/specs/saveSign.spec.js +++ b/modules/ticket/back/methods/ticket/specs/saveSign.spec.js @@ -27,7 +27,7 @@ describe('Ticket saveSign()', () => { expect(error).toBeDefined(); }); - fit('should change state for ticket', async() => { + it('should change state for ticket', async() => { const tx = await models.Ticket.beginTransaction({}); const ticketWithPackedState = 7; const ticketStateId = 16; -- 2.40.1