Merge pull request '2666 - Closure invalid email notification' (#489) from 2666-closure_invalid_email into dev
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #489
Reviewed-by: Carlos Jimenez Ruiz <carlosjr@verdnatura.es>
This commit is contained in:
Carlos Jimenez Ruiz 2020-12-23 12:38:29 +00:00
commit 5696ada927
5 changed files with 44 additions and 7 deletions

View File

@ -4,6 +4,8 @@ import './style.scss';
export default class DescriptorPopover extends Popover { export default class DescriptorPopover extends Popover {
show(parent, id) { show(parent, id) {
if (!id) return;
super.show(parent); super.show(parent);
this.id = id; this.id = id;

View File

@ -23,9 +23,9 @@
<vn-td>{{::tracking.state.name}}</vn-td> <vn-td>{{::tracking.state.name}}</vn-td>
<vn-td expand> <vn-td expand>
<span <span
class="link" ng-class="{'link': tracking.worker.id}"
ng-click="workerDescriptor.show($event, tracking.worker.user.id)"> ng-click="workerDescriptor.show($event, tracking.worker.user.id)">
{{::tracking.worker.user.name | dashIfEmpty}} {{::tracking.worker.user.name || 'System' | translate}}
</span> </span>
</vn-td> </vn-td>
<vn-td>{{::tracking.created | date:'dd/MM/yyyy HH:mm'}}</vn-td> <vn-td>{{::tracking.created | date:'dd/MM/yyyy HH:mm'}}</vn-td>

View File

@ -33,7 +33,7 @@
<span <span
ng-class="{'link': log.user.worker.id, 'value': !log.user.worker.id}" ng-class="{'link': log.user.worker.id, 'value': !log.user.worker.id}"
ng-click="$ctrl.showWorkerDescriptor($event, log.user.worker.id)" ng-click="$ctrl.showWorkerDescriptor($event, log.user.worker.id)"
translate>{{::log.user.name | dashIfEmpty}} translate>{{::log.user.name || 'System' | translate}}
</span> </span>
</div> </div>
<div> <div>
@ -54,7 +54,7 @@
<span <span
ng-class="{'link': log.user.worker.id, 'value': !log.user.worker.id}" ng-class="{'link': log.user.worker.id, 'value': !log.user.worker.id}"
ng-click="$ctrl.showWorkerDescriptor($event, log.user.worker.id)" ng-click="$ctrl.showWorkerDescriptor($event, log.user.worker.id)"
translate>{{::log.user.name | dashIfEmpty}} translate>{{::log.user.name || 'System' | translate}}
</span> </span>
</vn-td> </vn-td>
<vn-td class="expendable"> <vn-td class="expendable">
@ -70,7 +70,7 @@
<vn-one ng-repeat="old in log.oldProperties"> <vn-one ng-repeat="old in log.oldProperties">
<div> <div>
<span translate class="label">{{::old.key}}</span><span class="label">: </span> <span translate class="label">{{::old.key}}</span><span class="label">: </span>
<span translate class="value">{{::old.value}}</span> <span translate class="value">{{::old.value | dashIfEmpty}}</span>
</div> </div>
</vn-one> </vn-one>
</vn-td> </vn-td>
@ -81,7 +81,7 @@
id="newInstance"> id="newInstance">
<div> <div>
<span translate class="label">{{::new.key}}</span><span class="label">: </span> <span translate class="label">{{::new.key}}</span><span class="label">: </span>
<span translate class="value">{{::new.value}}</span> <span translate class="value">{{::new.value | dashIfEmpty}}</span>
</div> </div>
</vn-one> </vn-one>
<vn-one <vn-one

View File

@ -9,4 +9,5 @@ Name: Nombre
Creates: Crea Creates: Crea
Updates: Actualiza Updates: Actualiza
Deletes: Elimina Deletes: Elimina
Views: Visualiza Views: Visualiza
System: Sistema

View File

@ -151,6 +151,7 @@ module.exports = app => {
SELECT SELECT
t.id, t.id,
t.clientFk, t.clientFk,
c.name clientName,
c.email recipient, c.email recipient,
c.salesPersonFk, c.salesPersonFk,
c.isToBeMailed, c.isToBeMailed,
@ -196,6 +197,10 @@ module.exports = app => {
const email = new Email('delivery-note-link', args); const email = new Email('delivery-note-link', args);
await email.send(); await email.send();
} catch (error) { } catch (error) {
// Domain not found
if (error.responseCode == 450)
return invalidEmail(ticket);
// Save tickets on a list of failed ids // Save tickets on a list of failed ids
failedtickets.push({ failedtickets.push({
id: ticket.id, 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 <strong>${ticket.id}</strong>
al cliente <strong>${ticket.clientFk} - ${ticket.clientName}</strong>
porque la dirección de email <strong>"${ticket.recipient}"</strong> no es correcta o no está disponible.<br/><br/>
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
});
}
}; };