5914-transferInvoiceOut #1761

Merged
jorgep merged 55 commits from 5914-transferInvoiceOut into dev 2023-10-26 12:39:11 +00:00
3 changed files with 52 additions and 4 deletions
Showing only changes of commit 98ee9bbaf3 - Show all commits

View File

@ -4,3 +4,7 @@ INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalTyp
('CplusInvoiceType477', '*', 'READ', 'ALLOW', 'ROLE', 'administrative'), ('CplusInvoiceType477', '*', 'READ', 'ALLOW', 'ROLE', 'administrative'),
('InvoiceCorrectionType', '*', 'READ', 'ALLOW', 'ROLE', 'administrative'), ('InvoiceCorrectionType', '*', 'READ', 'ALLOW', 'ROLE', 'administrative'),
('InvoiceOut', 'transferInvoice', 'WRITE', 'ALLOW', 'ROLE', 'administrative'); ('InvoiceOut', 'transferInvoice', 'WRITE', 'ALLOW', 'ROLE', 'administrative');
INSERT INTO `vn`.`invoiceCorrectionType` (description)
VALUES
('Error en el cálculo del IVA')

View File

@ -0,0 +1,43 @@
const models = require('vn-loopback/server/server').models;
describe('InvoiceOut tranferInvoice()', () => {
const userId = 5;
const ctx = {req: {accessToken: userId}};
ctx.args = {
id: '1',
ref: 'T1111111',
newClientFk: 1,
cplusRectificationId: 1,
cplusInvoiceType477Id: 1,
invoiceCorrectionTypeId: 1
};
it('should return the id of the created issued invoice', async() => {
const tx = await models.InvoiceOut.beginTransaction({});
const options = {transaction: tx};
try {
const result = await models.InvoiceOut.transferInvoice(
ctx,
options);
expect(result).toBeDefined();
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
it('should throw an UserError when it is the same client', async() => {
const tx = await models.InvoiceOut.beginTransaction({});
const options = {transaction: tx};
try {
ctx.args.newClientFk = 1101;
await models.InvoiceOut.transferInvoice(
ctx,
options);
} catch (e) {
expect(e.message).toBe(`Select a different client`);
await tx.rollback();
}
});
});

View File

@ -97,9 +97,10 @@ module.exports = Self => {
invoiceCorrectionTypeFk: args.invoiceCorrectionTypeId invoiceCorrectionTypeFk: args.invoiceCorrectionTypeId
}, myOptions); }, myOptions);
if (tx) await tx.commit(); if (tx) {
await tx.commit();
await models.InvoiceOut.makePdfAndNotify(ctx, invoiceId, null); await models.InvoiceOut.makePdfAndNotify(ctx, invoiceId, null);
}
return invoiceId; return invoiceId;
} catch (e) { } catch (e) {