diff --git a/modules/invoiceOut/back/methods/invoiceOut/refundAndInvoice.js b/modules/invoiceOut/back/methods/invoiceOut/refundAndInvoice.js index 7c7788459..41a645ff3 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/refundAndInvoice.js +++ b/modules/invoiceOut/back/methods/invoiceOut/refundAndInvoice.js @@ -9,6 +9,11 @@ module.exports = Self => { required: true, description: 'Issued invoice id' }, + { + arg: 'withWarehouse', + type: 'boolean', + required: true + }, { arg: 'cplusRectificationTypeFk', type: 'number', @@ -38,6 +43,7 @@ module.exports = Self => { Self.refundAndInvoice = async( ctx, id, + withWarehouse, cplusRectificationTypeFk, siiTypeInvoiceOutFk, invoiceCorrectionTypeFk, @@ -59,7 +65,7 @@ module.exports = Self => { try { const originalInvoice = await models.InvoiceOut.findById(id, myOptions); - const refundedTickets = await Self.refund(ctx, originalInvoice.ref, false, myOptions); + const refundedTickets = await Self.refund(ctx, originalInvoice.ref, withWarehouse, myOptions); const invoiceCorrection = { correctedFk: id, diff --git a/modules/invoiceOut/back/methods/invoiceOut/specs/refundAndInvoice.spec.js b/modules/invoiceOut/back/methods/invoiceOut/specs/refundAndInvoice.spec.js index c54ae5f6c..ed15fb404 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/specs/refundAndInvoice.spec.js +++ b/modules/invoiceOut/back/methods/invoiceOut/specs/refundAndInvoice.spec.js @@ -14,14 +14,16 @@ describe('InvoiceOut refundAndInvoice()', () => { spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({active: activeCtx}); }); - it('should refund an invoice and create a new invoice', async() => { + it('should refund an invoice and create a new invoice with warehouse', async() => { const tx = await models.InvoiceOut.beginTransaction({}); const options = {transaction: tx}; + const withWarehouse = true; try { const result = await models.InvoiceOut.refundAndInvoice( ctx, id, + withWarehouse, cplusRectificationTypeFk, siiTypeInvoiceOutFk, invoiceCorrectionTypeFk, @@ -32,7 +34,40 @@ describe('InvoiceOut refundAndInvoice()', () => { expect(result.refundId).toBeDefined(); const invoicesAfter = await models.InvoiceOut.find({where: {id: result.refundId}}, options); - const ticketsAfter = await models.Ticket.find({where: {refFk: 'R10100001'}}, options); + const ticketsAfter = await models.Ticket.find( + {where: {refFk: 'R10100001', warehouse: {neq: null}}}, options); + + expect(invoicesAfter.length).toBeGreaterThan(0); + expect(ticketsAfter.length).toBeGreaterThan(0); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should refund an invoice and create a new invoice with warehouse null', async() => { + const tx = await models.InvoiceOut.beginTransaction({}); + const options = {transaction: tx}; + const withWarehouse = false; + + try { + const result = await models.InvoiceOut.refundAndInvoice( + ctx, + id, + withWarehouse, + cplusRectificationTypeFk, + siiTypeInvoiceOutFk, + invoiceCorrectionTypeFk, + options + ); + + expect(result).toBeDefined(); + expect(result.refundId).toBeDefined(); + + const invoicesAfter = await models.InvoiceOut.find({where: {id: result.refundId}}, options); + const ticketsAfter = await models.Ticket.find({where: {refFk: 'R10100001', warehouse: null}}, options); expect(invoicesAfter.length).toBeGreaterThan(0); expect(ticketsAfter.length).toBeGreaterThan(0); diff --git a/modules/invoiceOut/back/methods/invoiceOut/transfer.js b/modules/invoiceOut/back/methods/invoiceOut/transfer.js index 954adf780..aa5c0d9d2 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/transfer.js +++ b/modules/invoiceOut/back/methods/invoiceOut/transfer.js @@ -75,6 +75,7 @@ module.exports = Self => { await Self.refundAndInvoice( ctx, id, + false, cplusRectificationTypeFk, siiTypeInvoiceOutFk, invoiceCorrectionTypeFk,