diff --git a/modules/invoiceOut/back/methods/invoiceOut/invoiceClient.js b/modules/invoiceOut/back/methods/invoiceOut/invoiceClient.js index 7c8742caa..6667b5f0e 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/invoiceClient.js +++ b/modules/invoiceOut/back/methods/invoiceOut/invoiceClient.js @@ -63,6 +63,7 @@ module.exports = Self => { } let invoiceId; + let invoiceOut; try { const client = await models.Client.findById(args.clientId, { fields: ['id', 'hasToInvoiceByAddress'] @@ -119,25 +120,24 @@ module.exports = Self => { await notifyFailures(ctx, failedClient, myOptions); } + invoiceOut = await models.InvoiceOut.findById(invoiceId, { + include: { + relation: 'client' + } + }, myOptions); + if (tx) await tx.commit(); } catch (e) { if (tx) await tx.rollback(); throw e; } - const invoiceOut = await models.InvoiceOut.findById(invoiceId, { - include: { - relation: 'client' - } - }); ctx.args = { reference: invoiceOut.ref, recipientId: invoiceOut.clientFk, recipient: invoiceOut.client().email }; - try { - await models.InvoiceOut.invoiceEmail(ctx); - } catch (err) {} + await models.InvoiceOut.invoiceEmail(ctx); return invoiceId; };