feat: add backTest
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
cff1e6cfbf
commit
d22be6620c
|
@ -24,29 +24,37 @@ module.exports = Self => {
|
||||||
|
|
||||||
Self.createInvoiceIn = async(rows, dms, options) => {
|
Self.createInvoiceIn = async(rows, dms, options) => {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
|
|
||||||
|
let tx;
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
|
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
const [firstRow] = rows;
|
if (!myOptions.transaction) {
|
||||||
const [firstDms] = dms;
|
tx = await Self.beginTransaction({});
|
||||||
|
myOptions.transaction = tx;
|
||||||
|
}
|
||||||
|
|
||||||
const [reference] = await Self.rawSql(`SELECT reference FROM vn.dms WHERE id = ?`, [firstDms.id]);
|
try {
|
||||||
|
const [firstRow] = rows;
|
||||||
|
const [firstDms] = dms;
|
||||||
|
|
||||||
const newInvoiceIn = await models.InvoiceIn.create({
|
const [reference] = await Self.rawSql(`SELECT reference FROM vn.dms WHERE id = ?`, [firstDms.id], myOptions);
|
||||||
supplierFk: firstRow.supplierFk,
|
|
||||||
supplierRef: reference.value,
|
|
||||||
issued: firstRow.created,
|
|
||||||
booked: firstRow.created,
|
|
||||||
operated: firstRow.created,
|
|
||||||
bookEntried: firstRow.created,
|
|
||||||
gestdoc_id: firstDms.id
|
|
||||||
});
|
|
||||||
|
|
||||||
const [expence] = await Self.rawSql(`SELECT expenceFk value FROM vn.agencyTermConfig`);
|
const newInvoiceIn = await models.InvoiceIn.create({
|
||||||
|
supplierFk: firstRow.supplierFk,
|
||||||
|
supplierRef: reference.value,
|
||||||
|
issued: firstRow.created,
|
||||||
|
booked: firstRow.created,
|
||||||
|
operated: firstRow.created,
|
||||||
|
bookEntried: firstRow.created,
|
||||||
|
gestdoc_id: firstDms.id
|
||||||
|
}, myOptions);
|
||||||
|
|
||||||
const [taxTypeSage] = await Self.rawSql(`
|
const [expence] = await Self.rawSql(`SELECT expenceFk value FROM vn.agencyTermConfig`, null, myOptions);
|
||||||
|
|
||||||
|
const [taxTypeSage] = await Self.rawSql(`
|
||||||
SELECT IFNULL(s.taxTypeSageFk, CodigoIva) value
|
SELECT IFNULL(s.taxTypeSageFk, CodigoIva) value
|
||||||
FROM vn.supplier s
|
FROM vn.supplier s
|
||||||
JOIN sage.TiposIva ti ON TRUE
|
JOIN sage.TiposIva ti ON TRUE
|
||||||
|
@ -54,32 +62,38 @@ module.exports = Self => {
|
||||||
WHERE s.id = ?
|
WHERE s.id = ?
|
||||||
AND ti.CuentaIvaSoportado = atg.vatAccountSupported
|
AND ti.CuentaIvaSoportado = atg.vatAccountSupported
|
||||||
AND ti.PorcentajeIva = atg.vatPercentage
|
AND ti.PorcentajeIva = atg.vatPercentage
|
||||||
`, [firstRow.supplierFk]);
|
`, [firstRow.supplierFk], myOptions);
|
||||||
|
|
||||||
const [transactionTypeSage] = await Self.rawSql(`
|
const [transactionTypeSage] = await Self.rawSql(`
|
||||||
SELECT IFNULL(s.transactionTypeSageFk, tt.CodigoTransaccion) value
|
SELECT IFNULL(s.transactionTypeSageFk, tt.CodigoTransaccion) value
|
||||||
FROM vn.supplier s
|
FROM vn.supplier s
|
||||||
JOIN sage.TiposTransacciones tt ON TRUE
|
JOIN sage.TiposTransacciones tt ON TRUE
|
||||||
JOIN vn.agencyTermConfig atg
|
JOIN vn.agencyTermConfig atg
|
||||||
WHERE s.id = ?
|
WHERE s.id = ?
|
||||||
AND tt.Transaccion = atg.transaction
|
AND tt.Transaccion = atg.transaction
|
||||||
`, [firstRow.supplierFk]);
|
`, [firstRow.supplierFk], myOptions);
|
||||||
|
|
||||||
await models.InvoiceInTax.create({
|
await models.InvoiceInTax.create({
|
||||||
invoiceInFk: newInvoiceIn.id,
|
invoiceInFk: newInvoiceIn.id,
|
||||||
taxableBase: firstRow.totalPrice,
|
taxableBase: firstRow.totalPrice,
|
||||||
expenseFk: expence.value,
|
expenseFk: expence.value,
|
||||||
taxTypeSageFk: taxTypeSage.value,
|
taxTypeSageFk: taxTypeSage.value,
|
||||||
transactionTypeSageFk: transactionTypeSage.value
|
transactionTypeSageFk: transactionTypeSage.value
|
||||||
});
|
}, myOptions);
|
||||||
|
|
||||||
await Self.rawSql(`CALL invoiceInDueDay_calculate(?)`, [newInvoiceIn.id]);
|
await Self.rawSql(`CALL invoiceInDueDay_calculate(?)`, [newInvoiceIn.id], myOptions);
|
||||||
|
|
||||||
for (let agencyTerm of rows) {
|
for (let agencyTerm of rows) {
|
||||||
const route = await models.Route.findById(agencyTerm.routeFk);
|
const route = await models.Route.findById(agencyTerm.routeFk, null, myOptions);
|
||||||
await Self.rawSql(`
|
await Self.rawSql(`
|
||||||
UPDATE vn.route SET invoiceInFk = ? WHERE id = ?
|
UPDATE vn.route SET invoiceInFk = ? WHERE id = ?
|
||||||
`, [newInvoiceIn.id, route.id]);
|
`, [newInvoiceIn.id, route.id], myOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tx) await tx.commit();
|
||||||
|
} catch (e) {
|
||||||
|
if (tx) await tx.rollback();
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -11,23 +11,9 @@ describe('AgencyTerm createInvoiceIn()', () => {
|
||||||
];
|
];
|
||||||
const dms = [
|
const dms = [
|
||||||
{
|
{
|
||||||
id: 7,
|
id: 6
|
||||||
file: '7.pdf',
|
|
||||||
contentType: 'application/pdf',
|
|
||||||
reference: '1',
|
|
||||||
description: 'Plants SL',
|
|
||||||
hasFile: false,
|
|
||||||
companyFk: 442,
|
|
||||||
dmsTypeFk: 1,
|
|
||||||
warehouseFk: 1,
|
|
||||||
workerFk: 9
|
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
const userId = 1;
|
|
||||||
const activeCtx = {
|
|
||||||
accessToken: {userId: userId},
|
|
||||||
};
|
|
||||||
const ctx = {req: activeCtx};
|
|
||||||
|
|
||||||
it('should make a global invoicing', async() => {
|
it('should make a global invoicing', async() => {
|
||||||
const tx = await models.AgencyTerm.beginTransaction({});
|
const tx = await models.AgencyTerm.beginTransaction({});
|
||||||
|
@ -38,19 +24,19 @@ describe('AgencyTerm createInvoiceIn()', () => {
|
||||||
const invoiceInDueDayId = 11;
|
const invoiceInDueDayId = 11;
|
||||||
const invoiceInTaxId = 12;
|
const invoiceInTaxId = 12;
|
||||||
|
|
||||||
const oldInvoiceIn = await models.AgencyTerm.findById(invoiceInId, null, options);
|
const oldInvoiceIn = await models.InvoiceIn.findById(invoiceInId, null, options);
|
||||||
const oldInvoiceInDueDay = await models.AgencyTerm.findById(invoiceInDueDayId, null, options);
|
const oldInvoiceInDueDay = await models.InvoiceInDueDay.findById(invoiceInDueDayId, null, options);
|
||||||
const oldInvoiceInTax = await models.AgencyTerm.findById(invoiceInTaxId, null, options);
|
const oldInvoiceInTax = await models.InvoiceInTax.findById(invoiceInTaxId, null, options);
|
||||||
|
|
||||||
const [newInvoiceIn] = await models.Ticket.rawSql('SELECT MAX(id) id FROM invoiceIn', null, options);
|
|
||||||
// const [newInvoiceInDueDay] = await models.AgencyTerm.rawSql('SELECT MAX(id) id FROM invoiceInDueDay', null, options);
|
|
||||||
// const [newInvoiceInTax] = await models.AgencyTerm.rawSql('SELECT MAX(id) id FROM invoiceInTax', null, options);
|
|
||||||
|
|
||||||
await models.AgencyTerm.createInvoiceIn(rows, dms, options);
|
await models.AgencyTerm.createInvoiceIn(rows, dms, options);
|
||||||
|
|
||||||
// expect(newInvoiceIn.id).toEqual(oldInvoiceIn.id + 1);
|
const [newInvoiceIn] = await models.InvoiceIn.rawSql('SELECT MAX(id) id FROM invoiceIn', null, options);
|
||||||
// expect(newInvoiceInDueDay.id).toEqual(oldInvoiceInDueDay.id + 1);
|
const [newInvoiceInDueDay] = await models.InvoiceInDueDay.rawSql('SELECT MAX(id) id FROM invoiceInDueDay', null, options);
|
||||||
// expect(newInvoiceInTax.id).toEqual(oldInvoiceInTax.id + 1);
|
const [newInvoiceInTax] = await models.InvoiceInTax.rawSql('SELECT MAX(id) id FROM invoiceInTax', null, options);
|
||||||
|
|
||||||
|
expect(newInvoiceIn.id).toBeGreaterThan(oldInvoiceIn.id);
|
||||||
|
expect(newInvoiceInDueDay.id).toBeGreaterThan(oldInvoiceInDueDay.id);
|
||||||
|
expect(newInvoiceInTax.id).toBeGreaterThan(oldInvoiceInTax.id);
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const models = require('vn-loopback/server/server').models;
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
xdescribe('AgencyTerm filter()', () => {
|
describe('AgencyTerm filter()', () => {
|
||||||
const authUserId = 9;
|
const authUserId = 9;
|
||||||
|
|
||||||
it('should all return the tickets matching the filter', async() => {
|
it('should all return the tickets matching the filter', async() => {
|
||||||
|
@ -9,9 +9,9 @@ xdescribe('AgencyTerm filter()', () => {
|
||||||
try {
|
try {
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
const filter = {};
|
const filter = {};
|
||||||
const ctx = {req: {accessToken: {userId: authUserId}}, args: {filter: filter}};
|
const ctx = {req: {accessToken: {userId: authUserId}}};
|
||||||
|
|
||||||
const agencyTerms = await models.AgencyTerm.filter(ctx, null, options);
|
const agencyTerms = await models.AgencyTerm.filter(ctx, filter, options);
|
||||||
const firstAgencyTerm = agencyTerms[0];
|
const firstAgencyTerm = agencyTerms[0];
|
||||||
|
|
||||||
expect(firstAgencyTerm.routeFk).toEqual(1);
|
expect(firstAgencyTerm.routeFk).toEqual(1);
|
||||||
|
|
Loading…
Reference in New Issue