diff --git a/db/changes/10003-easter/00-ACL.sql b/db/changes/10003-easter/00-ACL.sql index e92e14f8a..424d0546b 100644 --- a/db/changes/10003-easter/00-ACL.sql +++ b/db/changes/10003-easter/00-ACL.sql @@ -1 +1,2 @@ INSERT INTO `salix`.`ACL` (`id`, `model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES (162, 'InvoiceOut', 'delete', 'WRITE', 'ALLOW', 'ROLE', 'invoicing'); +INSERT INTO `salix`.`ACL` (`id`, `model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES (163, 'InvoiceOut', 'book', 'WRITE', 'ALLOW', 'ROLE', 'invoicing'); diff --git a/modules/invoiceOut/back/methods/invoiceOut/book.js b/modules/invoiceOut/back/methods/invoiceOut/book.js new file mode 100644 index 000000000..eeddcd7f5 --- /dev/null +++ b/modules/invoiceOut/back/methods/invoiceOut/book.js @@ -0,0 +1,26 @@ + +module.exports = Self => { + Self.remoteMethod('book', { + description: 'Book a invoiceOut', + accessType: 'WRITE', + accepts: { + arg: 'ref', + type: 'string', + required: true, + description: 'The invoiceOut ref', + http: {source: 'path'} + }, + returns: { + type: 'object', + root: true + }, + http: { + path: `/:ref/book`, + verb: 'POST' + } + }); + + Self.book = async ref => { + return Self.rawSql(`CALL vn.invoiceOutAgain(?)`, [ref]); + }; +}; diff --git a/modules/invoiceOut/back/methods/invoiceOut/specs/book.spec.js b/modules/invoiceOut/back/methods/invoiceOut/specs/book.spec.js new file mode 100644 index 000000000..383e952b6 --- /dev/null +++ b/modules/invoiceOut/back/methods/invoiceOut/specs/book.spec.js @@ -0,0 +1,32 @@ +const app = require('vn-loopback/server/server'); + +describe('invoiceOut book()', () => { + const invoiceOutId = 5; + let invoiceOutRef; + let OriginalInvoiceOut; + let updatedInvoiceOut; + afterAll(async done => { + updatedInvoiceOut.updateAttributes({booked: OriginalInvoiceOut.booked, hasPdf: OriginalInvoiceOut.hasPdf}); + + done(); + }); + + it('should check that invoice out booked is untainted', async() => { + const invoiceOut = await app.models.InvoiceOut.findById(invoiceOutId); + + expect(invoiceOut.booked).toBeNull(); + expect(invoiceOut.hasPdf).toBeTruthy(); + }); + + it(`should confirm the book property have been updated`, async() => { + OriginalInvoiceOut = await app.models.InvoiceOut.findById(invoiceOutId); + invoiceOutRef = OriginalInvoiceOut.ref; + + await app.models.InvoiceOut.book(invoiceOutRef); + + updatedInvoiceOut = await app.models.InvoiceOut.findById(invoiceOutId); + + expect(updatedInvoiceOut.booked).toEqual(jasmine.any(Object)); + expect(updatedInvoiceOut.hasPdf).toBeFalsy(); + }); +}); diff --git a/modules/invoiceOut/back/models/invoiceOut.js b/modules/invoiceOut/back/models/invoiceOut.js index ccc598989..8046f1dc4 100644 --- a/modules/invoiceOut/back/models/invoiceOut.js +++ b/modules/invoiceOut/back/models/invoiceOut.js @@ -4,4 +4,5 @@ module.exports = Self => { require('../methods/invoiceOut/download')(Self); require('../methods/invoiceOut/regenerate')(Self); require('../methods/invoiceOut/delete')(Self); + require('../methods/invoiceOut/book')(Self); }; diff --git a/modules/invoiceOut/front/descriptor/index.html b/modules/invoiceOut/front/descriptor/index.html index ccc5d424e..211560d28 100644 --- a/modules/invoiceOut/front/descriptor/index.html +++ b/modules/invoiceOut/front/descriptor/index.html @@ -57,4 +57,9 @@ vn-id="deleteConfirmation" on-response="$ctrl.deleteInvoiceOut(response)" question="Are you sure you want to delete this invoice?"> + + \ No newline at end of file diff --git a/modules/invoiceOut/front/descriptor/index.js b/modules/invoiceOut/front/descriptor/index.js index 957b3ac4d..036d0b261 100644 --- a/modules/invoiceOut/front/descriptor/index.js +++ b/modules/invoiceOut/front/descriptor/index.js @@ -11,7 +11,8 @@ class Controller { this.aclService = aclService; this.moreOptions = [ {callback: this.showInvoiceOutPdf, name: 'Show invoice out PDF'}, - {callback: this.showDeleteInvoiceOutDialog, name: 'Delete InvoiceOut', acl: 'invoicing'} + {callback: this.showDeleteInvoiceOutDialog, name: 'Delete InvoiceOut', acl: 'invoicing'}, + {callback: this.showBookInvoiceOutDialog, name: 'Book invoice', acl: 'invoicing'} ]; } @@ -60,6 +61,10 @@ class Controller { this.$scope.deleteConfirmation.show(); } + showBookInvoiceOutDialog() { + this.$scope.bookConfirmation.show(); + } + deleteInvoiceOut(response) { if (response === 'ACCEPT') { const query = `/invoiceOut/api/InvoiceOuts/${this.invoiceOut.id}/delete`; @@ -70,6 +75,16 @@ class Controller { } } + bookInvoiceOut(response) { + if (response === 'ACCEPT') { + const query = `/invoiceOut/api/InvoiceOuts/${this.invoiceOut.ref}/book`; + this.$http.post(query).then(() => { + this.vnApp.showSuccess(this.$translate.instant('InvoiceOut booked')); + this.$state.go('invoiceOut.index'); + }); + } + } + set quicklinks(value = {}) { this._quicklinks = Object.assign(value, this._quicklinks); } diff --git a/modules/invoiceOut/front/descriptor/locale/es.yml b/modules/invoiceOut/front/descriptor/locale/es.yml index 6a77a268c..cedd0e94e 100644 --- a/modules/invoiceOut/front/descriptor/locale/es.yml +++ b/modules/invoiceOut/front/descriptor/locale/es.yml @@ -5,4 +5,7 @@ Invoice ticket list: Listado de tickets de la factura Show invoice out PDF: Ver factura emitida en PDF Delete InvoiceOut: Borrar factura InvoiceOut deleted: Factura eliminada -Are you sure you want to delete this invoice?: Estas seguro de eliminar esta factura? \ No newline at end of file +Are you sure you want to delete this invoice?: Estas seguro de eliminar esta factura? +Book invoice: Asentar factura +InvoiceOut booked: Factura asentada +Are you sure you want to book this invoice?: Estas seguro de querer asentar esta factura? \ No newline at end of file