2021-07-23 12:06:48 +00:00
|
|
|
const models = require('vn-loopback/server/server').models;
|
|
|
|
|
2021-09-07 09:55:26 +00:00
|
|
|
describe('invoiceIn clone()', () => {
|
2024-06-14 06:39:57 +00:00
|
|
|
const ctx = beforeAll.getCtx();
|
2024-02-05 10:59:51 +00:00
|
|
|
let options;
|
|
|
|
let tx;
|
|
|
|
|
|
|
|
beforeEach(async() => {
|
|
|
|
options = {transaction: tx};
|
|
|
|
tx = await models.Sale.beginTransaction({});
|
|
|
|
options.transaction = tx;
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(async() => {
|
|
|
|
await tx.rollback();
|
2023-04-12 10:33:14 +00:00
|
|
|
});
|
|
|
|
|
2024-06-12 06:25:50 +00:00
|
|
|
it('should return the cloned invoiceIn and also clone invoiceInDueDays ' +
|
|
|
|
'and invoiceInTaxes if there are any referencing the invoiceIn', async() => {
|
2024-02-05 10:59:51 +00:00
|
|
|
const clone = await models.InvoiceIn.clone(ctx, 1, false, options);
|
2021-07-23 12:06:48 +00:00
|
|
|
|
2024-02-05 10:59:51 +00:00
|
|
|
expect(clone.supplierRef).toEqual('1234(2)');
|
|
|
|
const invoiceIn = await models.InvoiceIn.findOne({
|
|
|
|
include: [
|
|
|
|
{
|
|
|
|
relation: 'invoiceInTax',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
relation: 'invoiceInDueDay',
|
|
|
|
}
|
|
|
|
], where: {
|
|
|
|
id: clone.id
|
2021-07-23 12:06:48 +00:00
|
|
|
}
|
2024-02-05 10:59:51 +00:00
|
|
|
}, options);
|
|
|
|
const invoiceInTax = invoiceIn.invoiceInTax();
|
|
|
|
const invoiceInDueDay = invoiceIn.invoiceInDueDay();
|
|
|
|
|
|
|
|
expect(invoiceInTax.length).toEqual(2);
|
|
|
|
expect(invoiceInDueDay.length).toEqual(2);
|
|
|
|
});
|
|
|
|
|
2024-06-12 06:25:50 +00:00
|
|
|
it('should return the cloned invoiceIn and also clone invoiceInIntrastat ' +
|
|
|
|
'and invoiceInTaxes if it is rectificative', async() => {
|
2024-02-05 10:59:51 +00:00
|
|
|
const clone = await models.InvoiceIn.clone(ctx, 1, true, options);
|
2021-07-23 12:06:48 +00:00
|
|
|
|
2024-02-05 10:59:51 +00:00
|
|
|
expect(clone.supplierRef).toEqual('1234(2)');
|
|
|
|
const invoiceIn = await models.InvoiceIn.findOne({
|
|
|
|
include: [
|
|
|
|
{
|
|
|
|
relation: 'invoiceInTax',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
relation: 'invoiceInIntrastat',
|
2024-02-02 13:02:16 +00:00
|
|
|
}
|
2024-02-05 10:59:51 +00:00
|
|
|
], where: {
|
|
|
|
id: clone.id
|
|
|
|
}
|
|
|
|
}, options);
|
|
|
|
const invoiceInTax = invoiceIn.invoiceInTax();
|
|
|
|
const invoiceInIntrastat = invoiceIn.invoiceInIntrastat();
|
|
|
|
|
|
|
|
expect(invoiceInTax.length).toEqual(2);
|
|
|
|
expect(invoiceInIntrastat.length).toEqual(2);
|
2021-07-23 12:06:48 +00:00
|
|
|
});
|
|
|
|
});
|