diff --git a/modules/invoiceOut/back/methods/invoiceOut/transferInvoice.js b/modules/invoiceOut/back/methods/invoiceOut/transferInvoice.js index 782eaf6d8..3372c84dd 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/transferInvoice.js +++ b/modules/invoiceOut/back/methods/invoiceOut/transferInvoice.js @@ -50,6 +50,7 @@ module.exports = Self => { Self.transferInvoice = async(ctx, options) => { const models = Self.app.models; const myOptions = {userId: ctx.req.accessToken.userId}; + let makePdf = false; const {id, refFk, newClientFk, cplusRectificationTypeFk, siiTypeInvoiceOutFk, invoiceCorrectionTypeFk} = ctx.args; let tx; if (typeof options == 'object') @@ -63,6 +64,7 @@ module.exports = Self => { if (!myOptions.transaction) { tx = await Self.beginTransaction({}); myOptions.transaction = tx; + makePdf = true; } try { const filterRef = {where: {refFk: refFk}}; @@ -93,11 +95,9 @@ module.exports = Self => { await models.Ticket.invoiceTickets(ctx, refundTicketIds, invoiceCorrection, myOptions); const [invoiceId] = await models.Ticket.invoiceTickets(ctx, clonedTicketIds, null, myOptions); - if (tx) { - await tx.commit(); - await models.InvoiceOut.makePdfAndNotify(ctx, invoiceId, null); - } + tx && await tx.commit(); + makePdf && await models.InvoiceOut.makePdfAndNotify(ctx, invoiceId, null); return invoiceId; } catch (e) { if (tx) await tx.rollback(); diff --git a/modules/ticket/back/methods/ticket/invoiceTickets.js b/modules/ticket/back/methods/ticket/invoiceTickets.js index 06429836e..162ddda03 100644 --- a/modules/ticket/back/methods/ticket/invoiceTickets.js +++ b/modules/ticket/back/methods/ticket/invoiceTickets.js @@ -32,6 +32,7 @@ module.exports = function(Self) { const models = Self.app.models; const date = Date.vnNew(); date.setHours(0, 0, 0, 0); + let makePdf = false; const myOptions = {userId: ctx.req.accessToken.userId}; let tx; @@ -42,6 +43,7 @@ module.exports = function(Self) { if (!myOptions.transaction) { tx = await Self.beginTransaction({}); myOptions.transaction = tx; + makePdf = true; } let invoicesIds = []; @@ -81,7 +83,7 @@ module.exports = function(Self) { if (tx) await tx.rollback(); throw e; } - if (tx) { + if (makePdf) { for (const invoiceId of invoicesIds) await models.InvoiceOut.makePdfAndNotify(ctx, invoiceId, null); }