fix: refs #7569 saveSign use smtp.send and fix link
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Sergio De la torre 2025-01-28 09:54:26 +01:00
parent 6833dbe846
commit a29de13ab3
6 changed files with 29 additions and 32 deletions

View File

@ -253,5 +253,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."
"Ticket has been delivered out of order": "The ticket {{ticket}} of route {{{fullUrl}}} has been delivered out of order."
}

View File

@ -395,6 +395,6 @@
"All tickets have a route order": "Todos los tickets tienen orden de ruta",
"There are tickets to be invoiced": "La zona tiene tickets por facturar",
"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.",
"Ticket has been delivered out of order": "El ticket {{ticket}} de la ruta {{{fullUrl}}} no ha sigo entregado en su orden.",
"Price cannot be blank": "El precio no puede estar en blanco"
}

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."
"Ticket has been delivered out of order": "Le ticket {{ticket}} de la route {{{fullUrl}}} a été livré hors service."
}

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."
"Ticket has been delivered out of order": "O ticket {{ticket}} da rota {{{fullUrl}}} foi entregue fora de ordem."
}

View File

@ -1,4 +1,5 @@
const UserError = require('vn-loopback/util/user-error');
const smtp = require('vn-print/core/smtp');
module.exports = Self => {
Self.remoteMethodCtx('saveSign', {
@ -31,6 +32,7 @@ module.exports = Self => {
Self.saveSign = async(ctx, tickets, location, signedTime, options) => {
const models = Self.app.models;
const myOptions = {userId: ctx.req.accessToken.userId};
const url = await Self.app.models.Url.getUrl('lilium');
let tx;
let ticket;
let dms;
@ -146,11 +148,11 @@ module.exports = Self => {
await ticket.updateAttribute('isSigned', true, myOptions);
const [{stateCode}] = await Self.rawSql(`
SELECT
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
JOIN vn.expeditionStateType est ON est.id = e.stateTypeFk
WHERE e.ticketFk = ?;
`, [ticketId], myOptions);
@ -167,15 +169,15 @@ module.exports = Self => {
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
WHERE t.routeFk = ?
AND s.\`order\` < ?
AND priority <(SELECT t.priority
FROM ticket t
WHERE t.id = ?)`
, [ticket.routeFk, orderState.id, ticket.id], myOptions);
if (ticketIncorrect?.length > 0)
await sendMail(ctx, ticket.routeFk, ticket.id, ticket.zone().name);
await sendMail(ticket.routeFk, ticket.id, ticket.zone().name);
}
if (ticket?.address()?.province()?.country()?.code != 'ES' && ticket.$cmrFk) {
@ -189,26 +191,21 @@ module.exports = Self => {
throw e;
}
await models.Ticket.sendCmrEmail(ctx, externalTickets);
async function sendMail(route, ticket, zoneName) {
const $t = ctx.req.__;
const fullUrl = `<a href="${url}route/${route}/summary">${route}</a>`;
await smtp.send({
to: 'repartos@verdnatura.es',
subject: $t('Incorrect delivery order alert on route', {
route,
zone: zoneName
}),
html: $t('Ticket has been delivered out of order', {
ticket,
fullUrl
})
});
}
};
async function sendMail(ctx, route, ticket, zoneName) {
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,
zone: zoneName
});
const emailBody = $t('Ticket has been delivered out of order', {
ticket,
fullUrl
});
await Self.app.models.Mail.create({
receiver: sendTo,
subject: emailSubject,
body: emailBody
});
}
};

View File

@ -6,7 +6,7 @@ describe('Ticket saveSign()', () => {
getLocale: () => {
return 'en';
},
__: () => {},
__: t => t,
accessToken: {userId: 9}
}
};