From 31a6db5da0cc02f9062e17bb2a07f59632e1abbb Mon Sep 17 00:00:00 2001 From: sergiodt Date: Thu, 12 Dec 2024 20:30:38 +0100 Subject: [PATCH 1/9] feat: refs #7569 refs#7569 sendMail --- loopback/locale/en.json | 8 +-- loopback/locale/es.json | 13 ++--- loopback/locale/fr.json | 12 +++-- loopback/locale/pt.json | 6 ++- .../ticket/back/methods/ticket/saveSign.js | 52 ++++++++++++++++++- .../methods/ticket/specs/saveSign.spec.js | 42 +++++++++++++++ 6 files changed, 116 insertions(+), 17 deletions(-) diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 7372ac9a6..f5c27726b 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -246,6 +246,8 @@ "ticketLostExpedition": "The ticket [{{ticketId}}]({{{ticketUrl}}}) has the following lost expedition:{{ expeditionId }}", "The raid information is not correct": "The raid information is not correct", "Payment method is required": "Payment method is required", - "Sales already moved": "Sales already moved", - "Holidays to past days not available": "Holidays to past days not available" -} + "Sales already moved": "Sales already moved", + "Holidays to past days not available": "Holidays to past days not available", + "Incorrect delivery order alert on route": "Incorrect delivery order alert on route: {{ route }} zone: {{ zone }}", + "Ticket has been delivered out of order": "The ticket {{ ticket }} ({{ fullUrl }}) has been delivered out of order. Tickets that have not been delivered in their route are: {{ ticketsToMail }}" +} \ No newline at end of file diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 0dc8e53a8..2a93407fc 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -388,10 +388,11 @@ "You do not have permission to modify the booked field": "No tienes permisos para modificar el campo contabilizada", "ticketLostExpedition": "El ticket [{{ticketId}}]({{{ticketUrl}}}) tiene la siguiente expedición perdida:{{ expeditionId }}", "The web user's email already exists": "El correo del usuario web ya existe", - "Sales already moved": "Ya han sido transferidas", - "The raid information is not correct": "La información de la redada no es correcta", - "There are tickets to be invoiced": "Hay tickets para esta zona, borralos primero", + "Sales already moved": "Ya han sido transferidas", + "The raid information is not correct": "La información de la redada no es correcta", + "There are tickets to be invoiced": "Hay tickets para esta zona, borralos primero", "An item type with the same code already exists": "Un tipo con el mismo código ya existe", - "Holidays to past days not available": "Las vacaciones a días pasados no están disponibles" -} - + "Holidays to past days not available": "Las vacaciones a días pasados no están disponibles", + "Incorrect delivery order alert on route": "Alerta de orden de entrega incorrecta en ruta: {{ route }} zona: {{ zone }}", + "Ticket has been delivered out of order": "El ticket {{ ticket }} ({{ fullUrl }}) no ha sigo entregado en su orden. Los tickets de la ruta que no han sido entregados en su orden son: {{ ticketsToMail }}" +} \ No newline at end of file diff --git a/loopback/locale/fr.json b/loopback/locale/fr.json index 9941358be..719cbf99c 100644 --- a/loopback/locale/fr.json +++ b/loopback/locale/fr.json @@ -362,9 +362,11 @@ "The invoices have been created but the PDFs could not be generated": "La facture a été émise mais le PDF n'a pas pu être généré", "It has been invoiced but the PDF of refund not be generated": "Il a été facturé mais le PDF de remboursement n'a pas été généré", "Cannot send mail": "Impossible d'envoyer le mail", - "Original invoice not found": "Facture originale introuvable", - "The quantity claimed cannot be greater than the quantity of the line": "Le montant réclamé ne peut pas être supérieur au montant de la ligne", - "You do not have permission to modify the booked field": "Vous n'avez pas la permission de modifier le champ comptabilisé", + "Original invoice not found": "Facture originale introuvable", + "The quantity claimed cannot be greater than the quantity of the line": "Le montant réclamé ne peut pas être supérieur au montant de la ligne", + "You do not have permission to modify the booked field": "Vous n'avez pas la permission de modifier le champ comptabilisé", "ticketLostExpedition": "Le ticket [{{ticketId}}]({{{ticketUrl}}}) a l'expédition perdue suivante : {{expeditionId}}", - "The web user's email already exists": "L'email de l'internaute existe déjà" -} + "The web user's email already exists": "L'email de l'internaute existe déjà", + "Incorrect delivery order alert on route": "Alerte de bon de livraison incorrect sur l'itinéraire: {{ route }} zone : {{ zone }}", + "Ticket has been delivered out of order": "Le ticket {{ticket}} ({{fullUrl}}) a été livré hors ordre. Les tickets qui n'ont pas été livrés dans leur itinéraire sont : {{ticketsToMail}}" +} \ No newline at end of file diff --git a/loopback/locale/pt.json b/loopback/locale/pt.json index e84b30f3d..5dfad3725 100644 --- a/loopback/locale/pt.json +++ b/loopback/locale/pt.json @@ -365,5 +365,7 @@ "Cannot send mail": "Não é possível enviar o email", "The quantity claimed cannot be greater than the quantity of the line": "O valor reclamado não pode ser superior ao valor da linha", "ticketLostExpedition": "O ticket [{{ticketId}}]({{{ticketUrl}}}) tem a seguinte expedição perdida: {{expeditionId}}", - "The web user's email already exists": "O e-mail do utilizador da web já existe." -} + "The web user's email already exists": "O e-mail do utilizador da web já existe.", + "Incorrect delivery order alert on route": "Alerta de ordem de entrega incorreta na rota: {{ route }} zona: {{ zone }}", + "Ticket has been delivered out of order": "O ticket {{ ticket }} ({{ fullUrl }}) foi entregue fora de ordem. Os tickets que não foram entregues na sua rota são: {{ ticketsToMail }}" +} \ 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 ac2a7bc66..eeb753614 100644 --- a/modules/ticket/back/methods/ticket/saveSign.js +++ b/modules/ticket/back/methods/ticket/saveSign.js @@ -28,7 +28,6 @@ module.exports = Self => { verb: 'POST' } }); - Self.saveSign = async(ctx, tickets, location, signedTime, options) => { const models = Self.app.models; const myOptions = {userId: ctx.req.accessToken.userId}; @@ -111,6 +110,12 @@ module.exports = Self => { scope: { fields: ['id'] } + }, + { + relation: 'zone', + scope: { + fields: ['id', 'zoneFk,', 'name'] + } }] }, myOptions); @@ -151,6 +156,29 @@ module.exports = Self => { await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [ticketId, stateCode], myOptions); + if (stateCode == 'DELIVERED' && ticket.priority) { + const orderState = await models.State.findOne({ + where: {code: 'DELIVERED'}, + fields: ['id'] + }, myOptions); + + const ticketsToMail = await Self.rawSql(` + SELECT t.id + FROM ticket t + JOIN ticketState ts ON ts.ticketFk = t.id + JOIN state s ON s.code = ts.code + WHERE t.routeFk = ? + AND s.\`order\` < ? + AND priority <(SELECT t.priority + FROM ticket t + WHERE t.id = ?)` + , [ticket.routeFk, orderState.id, ticket.id], myOptions); + const ticketIds = ticketsToMail.map(row => row.id); + + if (ticketsToMail) + await sendMail(ctx, ticket.routeFk, ticket.id, ticket.zone().name, ticketIds); + } + if (ticket?.address()?.province()?.country()?.code != 'ES' && ticket.$cmrFk) { await models.Ticket.saveCmr(ctx, [ticketId], myOptions); externalTickets.push(ticketId); @@ -163,4 +191,26 @@ module.exports = Self => { } await models.Ticket.sendCmrEmail(ctx, externalTickets); }; + + async function sendMail(ctx, route, ticket, zoneName, ticketsToMail) { + const $t = ctx.req.__; + const url = await Self.app.models.Url.getUrl(); + const sendTo = 'repartos@verdnatura.es'; + const fullUrl = `${url}route/${route}/summary`; + const emailSubject = $t('Incorrect delivery order alert on route', { + route: route, + zone: zoneName + }); + const emailBody = $t('Ticket has been delivered out of order', { + ticket: ticket, + fullUrl: fullUrl, + ticketsToMail: ticketsToMail, + }, {escape: false}); + + await Self.app.models.Mail.create({ + receiver: sendTo, + subject: emailSubject, + body: emailBody + }); + } }; diff --git a/modules/ticket/back/methods/ticket/specs/saveSign.spec.js b/modules/ticket/back/methods/ticket/specs/saveSign.spec.js index e93408973..559c413e5 100644 --- a/modules/ticket/back/methods/ticket/specs/saveSign.spec.js +++ b/modules/ticket/back/methods/ticket/specs/saveSign.spec.js @@ -51,4 +51,46 @@ describe('Ticket saveSign()', () => { expect(ticketTrackingAfter.name).toBe('Entregado en parte'); }); + + fit('should send an email to notify that the delivery order is not correct', async() => { + const tx = await models.Ticket.beginTransaction({}); + const ticketFk = 8; + const priority = 5; + const stateFk = 10; + const stateTicketFk = 2; + const expeditionFk = 11; + const expeditionStateFK = 2; + + let mailCountBefore; + let mailCountAfter; + spyOn(models.Dms, 'uploadFile').and.returnValue([{id: 1}]); + + const options = {transaction: tx}; + const tickets = [ticketFk]; + + const expedition = await models.Expedition.findById(expeditionFk, null, options); + expedition.updateAttribute('stateTypeFk', expeditionStateFK, options); + + const ticket = await models.Ticket.findById(ticketFk, null, options); + ticket.updateAttribute('priority', priority, options); + + const filter = {where: { + ticketFk: ticketFk, + stateFk: stateTicketFk} + }; + try { + const ticketTracking = await models.TicketTracking.findOne(filter, options); + ticketTracking.updateAttribute('stateFk', stateFk, options); + mailCountBefore = await models.Mail.count(options); + await models.Ticket.saveSign(ctx, tickets, null, null, options); + mailCountAfter = await models.Mail.count(options); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + + expect(mailCountAfter).toBeGreaterThan(mailCountBefore); + }); }); From 2c672951c6428f27958ee850f11093db08748c5e Mon Sep 17 00:00:00 2001 From: sergiodt Date: Thu, 12 Dec 2024 20:33:00 +0100 Subject: [PATCH 2/9] fix: refs #7569 refs#8188 add IfNotExists --- modules/ticket/back/methods/ticket/saveSign.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ticket/back/methods/ticket/saveSign.js b/modules/ticket/back/methods/ticket/saveSign.js index eeb753614..6dc90e330 100644 --- a/modules/ticket/back/methods/ticket/saveSign.js +++ b/modules/ticket/back/methods/ticket/saveSign.js @@ -205,7 +205,7 @@ module.exports = Self => { ticket: ticket, fullUrl: fullUrl, ticketsToMail: ticketsToMail, - }, {escape: false}); + }); await Self.app.models.Mail.create({ receiver: sendTo, From 12fa87a93cbb53f7ce95b9cc257f522ff010fdbf Mon Sep 17 00:00:00 2001 From: sergiodt Date: Thu, 9 Jan 2025 16:15:29 +0100 Subject: [PATCH 3/9] =?UTF-8?q?fix:=20refs=20#7569=20refs=C2=B76861=20tick?= =?UTF-8?q?etOrderReserve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- loopback/locale/en.json | 2 +- loopback/locale/es.json | 2 +- loopback/locale/fr.json | 2 +- modules/ticket/back/methods/ticket/saveSign.js | 8 ++++---- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/loopback/locale/en.json b/loopback/locale/en.json index f5c27726b..0f53cf572 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -249,5 +249,5 @@ "Sales already moved": "Sales already moved", "Holidays to past days not available": "Holidays to past days not available", "Incorrect delivery order alert on route": "Incorrect delivery order alert on route: {{ route }} zone: {{ zone }}", - "Ticket has been delivered out of order": "The ticket {{ ticket }} ({{ fullUrl }}) has been delivered out of order. Tickets that have not been delivered in their route are: {{ ticketsToMail }}" + "Ticket has been delivered out of order": "The ticket {{ticket}} {{{fullUrl}}} has been delivered out of order. Tickets that have not been delivered in their route are: {{ ticketsToMail }}" } \ No newline at end of file diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 2a93407fc..163fbaa71 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -394,5 +394,5 @@ "An item type with the same code already exists": "Un tipo con el mismo código ya existe", "Holidays to past days not available": "Las vacaciones a días pasados no están disponibles", "Incorrect delivery order alert on route": "Alerta de orden de entrega incorrecta en ruta: {{ route }} zona: {{ zone }}", - "Ticket has been delivered out of order": "El ticket {{ ticket }} ({{ fullUrl }}) no ha sigo entregado en su orden. Los tickets de la ruta que no han sido entregados en su orden son: {{ ticketsToMail }}" + "Ticket has been delivered out of order": "El ticket {{ticket}} {{{fullUrl}}} no ha sigo entregado en su orden. Los tickets de la ruta que no han sido entregados en su orden son: {{ ticketsToMail }}" } \ No newline at end of file diff --git a/loopback/locale/fr.json b/loopback/locale/fr.json index 719cbf99c..082aedd2b 100644 --- a/loopback/locale/fr.json +++ b/loopback/locale/fr.json @@ -368,5 +368,5 @@ "ticketLostExpedition": "Le ticket [{{ticketId}}]({{{ticketUrl}}}) a l'expédition perdue suivante : {{expeditionId}}", "The web user's email already exists": "L'email de l'internaute existe déjà", "Incorrect delivery order alert on route": "Alerte de bon de livraison incorrect sur l'itinéraire: {{ route }} zone : {{ zone }}", - "Ticket has been delivered out of order": "Le ticket {{ticket}} ({{fullUrl}}) a été livré hors ordre. Les tickets qui n'ont pas été livrés dans leur itinéraire sont : {{ticketsToMail}}" + "Ticket has been delivered out of order": "Le ticket {{ticket}} {{{fullUrl}}} a été livré hors ordre. Les tickets qui n'ont pas été livrés dans leur itinéraire sont : {{ticketsToMail}}" } \ 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 6dc90e330..443b2c1c7 100644 --- a/modules/ticket/back/methods/ticket/saveSign.js +++ b/modules/ticket/back/methods/ticket/saveSign.js @@ -198,13 +198,13 @@ module.exports = Self => { const sendTo = 'repartos@verdnatura.es'; const fullUrl = `${url}route/${route}/summary`; const emailSubject = $t('Incorrect delivery order alert on route', { - route: route, + route, zone: zoneName }); const emailBody = $t('Ticket has been delivered out of order', { - ticket: ticket, - fullUrl: fullUrl, - ticketsToMail: ticketsToMail, + ticket, + fullUrl, + ticketsToMail, }); await Self.app.models.Mail.create({ From a1e1d4fa72fd906a65659fbfb3425fd683c25652 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Fri, 10 Jan 2025 07:20:24 +0100 Subject: [PATCH 4/9] =?UTF-8?q?fix:=20refs=20#7569=20refs=C2=B76861=20tick?= =?UTF-8?q?etOrderReserve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- loopback/locale/pt.json | 2 +- modules/ticket/back/methods/ticket/specs/saveSign.spec.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/loopback/locale/pt.json b/loopback/locale/pt.json index 5dfad3725..1fa16074f 100644 --- a/loopback/locale/pt.json +++ b/loopback/locale/pt.json @@ -367,5 +367,5 @@ "ticketLostExpedition": "O ticket [{{ticketId}}]({{{ticketUrl}}}) tem a seguinte expedição perdida: {{expeditionId}}", "The web user's email already exists": "O e-mail do utilizador da web já existe.", "Incorrect delivery order alert on route": "Alerta de ordem de entrega incorreta na rota: {{ route }} zona: {{ zone }}", - "Ticket has been delivered out of order": "O ticket {{ ticket }} ({{ fullUrl }}) foi entregue fora de ordem. Os tickets que não foram entregues na sua rota são: {{ ticketsToMail }}" + "Ticket has been delivered out of order": "O ticket {{ticket}} {{{fullUrl}}} foi entregue fora de ordem. Os tickets que não foram entregues na sua rota são: {{ ticketsToMail }}" } \ No newline at end of file diff --git a/modules/ticket/back/methods/ticket/specs/saveSign.spec.js b/modules/ticket/back/methods/ticket/specs/saveSign.spec.js index 559c413e5..ed802e311 100644 --- a/modules/ticket/back/methods/ticket/specs/saveSign.spec.js +++ b/modules/ticket/back/methods/ticket/specs/saveSign.spec.js @@ -52,7 +52,7 @@ describe('Ticket saveSign()', () => { expect(ticketTrackingAfter.name).toBe('Entregado en parte'); }); - fit('should send an email to notify that the delivery order is not correct', async() => { + it('should send an email to notify that the delivery order is not correct', async() => { const tx = await models.Ticket.beginTransaction({}); const ticketFk = 8; const priority = 5; From 0340612645ab456997ba034775c0de3cab70aff1 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Mon, 20 Jan 2025 12:35:55 +0100 Subject: [PATCH 5/9] feat: refs #7569 refs#7569 sendEmailNotification --- loopback/locale/en.json | 2 +- loopback/locale/es.json | 3 ++- loopback/locale/fr.json | 2 +- loopback/locale/pt.json | 2 +- modules/ticket/back/methods/ticket/saveSign.js | 12 +++++------- .../back/methods/ticket/specs/saveSign.spec.js | 16 ++++++++++++---- 6 files changed, 22 insertions(+), 15 deletions(-) diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 0f53cf572..d39b1bac5 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -249,5 +249,5 @@ "Sales already moved": "Sales already moved", "Holidays to past days not available": "Holidays to past days not available", "Incorrect delivery order alert on route": "Incorrect delivery order alert on route: {{ route }} zone: {{ zone }}", - "Ticket has been delivered out of order": "The ticket {{ticket}} {{{fullUrl}}} has been delivered out of order. Tickets that have not been delivered in their route are: {{ ticketsToMail }}" + "Ticket has been delivered out of order": "The ticket {{ticket}} {{{fullUrl}}} has been delivered out of order." } \ No newline at end of file diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 163fbaa71..b9207d9cf 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -394,5 +394,6 @@ "An item type with the same code already exists": "Un tipo con el mismo código ya existe", "Holidays to past days not available": "Las vacaciones a días pasados no están disponibles", "Incorrect delivery order alert on route": "Alerta de orden de entrega incorrecta en ruta: {{ route }} zona: {{ zone }}", - "Ticket has been delivered out of order": "El ticket {{ticket}} {{{fullUrl}}} no ha sigo entregado en su orden. Los tickets de la ruta que no han sido entregados en su orden son: {{ ticketsToMail }}" + "Ticket has been delivered out of order": "El ticket {{ticket}} {{{fullUrl}}} no ha sigo entregado en su orden.", + "Price cannot be blank": "Price cannot be blank" } \ No newline at end of file diff --git a/loopback/locale/fr.json b/loopback/locale/fr.json index 082aedd2b..66098bac5 100644 --- a/loopback/locale/fr.json +++ b/loopback/locale/fr.json @@ -368,5 +368,5 @@ "ticketLostExpedition": "Le ticket [{{ticketId}}]({{{ticketUrl}}}) a l'expédition perdue suivante : {{expeditionId}}", "The web user's email already exists": "L'email de l'internaute existe déjà", "Incorrect delivery order alert on route": "Alerte de bon de livraison incorrect sur l'itinéraire: {{ route }} zone : {{ zone }}", - "Ticket has been delivered out of order": "Le ticket {{ticket}} {{{fullUrl}}} a été livré hors ordre. Les tickets qui n'ont pas été livrés dans leur itinéraire sont : {{ticketsToMail}}" + "Ticket has been delivered out of order": "Le ticket {{ticket}} {{{fullUrl}}} a été livré hors ordre." } \ No newline at end of file diff --git a/loopback/locale/pt.json b/loopback/locale/pt.json index 1fa16074f..240d239d6 100644 --- a/loopback/locale/pt.json +++ b/loopback/locale/pt.json @@ -367,5 +367,5 @@ "ticketLostExpedition": "O ticket [{{ticketId}}]({{{ticketUrl}}}) tem a seguinte expedição perdida: {{expeditionId}}", "The web user's email already exists": "O e-mail do utilizador da web já existe.", "Incorrect delivery order alert on route": "Alerta de ordem de entrega incorreta na rota: {{ route }} zona: {{ zone }}", - "Ticket has been delivered out of order": "O ticket {{ticket}} {{{fullUrl}}} foi entregue fora de ordem. Os tickets que não foram entregues na sua rota são: {{ ticketsToMail }}" + "Ticket has been delivered out of order": "O ticket {{ticket}} {{{fullUrl}}} foi entregue fora de ordem." } \ 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 443b2c1c7..9c33797b6 100644 --- a/modules/ticket/back/methods/ticket/saveSign.js +++ b/modules/ticket/back/methods/ticket/saveSign.js @@ -162,7 +162,7 @@ module.exports = Self => { fields: ['id'] }, myOptions); - const ticketsToMail = await Self.rawSql(` + const ticketIncorrect = await Self.rawSql(` SELECT t.id FROM ticket t JOIN ticketState ts ON ts.ticketFk = t.id @@ -173,10 +173,9 @@ module.exports = Self => { FROM ticket t WHERE t.id = ?)` , [ticket.routeFk, orderState.id, ticket.id], myOptions); - const ticketIds = ticketsToMail.map(row => row.id); - if (ticketsToMail) - await sendMail(ctx, ticket.routeFk, ticket.id, ticket.zone().name, ticketIds); + if (ticketIncorrect && ticketIncorrect.length > 0) + await sendMail(ctx, ticket.routeFk, ticket.id, ticket.zone().name); } if (ticket?.address()?.province()?.country()?.code != 'ES' && ticket.$cmrFk) { @@ -192,7 +191,7 @@ module.exports = Self => { await models.Ticket.sendCmrEmail(ctx, externalTickets); }; - async function sendMail(ctx, route, ticket, zoneName, ticketsToMail) { + async function sendMail(ctx, route, ticket, zoneName) { const $t = ctx.req.__; const url = await Self.app.models.Url.getUrl(); const sendTo = 'repartos@verdnatura.es'; @@ -203,8 +202,7 @@ module.exports = Self => { }); const emailBody = $t('Ticket has been delivered out of order', { ticket, - fullUrl, - ticketsToMail, + fullUrl }); await Self.app.models.Mail.create({ diff --git a/modules/ticket/back/methods/ticket/specs/saveSign.spec.js b/modules/ticket/back/methods/ticket/specs/saveSign.spec.js index ed802e311..7098ee1fc 100644 --- a/modules/ticket/back/methods/ticket/specs/saveSign.spec.js +++ b/modules/ticket/back/methods/ticket/specs/saveSign.spec.js @@ -1,14 +1,22 @@ const models = require('vn-loopback/server/server').models; +const LoopBackContext = require('loopback-context'); describe('Ticket saveSign()', () => { let ctx = {req: { getLocale: () => { return 'en'; }, + __: () => {}, accessToken: {userId: 9} - }}; + } + }; + beforeEach(() => { + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ + active: ctx + }); + }); - it(`should throw error if the ticket's alert level is lower than 2`, async() => { + fit(`should throw error if the ticket's alert level is lower than 2`, async() => { const tx = await models.TicketDms.beginTransaction({}); const ticketWithOkState = 12; let error; @@ -27,7 +35,7 @@ describe('Ticket saveSign()', () => { expect(error).toBeDefined(); }); - it('should change state for ticket', async() => { + fit('should change state for ticket', async() => { const tx = await models.Ticket.beginTransaction({}); const ticketWithPackedState = 7; spyOn(models.Dms, 'uploadFile').and.returnValue([{id: 1}]); @@ -52,7 +60,7 @@ describe('Ticket saveSign()', () => { expect(ticketTrackingAfter.name).toBe('Entregado en parte'); }); - it('should send an email to notify that the delivery order is not correct', async() => { + fit('should send an email to notify that the delivery order is not correct', async() => { const tx = await models.Ticket.beginTransaction({}); const ticketFk = 8; const priority = 5; From b5e27707a73f339e2d4d5fbe27d76b3765ca9041 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Mon, 20 Jan 2025 12:36:31 +0100 Subject: [PATCH 6/9] feat: refs #7569 refs#7569 sendEmailNotification --- modules/ticket/back/methods/ticket/specs/saveSign.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/ticket/back/methods/ticket/specs/saveSign.spec.js b/modules/ticket/back/methods/ticket/specs/saveSign.spec.js index 7098ee1fc..9cc262ea0 100644 --- a/modules/ticket/back/methods/ticket/specs/saveSign.spec.js +++ b/modules/ticket/back/methods/ticket/specs/saveSign.spec.js @@ -16,7 +16,7 @@ describe('Ticket saveSign()', () => { }); }); - fit(`should throw error if the ticket's alert level is lower than 2`, async() => { + it(`should throw error if the ticket's alert level is lower than 2`, async() => { const tx = await models.TicketDms.beginTransaction({}); const ticketWithOkState = 12; let error; @@ -35,7 +35,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; spyOn(models.Dms, 'uploadFile').and.returnValue([{id: 1}]); From ef68884fe0b5f656540cfeddf1d3a6f711bd6259 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Mon, 20 Jan 2025 16:27:35 +0100 Subject: [PATCH 7/9] feat: refs #7569 refs#7569 sendEmailNotification --- loopback/locale/es.json | 2 +- modules/ticket/back/methods/ticket/saveSign.js | 2 +- modules/ticket/back/methods/ticket/specs/saveSign.spec.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index b9207d9cf..eff238150 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -395,5 +395,5 @@ "Holidays to past days not available": "Las vacaciones a días pasados no están disponibles", "Incorrect delivery order alert on route": "Alerta de orden de entrega incorrecta en ruta: {{ route }} zona: {{ zone }}", "Ticket has been delivered out of order": "El ticket {{ticket}} {{{fullUrl}}} no ha sigo entregado en su orden.", - "Price cannot be blank": "Price cannot be blank" + "Price cannot be blank": "El precio no puede estar en blanco" } \ 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 9c33797b6..f99311c39 100644 --- a/modules/ticket/back/methods/ticket/saveSign.js +++ b/modules/ticket/back/methods/ticket/saveSign.js @@ -174,7 +174,7 @@ module.exports = Self => { WHERE t.id = ?)` , [ticket.routeFk, orderState.id, ticket.id], myOptions); - if (ticketIncorrect && ticketIncorrect.length > 0) + if (ticketIncorrect?.length > 0) await sendMail(ctx, ticket.routeFk, ticket.id, ticket.zone().name); } diff --git a/modules/ticket/back/methods/ticket/specs/saveSign.spec.js b/modules/ticket/back/methods/ticket/specs/saveSign.spec.js index 9cc262ea0..3b426c2cf 100644 --- a/modules/ticket/back/methods/ticket/specs/saveSign.spec.js +++ b/modules/ticket/back/methods/ticket/specs/saveSign.spec.js @@ -60,7 +60,7 @@ describe('Ticket saveSign()', () => { expect(ticketTrackingAfter.name).toBe('Entregado en parte'); }); - fit('should send an email to notify that the delivery order is not correct', async() => { + it('should send an email to notify that the delivery order is not correct', async() => { const tx = await models.Ticket.beginTransaction({}); const ticketFk = 8; const priority = 5; From eee73f001de867f11a0e68f863a9f40bb0bc0b7e Mon Sep 17 00:00:00 2001 From: sergiodt Date: Tue, 21 Jan 2025 07:00:02 +0100 Subject: [PATCH 8/9] Merge branch 'dev' of https: refs #7569//gitea.verdnatura.es/verdnatura/salix into 7569-sendEmailOrderTicket --- loopback/locale/en.json | 2 -- loopback/locale/es.json | 4 +--- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 4f6374a8f..2c180e204 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -247,8 +247,6 @@ "ticketLostExpedition": "The ticket [{{ticketId}}]({{{ticketUrl}}}) has the following lost expedition:{{ expeditionId }}", "The raid information is not correct": "The raid information is not correct", "Payment method is required": "Payment method is required", - "Sales already moved": "Sales already moved", - "Holidays to past days not available": "Holidays to past days not available", "Price cannot be blank": "Price cannot be blank", "There are tickets to be invoiced": "There are tickets to be invoiced", "The address of the customer must have information about Incoterms and Customs Agent": "The address of the customer must have information about Incoterms and Customs Agent""Sales already moved": "Sales already moved", diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 0203a3bc1..abd2f79a0 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -390,13 +390,11 @@ "The web user's email already exists": "El correo del usuario web ya existe", "Sales already moved": "Ya han sido transferidas", "The raid information is not correct": "La información de la redada no es correcta", - "There are tickets to be invoiced": "Hay tickets para esta zona, borralos primero", "An item type with the same code already exists": "Un tipo con el mismo código ya existe", "Holidays to past days not available": "Las vacaciones a días pasados no están disponibles", "All tickets have a route order": "Todos los tickets tienen orden de ruta", - "Price cannot be blank": "Price cannot be blank", "There are tickets to be invoiced": "La zona tiene tickets por facturar", - "Social name should be uppercase": "La razón social debe ir en mayúscula""Incorrect delivery order alert on route": "Alerta de orden de entrega incorrecta en ruta: {{ route }} zona: {{ zone }}", + "Incorrect delivery order alert on route": "Alerta de orden de entrega incorrecta en ruta: {{ route }} zona: {{ zone }}", "Ticket has been delivered out of order": "El ticket {{ticket}} {{{fullUrl}}} no ha sigo entregado en su orden.", "Price cannot be blank": "El precio no puede estar en blanco" } \ No newline at end of file From c50ff6a43aa27323c9973b976c29da509920f4a6 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Tue, 21 Jan 2025 07:05:42 +0100 Subject: [PATCH 9/9] feat: refs #7569 refs#7569 sendEmailNotification --- loopback/locale/en.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 2c180e204..06428475f 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -249,7 +249,8 @@ "Payment method is required": "Payment method is required", "Price cannot be blank": "Price cannot be blank", "There are tickets to be invoiced": "There are tickets to be invoiced", - "The address of the customer must have information about Incoterms and Customs Agent": "The address of the customer must have information about Incoterms and Customs Agent""Sales already moved": "Sales already moved", + "The address of the customer must have information about Incoterms and Customs Agent": "The address of the customer must have information about Incoterms and Customs Agent", + "Sales already moved": "Sales already moved", "Holidays to past days not available": "Holidays to past days not available", "Incorrect delivery order alert on route": "Incorrect delivery order alert on route: {{ route }} zone: {{ zone }}", "Ticket has been delivered out of order": "The ticket {{ticket}} {{{fullUrl}}} has been delivered out of order."