feat: refs #7569 refs#7569 sendEmailNotification
gitea/salix/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Sergio De la torre 2025-01-20 12:35:55 +01:00
parent a1e1d4fa72
commit 0340612645
6 changed files with 22 additions and 15 deletions

View File

@ -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."
}

View File

@ -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"
}

View File

@ -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."
}

View File

@ -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."
}

View File

@ -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({

View File

@ -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;