fix(transferInvoice): separate invoice functionality from generating PDF and adapt tests #2528

Merged
alexm merged 4 commits from 6147-transferInvoice_split into master 2024-06-07 08:17:24 +00:00
2 changed files with 21 additions and 4 deletions
Showing only changes of commit 788f334e70 - Show all commits

View File

@ -1,4 +1,3 @@
/* eslint max-len: ["error", { "code": 150 }]*/
const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context');
@ -29,7 +28,16 @@ describe('InvoiceOut transferInvoice()', () => {
try {
const {clientFk: oldClient} = await models.InvoiceOut.findById(id, {fields: ['clientFk']});
const invoicesBefore = await models.InvoiceOut.find({}, options);
const result = await models.InvoiceOut.transferInvoice(ctx, id, 'T4444444', newClient, 1, 1, 1, true, options);
const result = await models.InvoiceOut.transferInvoice(
ctx,
id,
'T4444444',
newClient,
1,
1,
1,
true,
options);
const invoicesAfter = await models.InvoiceOut.find({}, options);
const rectificativeInvoice = invoicesAfter[invoicesAfter.length - 2];
const newInvoice = invoicesAfter[invoicesAfter.length - 1];

View File

@ -1,4 +1,3 @@
/* eslint max-len: ["error", { "code": 160 }]*/
const UserError = require('vn-loopback/util/user-error');
module.exports = Self => {
@ -53,7 +52,17 @@ module.exports = Self => {
}
});
Self.transferInvoice = async(ctx, id, refFk, newClientFk, cplusRectificationTypeFk, siiTypeInvoiceOutFk, invoiceCorrectionTypeFk, makeInvoice, options) => {
Self.transferInvoice = async(
ctx,
id,
refFk,
newClientFk,
cplusRectificationTypeFk,
siiTypeInvoiceOutFk,
invoiceCorrectionTypeFk,
makeInvoice,
options
) => {
const models = Self.app.models;
const myOptions = {userId: ctx.req.accessToken.userId};
let invoiceId;