5914-transferInvoiceOut #1761
|
@ -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')
|
|
@ -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();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
|
@ -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) {
|
||||||
|
|
Loading…
Reference in New Issue