diff --git a/modules/invoiceOut/back/methods/invoiceOut/createPdf.js b/modules/invoiceOut/back/methods/invoiceOut/createPdf.js index 15ba79ba0..f264cdd43 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/createPdf.js +++ b/modules/invoiceOut/back/methods/invoiceOut/createPdf.js @@ -61,12 +61,12 @@ module.exports = Self => { const created = invoiceOut.created; const year = created.getFullYear().toString(); - const month = created.getMonth().toString(); + const month = (created.getMonth() + 1).toString(); const day = created.getDate().toString(); const container = await models.InvoiceContainer.container(year); const rootPath = container.client.root; - const fileName = `${invoiceOut.ref}.pdf`; + const fileName = `${year}${invoiceOut.ref}.pdf`; const src = path.join(rootPath, year, month, day); fileSrc = path.join(src, fileName); diff --git a/modules/invoiceOut/back/methods/invoiceOut/download.js b/modules/invoiceOut/back/methods/invoiceOut/download.js index 21459e228..a8ec7e945 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/download.js +++ b/modules/invoiceOut/back/methods/invoiceOut/download.js @@ -47,13 +47,13 @@ module.exports = Self => { const created = invoiceOut.created; const year = created.getFullYear().toString(); - const month = created.getMonth().toString(); + const month = (created.getMonth() + 1).toString(); const day = created.getDate().toString(); const container = await models.InvoiceContainer.container(year); const rootPath = container.client.root; const src = path.join(rootPath, year, month, day); - const fileName = `${invoiceOut.ref}.pdf`; + const fileName = `${year}${invoiceOut.ref}.pdf`; const fileSrc = path.join(src, fileName); // Creates PDF document if it has not been created @@ -63,13 +63,14 @@ module.exports = Self => { const file = { path: fileSrc, contentType: 'application/pdf', - name: `${id}.pdf` + name: fileName }; await fs.access(file.path); let stream = fs.createReadStream(file.path); return [stream, file.contentType, `filename="${file.name}"`]; } catch (error) { + console.log(error); if (error.code === 'ENOENT') throw new UserError('The PDF document does not exists'); diff --git a/modules/invoiceOut/back/methods/invoiceOut/specs/download.spec.js b/modules/invoiceOut/back/methods/invoiceOut/specs/download.spec.js index 631991161..3a46311ad 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/specs/download.spec.js +++ b/modules/invoiceOut/back/methods/invoiceOut/specs/download.spec.js @@ -23,6 +23,6 @@ describe('InvoiceOut download()', () => { const result = await models.InvoiceOut.download(ctx, invoiceId); expect(result[1]).toEqual('application/pdf'); - expect(result[2]).toEqual('filename="1.pdf"'); + expect(result[2]).toEqual('filename="2021T1111111.pdf"'); }); });