diff --git a/db/changes/10370-pickles/00-ACL.sql b/db/changes/10370-pickles/00-ACL.sql new file mode 100644 index 000000000..c5e10dec5 --- /dev/null +++ b/db/changes/10370-pickles/00-ACL.sql @@ -0,0 +1 @@ +UPDATE salix.ACL t SET t.principalId = 'employee' WHERE t.id = 269; diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 2b65efbc1..1635335c4 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -489,11 +489,11 @@ INSERT INTO `vn`.`invoiceOutSerial` (`code`, `description`, `isTaxed`, `taxAreaF INSERT INTO `vn`.`invoiceOut`(`id`, `serial`, `amount`, `issued`,`clientFk`, `created`, `companyFk`, `dued`, `booked`, `bankFk`, `hasPdf`) VALUES - (1, 'T', 1014.24, CURDATE(), 1101, CURDATE(), 442, CURDATE(), CURDATE(), 1, 1), - (2, 'T', 121.36, CURDATE(), 1102, CURDATE(), 442, CURDATE(), CURDATE(), 1, 1), - (3, 'T', 8.88, CURDATE(), 1103, CURDATE(), 442, CURDATE(), CURDATE(), 1, 1), - (4, 'T', 8.88, CURDATE(), 1103, CURDATE(), 442, CURDATE(), CURDATE(), 1, 1), - (5, 'A', 8.88, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 1103, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 442, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 1, 1); + (1, 'T', 1014.24, CURDATE(), 1101, CURDATE(), 442, CURDATE(), CURDATE(), 1, 0), + (2, 'T', 121.36, CURDATE(), 1102, CURDATE(), 442, CURDATE(), CURDATE(), 1, 0), + (3, 'T', 8.88, CURDATE(), 1103, CURDATE(), 442, CURDATE(), CURDATE(), 1, 0), + (4, 'T', 8.88, CURDATE(), 1103, CURDATE(), 442, CURDATE(), CURDATE(), 1, 0), + (5, 'A', 8.88, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 1103, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 442, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 1, 0); UPDATE `vn`.`invoiceOut` SET ref = 'T1111111' WHERE id = 1; UPDATE `vn`.`invoiceOut` SET ref = 'T2222222' WHERE id = 2; diff --git a/modules/invoiceOut/back/methods/invoiceOut/createPdf.js b/modules/invoiceOut/back/methods/invoiceOut/createPdf.js index b866a5cf2..ac79f0d5d 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/createPdf.js +++ b/modules/invoiceOut/back/methods/invoiceOut/createPdf.js @@ -29,7 +29,7 @@ module.exports = Self => { const models = Self.app.models; const headers = ctx.req.headers; const origin = headers.origin; - const authorization = ctx.req.accessToken.id; + const auth = ctx.req.accessToken; if (process.env.NODE_ENV == 'test') throw new UserError(`Action not allowed on the test environment`); @@ -48,13 +48,18 @@ module.exports = Self => { let fileSrc; try { const invoiceOut = await Self.findById(id, null, myOptions); + const hasInvoicing = await models.Account.hasRole(auth.userId, 'invoicing', myOptions); + + if (invoiceOut.hasPdf && !hasInvoicing) + throw new UserError(`You don't have enough privileges`); + await invoiceOut.updateAttributes({ hasPdf: true }, myOptions); const response = got.stream(`${origin}/api/report/invoice`, { query: { - authorization: authorization, + authorization: auth.id, invoiceId: id } }); diff --git a/modules/invoiceOut/back/methods/invoiceOut/specs/filter.spec.js b/modules/invoiceOut/back/methods/invoiceOut/specs/filter.spec.js index 2a530048e..ededc5679 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/specs/filter.spec.js +++ b/modules/invoiceOut/back/methods/invoiceOut/specs/filter.spec.js @@ -61,9 +61,12 @@ describe('InvoiceOut filter()', () => { } }; + const invoiceOut = await models.InvoiceOut.findById(1, null, options); + await invoiceOut.updateAttribute('hasPdf', true, options); + const result = await models.InvoiceOut.filter(ctx, {}, options); - expect(result.length).toEqual(5); + expect(result.length).toEqual(1); await tx.rollback(); } catch (e) { diff --git a/modules/invoiceOut/front/card/index.html b/modules/invoiceOut/front/card/index.html index c70ac06e1..a6f56f775 100644 --- a/modules/invoiceOut/front/card/index.html +++ b/modules/invoiceOut/front/card/index.html @@ -1,5 +1,8 @@ - + + diff --git a/modules/invoiceOut/front/card/index.js b/modules/invoiceOut/front/card/index.js index 093fcdf66..85d03537b 100644 --- a/modules/invoiceOut/front/card/index.js +++ b/modules/invoiceOut/front/card/index.js @@ -10,7 +10,8 @@ class Controller extends ModuleCard { 'issued', 'amount', 'clientFk', - 'companyFk' + 'companyFk', + 'hasPdf' ], include: [ { diff --git a/modules/invoiceOut/front/descriptor/index.html b/modules/invoiceOut/front/descriptor/index.html index 1da487d15..4d9a4ffd8 100644 --- a/modules/invoiceOut/front/descriptor/index.html +++ b/modules/invoiceOut/front/descriptor/index.html @@ -33,11 +33,10 @@ - Regenerate invoice PDF + {{!$ctrl.invoiceOut.hasPdf ? 'Generate PDF invoice': 'Regenerate PDF invoice'}} @@ -101,8 +100,8 @@ + question="Are you sure you want to generate/regenerate the PDF invoice?" + message="Generate PDF invoice document"> diff --git a/modules/invoiceOut/front/descriptor/index.js b/modules/invoiceOut/front/descriptor/index.js index 5a535c9b5..0600ffa5b 100644 --- a/modules/invoiceOut/front/descriptor/index.js +++ b/modules/invoiceOut/front/descriptor/index.js @@ -10,6 +10,10 @@ class Controller extends Descriptor { this.entity = value; } + get hasInvoicing() { + return this.aclService.hasAny(['invoicing']); + } + deleteInvoiceOut() { return this.$http.post(`InvoiceOuts/${this.id}/delete`) .then(() => this.$state.go('invoiceOut.index')) @@ -25,6 +29,7 @@ class Controller extends Descriptor { createInvoicePdf() { const invoiceId = this.invoiceOut.id; return this.$http.post(`InvoiceOuts/${invoiceId}/createPdf`) + .then(() => this.reload()) .then(() => { const snackbarMessage = this.$t( `The invoice PDF document has been regenerated`); @@ -60,6 +65,17 @@ class Controller extends Descriptor { .then(res => this.entity = res.data); } + reload() { + return this.loadData().then(() => { + if (this.cardReload) + this.cardReload(); + }); + } + + cardReload() { + // Prevents error when not defined + } + sendInvoice($data) { return this.vnEmail.send('invoice', { recipientId: this.invoiceOut.client.id, @@ -73,6 +89,7 @@ ngModule.vnComponent('vnInvoiceOutDescriptor', { template: require('./index.html'), controller: Controller, bindings: { - invoiceOut: '<' + invoiceOut: '<', + cardReload: '&' } }); diff --git a/modules/invoiceOut/front/descriptor/index.spec.js b/modules/invoiceOut/front/descriptor/index.spec.js index c16900a0a..6bf49d32b 100644 --- a/modules/invoiceOut/front/descriptor/index.spec.js +++ b/modules/invoiceOut/front/descriptor/index.spec.js @@ -18,6 +18,8 @@ describe('vnInvoiceOutDescriptor', () => { controller.invoiceOut = invoiceOut; + $httpBackend.whenGET(`InvoiceOuts/${invoiceOut.id}`).respond(); + $httpBackend.whenGET(`Tickets/16`).respond(); $httpBackend.expectPOST(`InvoiceOuts/${invoiceOut.id}/createPdf`).respond(); controller.createInvoicePdf(); $httpBackend.flush(); diff --git a/modules/invoiceOut/front/descriptor/locale/es.yml b/modules/invoiceOut/front/descriptor/locale/es.yml index ec9cd3310..3430fe4e7 100644 --- a/modules/invoiceOut/front/descriptor/locale/es.yml +++ b/modules/invoiceOut/front/descriptor/locale/es.yml @@ -12,5 +12,6 @@ Are you sure you want to clone this invoice?: Estas seguro de clonar esta factur Book invoice: Asentar factura InvoiceOut booked: Factura asentada Are you sure you want to book this invoice?: Estas seguro de querer asentar esta factura? -Regenerate invoice PDF: Regenerar PDF factura +Generate PDF invoice: Generar PDF factura +Regenerate PDF invoice: Regenerar PDF factura The invoice PDF document has been regenerated: El documento PDF de la factura ha sido regenerado \ No newline at end of file diff --git a/modules/ticket/front/card/index.html b/modules/ticket/front/card/index.html index a7c70c484..110ffeed4 100644 --- a/modules/ticket/front/card/index.html +++ b/modules/ticket/front/card/index.html @@ -1,5 +1,8 @@ - + + diff --git a/modules/ticket/front/descriptor-menu/index.html b/modules/ticket/front/descriptor-menu/index.html index 4f65fe008..555246f9f 100644 --- a/modules/ticket/front/descriptor-menu/index.html +++ b/modules/ticket/front/descriptor-menu/index.html @@ -80,12 +80,10 @@ - Regenerate invoice PDF + {{!$ctrl.ticket.invoiceOut.hasPdf ? 'Generate PDF invoice': 'Regenerate PDF invoice'}} + question="Are you sure you want to generate/regenerate the PDF invoice?" + message="Generate PDF invoice document"> diff --git a/modules/ticket/front/descriptor-menu/index.js b/modules/ticket/front/descriptor-menu/index.js index 5da9544e2..01709cf33 100644 --- a/modules/ticket/front/descriptor-menu/index.js +++ b/modules/ticket/front/descriptor-menu/index.js @@ -226,6 +226,7 @@ class Controller extends Section { createInvoicePdf() { const invoiceId = this.ticket.invoiceOut.id; return this.$http.post(`InvoiceOuts/${invoiceId}/createPdf`) + .then(() => this.reload()) .then(() => { const snackbarMessage = this.$t( `The invoice PDF document has been regenerated`); diff --git a/modules/ticket/front/descriptor-menu/index.spec.js b/modules/ticket/front/descriptor-menu/index.spec.js index b102b1f44..d10f4e958 100644 --- a/modules/ticket/front/descriptor-menu/index.spec.js +++ b/modules/ticket/front/descriptor-menu/index.spec.js @@ -153,6 +153,7 @@ describe('Ticket Component vnTicketDescriptorMenu', () => { it('should make a query and show a success snackbar', () => { jest.spyOn(controller.vnApp, 'showSuccess'); + $httpBackend.whenGET(`InvoiceOuts/${ticket.invoiceOut.id}`).respond(); $httpBackend.expectPOST(`InvoiceOuts/${ticket.invoiceOut.id}/createPdf`).respond(); controller.createInvoicePdf(); $httpBackend.flush(); diff --git a/modules/ticket/front/descriptor/index.js b/modules/ticket/front/descriptor/index.js index 28d5eb953..172e2767e 100644 --- a/modules/ticket/front/descriptor/index.js +++ b/modules/ticket/front/descriptor/index.js @@ -18,6 +18,10 @@ class Controller extends Descriptor { super.entity = value; } + get hasInvoicing() { + return this.aclService.hasAny(['invoicing']); + } + loadData() { const filter = { include: [ diff --git a/modules/ticket/front/descriptor/locale/es.yml b/modules/ticket/front/descriptor/locale/es.yml index c2b181c97..c72b2e923 100644 --- a/modules/ticket/front/descriptor/locale/es.yml +++ b/modules/ticket/front/descriptor/locale/es.yml @@ -21,8 +21,8 @@ Regenerate invoice PDF: Regenerar PDF factura The invoice PDF document has been regenerated: El documento PDF de la factura ha sido regenerado You are going to invoice this ticket: Vas a facturar este ticket Are you sure you want to invoice this ticket?: ¿Seguro que quieres facturar este ticket? -You are going to regenerate the invoice PDF document: Vas a regenerar el documento PDF de la factura -Are you sure you want to regenerate the invoice PDF document?: ¿Seguro que quieres regenerar el documento PDF de la factura? +Generate PDF invoice document: Generar PDF de la factura +Are you sure you want to generate/regenerate the PDF invoice?: ¿Seguro que quieres generar/regenerar el PDF de la factura? Shipped hour updated: Hora de envio modificada Deleted ticket: Ticket eliminado Recalculate components: Recalcular componentes