From 87b0d3e8d1b23e3fd2fb1571fd72df962660d793 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Mon, 15 Jul 2024 16:18:30 +0200 Subject: [PATCH 1/5] 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'); + }); }); From dc5903421b2bb1c57187b2253772f99b96c328d1 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Mon, 15 Jul 2024 16:21:19 +0200 Subject: [PATCH 2/5] 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; From 8a9a74a7ebb4a1819a45600084ca92a0b7e3048e Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 16 Jul 2024 09:04:58 +0200 Subject: [PATCH 3/5] test: fix ticket e2e --- e2e/paths/05-ticket/01-sale/01_list_sales.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/paths/05-ticket/01-sale/01_list_sales.spec.js b/e2e/paths/05-ticket/01-sale/01_list_sales.spec.js index 5c8eba571..ad0975889 100644 --- a/e2e/paths/05-ticket/01-sale/01_list_sales.spec.js +++ b/e2e/paths/05-ticket/01-sale/01_list_sales.spec.js @@ -57,7 +57,7 @@ describe('Ticket List sale path', () => { let searchValue = 'Melee weapon heavy shield 100cm'; await page.autocompleteSearch(selectors.ticketSales.secondSaleIdAutocomplete, searchValue); await page.waitToClick(selectors.ticketSales.secondSaleQuantityCell); - await page.type(selectors.ticketSales.secondSaleQuantity, '1'); + await page.type(selectors.ticketSales.secondSaleQuantity, '8'); await page.keyboard.press('Enter'); const message = await page.waitForSnackbar(); From b871615e8f5a701cea63a20ae2d1818fe3b435ed Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 16 Jul 2024 10:42:08 +0200 Subject: [PATCH 4/5] fix: worker new if not has provinceFk --- modules/worker/back/methods/worker/new.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/modules/worker/back/methods/worker/new.js b/modules/worker/back/methods/worker/new.js index fad464ae1..bb43fba99 100644 --- a/modules/worker/back/methods/worker/new.js +++ b/modules/worker/back/methods/worker/new.js @@ -193,9 +193,13 @@ module.exports = Self => { } await user.updateAttribute('email', email, myOptions); - const {countryFk} = await Self.app.models.Province.findById(provinceFk, { - fields: ['countryFk'] - }); + let countryFk; + if (provinceFk) { + const province = await Self.app.models.Province.findById(provinceFk, { + fields: ['countryFk'] + }); + countryFk = province.countryFk; + } await models.Worker.create({ id: user.id, firstName, @@ -205,7 +209,6 @@ module.exports = Self => { fi, birth, originCountryFk: countryFk - }, myOptions); if (tx) await tx.commit(); From 2181664c25b63f020cabf8c061104bdd4e202ed6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Tue, 16 Jul 2024 15:14:10 +0200 Subject: [PATCH 5/5] fix: ticket_setProblemTooLittleItemCost ticket_setRisk refs#7213 --- .../vn/procedures/ticket_setProblemTooLittleItemCost.sql | 2 +- db/routines/vn/procedures/ticket_setRisk.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/db/routines/vn/procedures/ticket_setProblemTooLittleItemCost.sql b/db/routines/vn/procedures/ticket_setProblemTooLittleItemCost.sql index 1f41c0716..ac3814c07 100644 --- a/db/routines/vn/procedures/ticket_setProblemTooLittleItemCost.sql +++ b/db/routines/vn/procedures/ticket_setProblemTooLittleItemCost.sql @@ -21,7 +21,7 @@ BEGIN GROUP BY t.id )SELECT ticketFk, ticket_isTooLittle(ticketFk) hasProblem, - ticket_isProblemCalcNeeded(t.id) isProblemCalcNeeded + ticket_isProblemCalcNeeded(ticketFk) isProblemCalcNeeded FROM tickets; CALL ticket_setProblem('isTooLittle'); diff --git a/db/routines/vn/procedures/ticket_setRisk.sql b/db/routines/vn/procedures/ticket_setRisk.sql index 32f3647b7..bd5d1e9f9 100644 --- a/db/routines/vn/procedures/ticket_setRisk.sql +++ b/db/routines/vn/procedures/ticket_setRisk.sql @@ -72,7 +72,7 @@ BEGIN LEFT JOIN receipt r ON r.dated > ui.dated AND r.companyFk = ui.companyFk GROUP BY b.companyFk, ui.dated ) - SELECT ti.ticketFk, r.amount + SELECT ti.ticketFk, r.amount, ti.isProblemCalcNeeded FROM ticket ti JOIN risk r ON r.dated = ti.dated AND r.companyFk = ti.companyFk;