7983-testToMaster_2438 #2977
|
@ -9,6 +9,11 @@ module.exports = Self => {
|
||||||
required: true,
|
required: true,
|
||||||
description: 'Issued invoice id'
|
description: 'Issued invoice id'
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
arg: 'withWarehouse',
|
||||||
|
type: 'boolean',
|
||||||
|
required: true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
arg: 'cplusRectificationTypeFk',
|
arg: 'cplusRectificationTypeFk',
|
||||||
type: 'number',
|
type: 'number',
|
||||||
|
@ -38,6 +43,7 @@ module.exports = Self => {
|
||||||
Self.refundAndInvoice = async(
|
Self.refundAndInvoice = async(
|
||||||
ctx,
|
ctx,
|
||||||
id,
|
id,
|
||||||
|
withWarehouse,
|
||||||
cplusRectificationTypeFk,
|
cplusRectificationTypeFk,
|
||||||
siiTypeInvoiceOutFk,
|
siiTypeInvoiceOutFk,
|
||||||
invoiceCorrectionTypeFk,
|
invoiceCorrectionTypeFk,
|
||||||
|
@ -59,7 +65,7 @@ module.exports = Self => {
|
||||||
try {
|
try {
|
||||||
const originalInvoice = await models.InvoiceOut.findById(id, myOptions);
|
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 = {
|
const invoiceCorrection = {
|
||||||
correctedFk: id,
|
correctedFk: id,
|
||||||
|
|
|
@ -14,14 +14,16 @@ describe('InvoiceOut refundAndInvoice()', () => {
|
||||||
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({active: activeCtx});
|
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 tx = await models.InvoiceOut.beginTransaction({});
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
|
const withWarehouse = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await models.InvoiceOut.refundAndInvoice(
|
const result = await models.InvoiceOut.refundAndInvoice(
|
||||||
ctx,
|
ctx,
|
||||||
id,
|
id,
|
||||||
|
withWarehouse,
|
||||||
cplusRectificationTypeFk,
|
cplusRectificationTypeFk,
|
||||||
siiTypeInvoiceOutFk,
|
siiTypeInvoiceOutFk,
|
||||||
invoiceCorrectionTypeFk,
|
invoiceCorrectionTypeFk,
|
||||||
|
@ -32,7 +34,40 @@ describe('InvoiceOut refundAndInvoice()', () => {
|
||||||
expect(result.refundId).toBeDefined();
|
expect(result.refundId).toBeDefined();
|
||||||
|
|
||||||
const invoicesAfter = await models.InvoiceOut.find({where: {id: result.refundId}}, options);
|
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(invoicesAfter.length).toBeGreaterThan(0);
|
||||||
expect(ticketsAfter.length).toBeGreaterThan(0);
|
expect(ticketsAfter.length).toBeGreaterThan(0);
|
||||||
|
|
|
@ -75,6 +75,7 @@ module.exports = Self => {
|
||||||
await Self.refundAndInvoice(
|
await Self.refundAndInvoice(
|
||||||
ctx,
|
ctx,
|
||||||
id,
|
id,
|
||||||
|
false,
|
||||||
cplusRectificationTypeFk,
|
cplusRectificationTypeFk,
|
||||||
siiTypeInvoiceOutFk,
|
siiTypeInvoiceOutFk,
|
||||||
invoiceCorrectionTypeFk,
|
invoiceCorrectionTypeFk,
|
||||||
|
|
Loading…
Reference in New Issue