From 6416b0ad799f9abad1cc03e62ae8423bf6ce231c Mon Sep 17 00:00:00 2001 From: joan Date: Tue, 22 Dec 2020 14:56:21 +0100 Subject: [PATCH] 2666 - Closure invalid email notification --- .../components/descriptor-popover/index.js | 2 ++ .../ticket/front/tracking/index/index.html | 4 +-- modules/worker/front/log/index.html | 8 ++--- modules/worker/front/log/locale/es.yml | 3 +- print/methods/closure.js | 34 +++++++++++++++++++ 5 files changed, 44 insertions(+), 7 deletions(-) diff --git a/front/salix/components/descriptor-popover/index.js b/front/salix/components/descriptor-popover/index.js index b746f5c81..3ec5be1ae 100644 --- a/front/salix/components/descriptor-popover/index.js +++ b/front/salix/components/descriptor-popover/index.js @@ -4,6 +4,8 @@ import './style.scss'; export default class DescriptorPopover extends Popover { show(parent, id) { + if (!id) return; + super.show(parent); this.id = id; diff --git a/modules/ticket/front/tracking/index/index.html b/modules/ticket/front/tracking/index/index.html index 42d2197d0..7cb9431ab 100644 --- a/modules/ticket/front/tracking/index/index.html +++ b/modules/ticket/front/tracking/index/index.html @@ -23,9 +23,9 @@ {{::tracking.state.name}} - {{::tracking.worker.user.name | dashIfEmpty}} + {{::tracking.worker.user.name || 'System' | translate}} {{::tracking.created | date:'dd/MM/yyyy HH:mm'}} diff --git a/modules/worker/front/log/index.html b/modules/worker/front/log/index.html index bfa60a8c3..b7cf9fc77 100644 --- a/modules/worker/front/log/index.html +++ b/modules/worker/front/log/index.html @@ -33,7 +33,7 @@ {{::log.user.name | dashIfEmpty}} + translate>{{::log.user.name || 'System' | translate}}
@@ -54,7 +54,7 @@ {{::log.user.name | dashIfEmpty}} + translate>{{::log.user.name || 'System' | translate}} @@ -70,7 +70,7 @@
{{::old.key}}: - {{::old.value}} + {{::old.value | dashIfEmpty}}
@@ -81,7 +81,7 @@ id="newInstance">
{{::new.key}}: - {{::new.value}} + {{::new.value | dashIfEmpty}}
{ SELECT t.id, t.clientFk, + c.name clientName, c.email recipient, c.salesPersonFk, c.isToBeMailed, @@ -196,6 +197,10 @@ module.exports = app => { const email = new Email('delivery-note-link', args); await email.send(); } catch (error) { + // Domain not found + if (error.responseCode == 450) + return invalidEmail(ticket); + // Save tickets on a list of failed ids failedtickets.push({ id: ticket.id, @@ -220,4 +225,33 @@ module.exports = app => { }); } } + + async function invalidEmail(ticket) { + await db.rawSql(`UPDATE client SET email = NULL WHERE id = :clientId`, { + clientId: ticket.clientFk + }); + + const oldInstance = `{"email": "${ticket.recipient}"}`; + const newInstance = `{"email": ""}`; + await db.rawSql(` + INSERT INTO clientLog (originFk, userFk, action, changedModel, oldInstance, newInstance) + VALUES (:clientId, :userId, 'UPDATE', 'Client', :oldInstance, :newInstance)`, { + clientId: ticket.clientFk, + userId: null, + oldInstance: oldInstance, + newInstance: newInstance + }); + + const body = `No se ha podido enviar el albarán ${ticket.id} + al cliente ${ticket.clientFk} - ${ticket.clientName} + porque la dirección de email "${ticket.recipient}" no es correcta o no está disponible.

+ Para evitar que se repita este error, se ha eliminado la dirección de email de la ficha del cliente. + Actualiza la dirección de email con una correcta.`; + + smtp.send({ + to: ticket.salesPersonEmail, + subject: 'No se ha podido enviar el albarán', + html: body + }); + } };