feat: refs #7277 test with warehouse #2931
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -75,6 +75,7 @@ module.exports = Self => {
|
|||
await Self.refundAndInvoice(
|
||||
ctx,
|
||||
id,
|
||||
false,
|
||||
cplusRectificationTypeFk,
|
||||
siiTypeInvoiceOutFk,
|
||||
invoiceCorrectionTypeFk,
|
||||
|
|
Loading…
Reference in New Issue